Program the ESP8266
Launch the Arduino IDE
You should already have the Arduino IDE running from the previous step. If not, launch it now.
Check that ESP8266 USB cable is connected.
Check that the Board and Port settings are correct, as shown in Arduino IDE Installation.
Our next step is to download an Arduino Sketch (program) that reads the air quality data from the sensor and sends it to ThingSpeak.
We need to change some configuration setting in the Arduino Sketch to identify the ThingSpeak Channel for your sensor.
Configure the IKEA_ESP8266_ThingSpeak.ino sketch
File ... New
Select all the text and delete it.
Click the following link and download the file. (Be sure to remember where you saved it.)
In the Arduino IDE, use File ... Open to open the file you saved.
When prompted to save the file in a folder, click OK.Find the following line of code:
define SECRET_CH_ID 123 // "Channel ID"In your web browser, go to https://thingspeak.com/channels
Click on the "Air Quality" channel you created
Click the "API Keys" tab
Copy your Channel ID displayed near the top of the page.
In the Arduino IDE, replace 123 with your ThingSpeak ChannelID
Find the following line of code:
#define SECRET_WRITE_APIKEY "XXXXXXXXXXXXXXXX" // "Write API Key"From https://thingspeak.com/channels, copy the "Write API Key"
In the Arduino IDE, replace XXXXXXXXXXXXXXXX with the Write API Key.
Save, Compile and Upload the Arduino Sketch
In the Arduino IDA, click
File ... Save
and save your modified Arduino sketch somewhere you can access it again in the future.The, click
Sketch ... UploadWait for the Arduino compiler to run and upload the program to the ESP8266.
If everything is OK, the last line in the status window, at the bottom of the Arduino IDE, should be:
Hard resetting via RTS pin...
Check to see that the Sketch is working
In the Arduino IDE, click Tools ... Serial Monitor.
In the lower right of the Serial Monitor window, set the baud rate to 115200 if it set to another value.
You should see something like:
.....
IKEA Air Quality Sensor -> ThingSpeak
Hello from esp8266-vindriktning-particle-sensor
Core Version: 3.0.2
Boot Version: 6
Boot Mode: 1
CPU Frequency: 80 MHz
Reset reason: External System
-- Current GPIO Configuration --
PIN_UART_RX: 4
Wifi MAC address: 40:91:51:XX:XX:XX
ThingSpeak ChannelID: XXXX314
ThingSpeak Write API Key: XXXXXXXXXXXXXXXX
Attempting to connect to SSID: workshop
.
Connected to workshop
IP address: 192.168.0.103
If you are not seeing any text output, try disconnecting and reconnecting the USB cable connected to the ESP8266 board.
You can also press the tiny reset button on the ESP8266 board, located next to the USB connecter. Press it from the side.
If you are not seeing "Connected to workshop," ask for assistance.
Check to see that the sensor data is collected
In the Serial Monitor, you should see repeated messages like:
Receiving:....................Done.
Received PM 2.5 reading: 9
Current measurements: 9, 9, 9, 9, 9
...
AirQuality = 9.60 ug/cm3
This indicates that the ESP8266 board is collecting air quality sensor data from the IKEA sensor.
If you are seeing an error message, such as
"Not receiving sensor data. Check wiring!"
"Received message with invalid header"
be sure that the wiring is correct and the connectors for the IKEA sensor and fan are fully inserted into the IKEA circuit board.
Disconnect/re-connect the USB cable.
If you continue to see error messages, ask for assistance.
Check to see that the sensor data is sent to ThingSpeak
If you see a message in the form of "Problem updating ThingSpeak channel. HTTP error code -XXX"
check that you've edited the Arudino Sketch with the correct ThingSpeak SECRET_CH_ID and SECRET_WRITE_APIKEY for your channel.
If you continue to see error messages, ask for assistance.
LED error messages
The blue LED on the ESP8266 board (not the green/yellow/red LEDs on the IKEA sensor) blinks to indicate status and errors:
1 blink - data successfully sent to ThingSpeak - everything is working correctly.
3 blinks - connected to Wifi - upon startup or after a disconnect for some reason
5 blinks - unable to send data to ThingSpeak - problem!
10 blinks - unable to receive data from IKEA sensor - problem!