The ESP8266 based Feather HUZZAH & the HUZZAH ESP8266 breakout are both very popular options for connecting projects to Adafruit IO. This guide assumes you've completed the setup required to get your ESP8266 up and running with Arduino IDE and Adafruit IO.
- If you haven't yet set up your ESP8266 for use with Adafruit IO and the Arduino IDE, follow along with this guide. The setup only needs to be performed once.
You'll also need the Adafruit_ADT7410 library and the Adafruit Unified Sensor library installed.
- If you have not done this yet, click here to visit the setup guide and come back to this page when you're done.
Copy and paste the following code into an empty Arduino Sketch:
// SPDX-FileCopyrightText: 2019 Brent Rubell for Adafruit Industries // // SPDX-License-Identifier: MIT // Adafruit IO ADT7410 Example // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing // products from Adafruit! // // Written by Ladyada and Brent Rubell for Adafruit Industries // Copyright (c) 2019 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. /************************ Adafruit IO Config *******************************/ // visit io.adafruit.com if you need to create an account, // or if you need your Adafruit IO key. #define IO_USERNAME "YOUR_IO_USERNAME" #define IO_KEY "YOUR_IO_KEY" /******************************* WIFI **************************************/ // the AdafruitIO_WiFi client will work with the following boards: // - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471 // - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821 // - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405 // - Feather M0 WiFi -> https://www.adafruit.com/products/3010 // - Feather WICED -> https://www.adafruit.com/products/3056 #define WIFI_SSID "WIFI_NAME" #define WIFI_PASS "WIFI_PASS" // comment out the following two lines if you are using fona or ethernet #include "AdafruitIO_WiFi.h" AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); /************************** Configuration ***********************************/ // time between sending data to adafruit io, in minutes #define MESSAGE_WAIT_SEC (15 * 60) /************************ Example Starts Here *******************************/ #include <Wire.h> // adt7410 sensor #include "Adafruit_ADT7410.h" // featherwing oled #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <SPI.h> // Create the OLED display object Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); // Create the ADT7410 temperature sensor object Adafruit_ADT7410 tempsensor = Adafruit_ADT7410(); // set up the 'temperature' feed AdafruitIO_Feed *huzzah_temperature = io.feed("temperature"); void setup() { // start the serial connection Serial.begin(115200); // wait for serial monitor to open while (!Serial) ; Serial.println("Adafruit IO ADT7410 + OLED"); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 Serial.println("OLED begun"); // Show image buffer on the display hardware. // Since the buffer is intialized with an Adafruit splashscreen // internally, this will display the splashscreen. display.display(); delay(1000); // Clear the buffer. display.clearDisplay(); display.display(); // Make sure the sensor is found, you can also pass in a different i2c // address with tempsensor.begin(0x49) for example if (!tempsensor.begin()) { Serial.println("Couldn't find ADT7410!"); while (1) ; } // sensor takes 250 ms to get first readings delay(250); // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); display.clearDisplay(); display.display(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.print("Connecting to IO..."); display.display(); // wait for a connection while (io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } // we are connected Serial.println(); Serial.println(io.statusText()); } void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); // Read and print out the temperature, then convert to *F float c = tempsensor.readTempC(); Serial.print("Temp: "); Serial.print(c); Serial.println("C"); // clear the display display.clearDisplay(); display.display(); // print to display display.setTextColor(WHITE); display.setTextSize(2); display.setCursor(0, 0); display.print("Temp:"); display.print(c); // send data to adafruit io display.setCursor(15, 20); display.setTextSize(1); display.print("Sending..."); display.display(); Serial.println("Sending to Adafruit IO"); delay(1000); huzzah_temperature->save(c, 0, 0, 0, 2); // sent to IO display.clearDisplay(); display.display(); display.setTextSize(2); display.setCursor(0, 0); display.print("Temp:"); display.print(c); display.setTextSize(1); display.setCursor(15, 20); display.print("Sending...Done!"); display.display(); Serial.print("Waiting "); Serial.print(MESSAGE_WAIT_SEC); Serial.println(" seconds"); // wait 15 minutes between sends for (int i = 0; i < MESSAGE_WAIT_SEC; i++) { delay(1000); } }
Before you upload the sketch to the Huzzah, you'll need to configure the network and Adafruit IO.
Change IO_USERNAME
to your Adafruit IO username and IO_KEY
to the Adafruit IO Key you saved earlier.
Next, set up the sketch to use WiFi. Change WIFI_SSID
to your router's SSID and WIFI_PASS
to your router's password.
Save and upload the sketch to your board, and open the Arduino Serial Monitor. Your board should now connect to Adafruit IO.
Adafruit IO ADT7410 + OLED OLED begun Connecting to Adafruit IOAdafruitIO::connect() Adafruit IO connected.
The ADT7410 will read temperature values and the Feather will send them to Adafruit IO. You should see something resembling the following in the Arduino Serial Monitor:
Temp: 24.31C Sending to Adafruit IO Waiting 900 seconds
Want to change the amount of precision (decimal places) sent from the ADT7410 to Adafruit IO?
Modify this line from:
huzzah_temperature->save(c, 0, 0, 0, 2);
to
huzzah_temperature->save(c, 0, 0, 0, decimal_places);
Make sure to replace decimal_places
with the number of decimal places you'd like to send from the ADT7410.
Want to change the delay between sending data to Adafruit IO?
In the code, change this line from:
#define MESSAGE_WAIT_SEC (15 * 60)
to
#define MESSAGE_WAIT_SEC (SECONDS_TO_DELAY_BY * 60)
Make sure to replace SECONDS_TO_DELAY_BY
with the number of seconds to delay between sending sensor data.
Next, let's check that the data has been received by Adafruit IO. You can do this by visiting the Adafruit IO Monitor page. Every 15 minutes, the page will refresh with a new huzzah-temperature
value.
Text editor powered by tinymce.