rjconcepcion
Published © CC BY-NC-SA

Simplest IoT Temperature and Humidity Meter

Simplest IoT temperature and humidity meter allow you to collect temperature, humidity, and heat index. Then send them to Adafruit IO.

IntermediateFull instructions provided2 hours610
Simplest IoT Temperature and Humidity Meter

Things used in this project

Hardware components

LD1117V33 Voltage Regulator
×1
Espressif ESP8266 ESP-01
×1
DHT11 temperature and humidity sensor
×1
Capacitor 100nF
×1
Capacitor 10uF x 50 V
×1
Resistor 5.6K ohms
×1
Breadboard
×1
Preformed Breadboard Jumper Wire
×1

Software apps and online services

Arduino IDE
Arduino IDE
Adafruit IO

Story

Read more

Schematics

Schematic

You will need a power supply between 5 V to 9 V. I do not recommend use a power supply above 9 V because the voltage regulator gets hot.

Code

Code

Arduino
// IoT Thermometer with ESP-01
// If you do not know how to configure Adafruit OI go to the link below.
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"
#include <DHT.h>    // DHT library

/************************ Example Starts Here *******************************/

// Set input pin for receive the data from the sensor. I used GPIO1
#define DHTPIN 1
// Select DHT type sensor
#define DHTTYPE DHT11

// variables
int current_temp = 0;
int last_temp = -1;

int current_hum = 0;
int last_hum = -1;

// set pin and type of sensor
DHT dht(DHTPIN, DHTTYPE);

// set up the feeds
AdafruitIO_Feed *temp_feed = io.feed("temp_feed");
AdafruitIO_Feed *hum_feed = io.feed("hum_feed");
AdafruitIO_Feed *st_feed = io.feed("st_feed");

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // Start the dht function.
  dht.begin();


  // wait for serial monitor to open
  while(! Serial);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // 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();

  // Get humidity data from the sensor
  float hum = dht.readHumidity();
  // Get temperature data from the sensor
  float temp = dht.readTemperature();

  float st = dht.computeHeatIndex(temp, hum, false);

  // Print values in the serial monitor console
  Serial.print("Humedad: ");
  Serial.print(hum);
  Serial.println(" %\t");
  Serial.print("Temperatura: ");
  Serial.print(temp);
  Serial.println(" *C ");
  Serial.print("Índice de calor: ");
  Serial.print(st);
  Serial.println(" *C ");

  
  delay(10000);
 

  // Check if there was an error taking the data.
  if (isnan(hum) || isnan(temp)){
    Serial.println("Error en obtener los datos ");
    return;
  }
  
  current_temp = temp;
  current_hum = hum;
  
  // return if the value hasn't changed
  if((current_temp == last_temp) && (current_hum == last_hum))
    return;

  // save the current state to the feeds
  Serial.println("sending -> ");
  Serial.println(current_temp);
  temp_feed->save(current_temp);
  Serial.println(current_hum);
  hum_feed->save(current_hum);
  Serial.println(st);
  st_feed->save(st);

  // store last values
  last_temp = current_temp;
  last_hum = current_hum;

  // wait three seconds (1000 milliseconds == 1 second)
  //
  // because there are no active subscriptions, we can use delay()
  // instead of tracking millis()
  // wait 60 seconds to send the data to the Adafruit IO.
  delay(60000);

}

config.h file

Arduino
In this file you write your Adafruit credentials and the wireless network settings.
/************************ 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   "USERNAME"
#define IO_KEY        "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
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264

#define WIFI_SSID   "WIFI NAME"
#define WIFI_PASS   "WIFI PASS"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
  // Configure the pins used for the ESP32 connection
  #if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
    // Don't change the names of these #define's! they match the variant ones
    #define SPIWIFI SPI
    #define SPIWIFI_SS 10  // Chip select pin
    #define NINA_ACK 9    // a.k.a BUSY or READY pin
    #define NINA_RESETN 6 // Reset pin
    #define NINA_GPIO0 -1 // Not connected
  #endif
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

Credits

rjconcepcion

rjconcepcion

11 projects • 8 followers
Electronic is my passion. I like to work with programming devices like Arduino, ESP8266, Raspberry Pi. I enjoy design electronic projects.

Comments