Skip to content

Oliversenseii/Temperature-and-Humidity-Monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌡️ Temperature & Humidity Monitor

A simple IoT monitoring system that reads temperature and humidity from a DHT22 sensor, sends the data over WiFi to a Flask backend, and stores it in a Supabase database for tracking and alerting.


Architecture

DHT22 Sensor
     ↓
ESP8266 (Arduino)
     ↓ HTTP POST (JSON)
Flask Server (deployed / local)
     ↓
Supabase (PostgreSQL cloud database)

Files

File Purpose
temp_humidity_monitor.ino Upload to ESP8266 via Arduino IDE
server.py Python Flask server
.env Supabase credentials (never commit this!)
requirements.txt Python dependencies

Supabase Setup

  1. Go to https://supabase.com and create a free account
  2. Create a new project
  3. Go to SQL Editor and run this to create the table:
CREATE TABLE readings (
  id          BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  temperature FLOAT        NOT NULL,
  humidity    FLOAT        NOT NULL,
  alert       BOOLEAN      NOT NULL DEFAULT FALSE,
  timestamp   TIMESTAMPTZ  NOT NULL DEFAULT NOW()
);
  1. Go to Project Settings → API
  2. Copy your Project URL and anon public key
  3. Paste them into .env:
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_KEY=your-anon-key-here

Server Setup

pip install -r requirements.txt
python server.py

Deploy Server (optional)

To make it accessible from anywhere, deploy server.py to:

Add your .env values as environment variables in the platform dashboard. Never upload your .env file to GitHub.

After deploying, update the Arduino code:

const char* SERVER_URL = "https://your-deployed-server.railway.app/log";

Arduino Setup

Required Libraries

Install via Arduino IDE → Library Manager:

  • DHT sensor library by Adafruit
  • Adafruit Unified Sensor by Adafruit

ESP8266WiFi and ESP8266HTTPClient come with the ESP8266 board package.

Board Manager URL

Add under Arduino IDE → Preferences → Additional Board URLs:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Configure the Code

const char* WIFI_SSID     = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* SERVER_URL    = "http://YOUR_SERVER_URL/log";

Wiring

DHT22
  VCC  → 3.3V
  GND  → GND
  DATA → D2

Green LED (+) → 220Ω → D5
Red LED   (+) → 220Ω → D6
Buzzer    (+) → D7
All       (-) → GND

Alert Behavior

Condition Green LED Red LED Buzzer
Normal ON OFF Silent
Temp > 35°C or Humidity > 80% OFF ON Beep

API Endpoints

Method Endpoint Description
POST /log Save sensor reading
GET /readings Last 50 readings
GET /readings/latest Most recent reading
GET /readings/alerts Alert readings only
GET /readings/stats Avg / Max / Min stats
DELETE /readings/delete Clear all records

Troubleshooting

Problem Solution
Supabase connection error Check .env values are correct
ESP8266 won't connect Double-check WiFi credentials
Server response -1 Check SERVER_URL in .ino
Sensor reads NaN Check DHT22 wiring, use 3.3V not 5V
ModuleNotFoundError Run pip install -r requirements.txt

About

ESP8266 + DHT22 sensor that sends real-time temperature and humidity readings, with logging and alerts

Topics

Resources

Stars

Watchers

Forks

Contributors