Today, we are going to create something practical! I will teach you how to use Arduino to make a device that measures temperature and humidity. Not only can the data be uploaded to the cloud, but if it gets too humid or hot enough to fry an egg, it will also sound an alarm to remind you. Let’s get started without any fluff!
Step 1: Gather Materials
First, let’s prepare the necessary components:
•One Arduino Uno board (other models are fine, just not too old)•DHT11 temperature and humidity sensor (about the size of a cigarette pack, with three pins)•ESP8266 WiFi module (the size of a fingernail, with an antenna)•One buzzer (make sure it can sound an alarm, don’t buy an LED bulb instead)•Red LED bulb with a 220Ω resistor•One breadboard and a bunch of jumper wires•A data cable that can transmit data, not just a charging cable
Step 2: Wiring Without Mistakes
1.DHT11 Wiring: Connect the middle pin (DATA) to digital pin 2, the left pin to 5V, and the right pin to ground. Remember to add a 4.7kΩ pull-up resistor to the DATA pin, just like you need to use a clip to secure clothes on a line.2.ESP8266 Wiring: This module needs a separate power supply! Connect VCC to 3.3V, GND to ground, TX to Arduino’s RX, and RX to TX. Note that this module is sensitive; too high voltage will cause it to smoke.3.Alarm Device: Connect the positive terminal of the buzzer to digital pin 8, the LED to digital pin 9, and the negative terminals to ground. Remember that the LED must be in series with a resistor, or it will turn into fireworks.
Step 3: Write Code Without Shaking Hands
Open the Arduino IDE, first install the libraries: Tools → Manage Libraries → search for “Adafruit DHT” and “Blynk” and install them. Then let’s get coding:
#include <DHT.h> #include <ESP8266_Lib.h> #include <BlynkSimpleStream.h>
#define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer; ESP8266 wifi(&Serial);
char auth[] = "Your Blynk Token"; // Don't copy this! Generate it in the Blynk App char ssid[] = "Your WiFi Name"; char pass[] = "WiFi Password";
void setup() { pinMode(8, OUTPUT); // Buzzer pinMode(9, OUTPUT); // LED Serial.begin(115200); wifi.restart(); Blynk.begin(auth, wifi, ssid, pass); dht.begin(); timer.setInterval(5000L, sendSensorData); // Send data every 5 seconds }
void loop() { Blynk.run(); timer.run(); }
void sendSensorData() { float h = dht.readHumidity(); float t = dht.readTemperature();
if (isnan(h) || isnan(t)) { Serial.println("Error! Sensor did not read data!"); return; }
Blynk.virtualWrite(V0, t); // Temperature to virtual pin V0 Blynk.virtualWrite(V1, h); // Humidity to V1
// Trigger alarm logic if(t > 30 || h > 70){ digitalWrite(8, HIGH); // Buzzer sounds digitalWrite(9, HIGH); // LED lights up Blynk.notify("Warning! Temperature/Humidity exceeded limits!"); // Notification to phone } else { digitalWrite(8, LOW); digitalWrite(9, LOW); } }
Step 4: Cloud Setup
1.Download the Blynk App on your phone and register an account.2.Create a new project, select Arduino Uno, and copy the generated Auth Token into your code.3.Add two dashboard widgets, binding them to virtual pins V0 (temperature) and V1 (humidity).4.Add a notification widget, setting the alarm thresholds to 30°C for temperature and 70% for humidity.5.Don’t forget to click the lightning icon in the top right corner to save.
Step 5: Practical Testing
1.Make sure to connect the wires correctly before powering on! Incorrect order can easily burn the board.2.Open the Serial Monitor to see if it shows that it has connected to WiFi.3.Blow on the sensor to see if the humidity value rises.4.Wave a lighter near the sensor (don’t actually burn anything!), check if the temperature exceeds 30°C and if the buzzer sounds.5.If your phone receives a notification, then everything is working fine.
Common Issues and Solutions
•Inconsistent Readings: Put a sponge wind shield on the DHT11, or replace it with a new one.•WiFi Connection Issues: Check if it is a 2.4G network; this module does not recognize 5G.•Slow Data Transmission: Change the Blynk server to Tencent Cloud by modifying the server address in the code.•Alarm Not Sounding: First, disconnect the buzzer and measure the voltage with a multimeter to ensure it is not a defective product.
Advanced Features
Once the basic functionality is working, you can continue to experiment:
1.Add a button to manually turn off the alarm.2.Store data in an Excel spreadsheet to create a line chart.3.Connect a relay to control air conditioning for dehumidification.4.Add an LCD screen to display real-time data.
Remember, playing with electronics is like cooking; when the time is right, it will naturally be delicious. At first, you may feel clumsy, but with practice, it will become smooth.