Temperature Sensors with ESP32 - Part One (w/ Bonus Garduino)

September 2020 · 1200 words · 6 minute read

As part of one of my pushes to get more involved in the physical world and out of the digital world I’ve been experimenting with electronics, in particular, the ESP32 microcontroller as well as an Arduino.

There’s something I’ve found about interacting with a physical piece of kit in front of me, something that I can manipulating and touch with my hands, that I just haven’t been able to get with pure software projects in the past. It’s been a blast so far and I mean that genuinely, not in the fake internet way where everything is awesome or epic. I feel engaged and interested in learning about something and seeing the results. It’s just plain fun and interesting at the same time and it’s going to be interesting to see where this develops.

The first two projects that I’ve been working on have been:

So far, I’ve learnt a ton and made a number of mistakes.

For technology, I’ve been using a genuine Arduino Uno and a DFRobot Firebeetle ESP32 dev board to get started. The Arduino I’ve found has been really awesome for just trying something really quickly. They’re pretty big though, especially compared to the Firebeetle as well. This isn’t hugely important at this stage but it may become a factor later on. Of potentially more impact, the ESP32 has WiFi and can be used to send data.

Arduino vs ESP32 Firebeetle

An Arduino uno side by side with the DFRobot Firebeetle ESP32

My current plans are to use a basic temperature sensor project and the Garduino as learning projects. In these, I’m not going for low cost or for the prettiest design. Instead I’m treating it as incremental steps to get going with the project as a whole.

So far I’ve been able to get the temperature sensor working on the ESP32. Things I learnt:

I’ve also gone down a few rabbit holes that were probably not necessary at this stage. This includes:

Next Steps

Now that I’ve got some of the basics working I need to get the following working:

  1. ESP32 Temperature Sensor able to send JSON (or equivalent) to a server
  2. Set up a server to receive the ESP32 data (local or cloud? Do I trust someone else with my data?)
  3. Power the ESP32 from a power supply rather than off my computer to break the chain and be able to place it where I want it.
    1. I did look into battery power, little bit nervous about using LiPo batteries though, especially in Australia as it gets pretty hot here
  4. Learn how to solder
    1. Need to pick up a soldering iron as well as a soldering kit.
  5. Solder the temperature sensor design together so I can move past the breadboard
  6. Create an enclosure for it so that it looks a bit more attractive
  7. Output the data to some form of persistent dashboard
    1. Looking at setting up Home Assistant for this
  8. Create multiple sensors and have everything working together

Other assorted things I’ve learnt

Bonus: Garduino

The basic Garduino that I was able to get going used:

  1. An Arduino Uno
  2. The DFRobot Capacitative Soil Moisture Sensor - SEN0193
  3. A DHT22 Temperature and Humidity Sensor (AM2302)

I was able to wire all of this together as follows:

Garduino v1 Prototype

And then run this pretty basic code:

#include <DHT_U.h>
#include <DHT.h>

#define DHTPIN 4     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

DHT dht(DHTPIN, DHTTYPE);

const int AirValue = 520;   // My Calibrated Air Value
const int WaterValue = 294;  //Value when placed in a glass of water
int soilMoistureValue = 0;
int soilmoisturepercent = 0;

void setup() {
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
  dht.begin();

}

void loop() {
  soilMoistureValue = analogRead(A0);  //put Sensor insert into soil
  soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);

  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  float heat_index = dht.computeHeatIndex(temperature, humidity, false);
  
  Serial.print("The Soil is: ");
  Serial.print(soilmoisturepercent);
  Serial.print("% Moist, Sensor Reading: ");    
  Serial.print(soilMoistureValue);
  Serial.print(", Air Temperature is: ");
  Serial.print(temperature);
  Serial.print(", Air Humidity is: ");
  Serial.print(humidity);
  Serial.print(", Heat Index: ");
  Serial.println(heat_index);

  delay(4000);
}

Which gives me the following lovely output:

Garduino Output

It ain’t super pretty in any way but most importantly it works. Lots to do and more to build on top of I think. That wraps up this post, excited to see what comes next.