I recently tried out an example for a DS18B20 temperature sensor. The code example mentioned 2 libraries, so I went forward and downloaded them and imported them into my IDE but was disappointed to see an error like this when I tried to compile my example sketch
error: WConstants.h: No such file or directory
This occurred when I tried to compile my sketch, the reason for this is that these libraries were written in the ‘dark ages’ in terms of the Arduino compiler when WConstants.h was supported but since version 1.00 onwards this has not been the case. Never fear as this is easy to fix and improve.
The solution is to delete the line in the library header file like
and then in the .h header file, add the following in its place
#if ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif
Using this code, the code will compile, and it will be compatible with Arduino 0023 and 1.0 versions.