ESP32 Temperature Data Logger

2018-03-28 19:45:20 by

ESP32 Temperature Data Logger


In a previous article I went through the setup of a general purpose data logger based on an Espressif ESP32 development board from Adafruit. In this article I’m going to add a temperature sensor to read ambient air temperature and save the time and temperature data to the SD card.


The DHT11 Temperature Sensor

The DHT11 (the DHT22 is similar but more accurate) is a low-cost temperature/humidity sensor that is accurate enough for basic temperature logging and can read temperature values every second or two. There are a lot of vendors that sell the DHT11 either stand alone or on a simple PCB with required pullup resistor and pinouts. I’m using a DHT11 PCB Octopus board.


The DHT11 only requires 3 wires: Power, Ground, and Signal Out so it’s a one-wire communication between the temperature sensor and microcontroller board.


I’m connecting the VDD pin to 3V supply from the ESP32 – some of the DHT11 devices say you need 5V but it seems to work on 3V as well but you should test your own setup to verify.


For the signal pin I’m connecting that to pin 26 (A0) on the ESP32 but you can connect it to any general GPIO you want. However make sure you look at the ESP32 Feather pinout as some GPIO pins are reserved for special functions so they can’t be used as an output or input which won’t work for this bi-directional communication.


Adafruit has a great write-up on using a DHT11 with the Arduino so we will use that as a starting point to get it working with the ESP32. (Another great tutorial can be found at Circuit Basics)


Once you download the two libraries and re-start the Arduino IDE you should be able to open up the DHTtester sketch and comment out the lines for the DHT22:

Also be sure to change the pin number that you are connecting the DHT11 to in the code as well.

Here’s what I get testing inside my house:


Using An OLED Display Screen

The Adafruit featherwing alpha numeric display that we previously used works great but it blocks access to the rest of the ESP32 board pins so we are going to switch to an OLED display. This way we can see the temperature on the display in real time.


I’m going to be using 0.96 inch I2C 128×64 OLED display from Diymall that I got off of Amazon. There are a lot of OLED displays available from other vendors so find one suitable for your project.


For my OLED module there are 4 pins: VCC (3.3V or 5V), GND, SCL, and SDA and you can connecting these to the ESP32 is straight forward. I did use a breadboard to connect the GND pin to the OLED display and the DHT11 and I connected the VCC to 5V.


I just tried the Adafruit featherwing OLED code example (install the correct libraries) and it worked fine:


Displaying the Temperature on the OLED Display

Now we are going to put everything together and display the temperature from the DHT11 on the OLED screen.



We’ve taken our general purpose data logger and swapped out the alpha numeric display for an OLED display and added a temperature/humidity sensor and can now display that to the OLED screen. The next article we will add an external battery and along with displaying the temperature to the screen we will also save the time/temperature to the SD card for full data logging.


Read Comments