I am adding Dust Sensor to my particle photon project at home,

I got this GitHub project that I want to test before implementing a final code.

I am not an expert in cpp, I wanted to modularise the dust sensor codebase to separate library so I created new dustSensor.cpp file and kept the code linked above.

but I keep getting error:

'Serial' was not declared in this scope

'Serial1' was not declared in this scope

'DEBUG' was not declared in this scope

'DEC' was not declared in this scope dustSensor.cpp:13:57:

I do have Serial.begin(57600) called in setup() function but still get the above error

  • 1
    add #include <Arduno.h> to cpp
    – Juraj
    Commented Nov 15, 2018 at 13:48
  • you can find it with opened your Particle Project in the Desktop IDE and click on the Browse and Manage Libraries buttons and find the library you need. that's automatically include your libraries. see this docs. Commented Nov 15, 2018 at 14:02

1 Answer 1


I learned that I needed to include Arduino.h header file

apart from that I learned .ino files and .cpp files is that the .ino files transparently include particle.h for you.

The other difference is that .ino files generate forward declarations for you. This is necessary when you’ve implemented a function later in the file than when you’ve first used it. For example, if you pass the function to something like Particle.subscribe in setup() but you’ve implemented it farther down the file.

  • 2
    The technical name for that is a "forward reference". Historical note: the necessity to declare the function before a forward reference originated because early C compilers were written to read your source code only once, rather than once to find function and variable definitions and again to generate code once the components of it were known. Such a compiler was easier to write and ran faster (which was a bigger concern at the time than it is today).
    – JRobert
    Commented Nov 15, 2018 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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