I have NewSoftSerial.h and NewSoftSerial.cpp in the same folder as my sketch.

The sketch is thus.

#include <NewSoftSerial.h>

int incomingByte = 0;   // for incoming serial data
NewSoftSerial bluetooth(2, 3);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
  Serial.flush();
  //enter command mode
  Serial.println("$$$");
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    //read the incoming byte:
    incomingByte = Serial.read();

    //say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, BYTE);
  }
}

What am I doing wrong that I get these errors?

trainremotesketch.cpp:1:27: error: NewSoftSerial.h: No such file or directory trainremotesketch:3: error: 'NewSoftSerial' does not name a type

up vote 6 down vote accepted

The short answer is that library files go in the libraries folder in the Arduino root folder. A library should be in a sub-folder named for the class, and should contain a c++ implementation and header file.

-Arduino
  |
  +--libraries  
       |
       +--NewSoftSerial
           |
           +--NewSoftSerial.cpp
           |
           +--NewSoftSerial.h           

A longer answer is that if you want to include a header file which isn't in the library path, you use double quotes, instead of angle brackets:

#include "NewSoftSerial.h"
  • 6
    This answer is actually shorter – Jordan Sitkin Jul 8 '14 at 16:11

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.