Overview
Build an automated greenhouse controller that monitors temperature and humidity using a DHT22 sensor, turns on a fan when it gets too hot, activates a water pump when humidity drops, and sends Telegram alerts when conditions exceed safe ranges. This is a great first project for learning EdgeFlow with real hardware.
What You'll Need
Hardware
- * Raspberry Pi (any model with GPIO)
- * DHT22 sensor (or AM2302 module)
- * 5V relay module (2-channel)
- * 12V DC fan
- * Small water pump (5-12V)
- * Jumper wires and breadboard
Software
- * EdgeFlow installed on your Pi
- * Telegram account + Bot Token (from @BotFather)
- * Your Telegram Chat ID
Wiring Diagram
DHT22 Sensor
VCC → 3.3V (Pin 1)
DATA → GPIO4 (Pin 7)
GND → GND (Pin 9)
Fan Relay
VCC → 5V (Pin 2)
IN1 → GPIO17 (Pin 11)
GND → GND (Pin 6)
Pump Relay
VCC → 5V (Pin 4)
IN2 → GPIO27 (Pin 13)
GND → GND (Pin 14)
Importable Flow JSON
Copy this JSON and import it via Menu → Import in the EdgeFlow editor.
{
"name": "Smart Greenhouse Controller",
"nodes": [
{
"id": "dht22_1",
"type": "dht22",
"name": "Greenhouse DHT22",
"pin": 4,
"sensorType": "22",
"interval": 30,
"tempUnit": "C",
"x": 120,
"y": 200
},
{
"id": "switch_temp",
"type": "switch",
"name": "Temp > 28C?",
"property": "payload.temperature",
"rules": [
{ "t": "gt", "v": 28 },
{ "t": "lte", "v": 28 }
],
"x": 340,
"y": 160
},
{
"id": "switch_humid",
"type": "switch",
"name": "Humidity > 80%?",
"property": "payload.humidity",
"rules": [
{ "t": "gt", "v": 80 },
{ "t": "lte", "v": 80 }
],
"x": 340,
"y": 280
},
{
"id": "fan_on",
"type": "change",
"name": "Fan ON",
"rules": [
{ "t": "set", "p": "payload", "to": 1 }
],
"x": 540,
"y": 120
},
{
"id": "fan_off",
"type": "change",
"name": "Fan OFF",
"rules": [
{ "t": "set", "p": "payload", "to": 0 }
],
"x": 540,
"y": 180
},
{
"id": "gpio_fan",
"type": "gpio-out",
"name": "Fan Relay",
"pin": 17,
"mode": "digital",
"x": 720,
"y": 150
},
{
"id": "pump_on",
"type": "change",
"name": "Pump ON",
"rules": [
{ "t": "set", "p": "payload", "to": 1 }
],
"x": 540,
"y": 240
},
{
"id": "pump_off",
"type": "change",
"name": "Pump OFF",
"rules": [
{ "t": "set", "p": "payload", "to": 0 }
],
"x": 540,
"y": 320
},
{
"id": "gpio_pump",
"type": "gpio-out",
"name": "Pump Relay",
"pin": 27,
"mode": "digital",
"x": 720,
"y": 280
},
{
"id": "telegram_alert",
"type": "telegram",
"name": "Send Alert",
"botToken": "YOUR_BOT_TOKEN",
"chatId": "YOUR_CHAT_ID",
"x": 720,
"y": 400
},
{
"id": "format_alert",
"type": "function",
"name": "Format Alert",
"func": "var t = msg.payload.temperature;\nvar h = msg.payload.humidity;\nmsg.payload = '\u26a0\ufe0f Greenhouse Alert\n' + 'Temp: ' + t + '\u00b0C | Humidity: ' + h + '%\n' + (t > 28 ? 'Temperature is HIGH!\n' : '') + (h > 80 ? 'Humidity is HIGH!' : '');\nreturn msg;",
"x": 540,
"y": 400
},
{
"id": "debug_1",
"type": "debug",
"name": "Monitor",
"x": 340,
"y": 400
}
],
"connections": [
{ "from": "dht22_1", "to": "switch_temp" },
{ "from": "dht22_1", "to": "switch_humid" },
{ "from": "dht22_1", "to": "debug_1" },
{ "from": "switch_temp", "to": "fan_on", "fromPort": 0 },
{ "from": "switch_temp", "to": "fan_off", "fromPort": 1 },
{ "from": "fan_on", "to": "gpio_fan" },
{ "from": "fan_off", "to": "gpio_fan" },
{ "from": "switch_humid", "to": "pump_on", "fromPort": 0 },
{ "from": "switch_humid", "to": "pump_off", "fromPort": 1 },
{ "from": "pump_on", "to": "gpio_pump" },
{ "from": "pump_off", "to": "gpio_pump" },
{ "from": "switch_temp", "to": "format_alert", "fromPort": 0 },
{ "from": "switch_humid", "to": "format_alert", "fromPort": 0 },
{ "from": "format_alert", "to": "telegram_alert" }
]
} Step-by-Step Walkthrough
Wire the Sensors and Relays
Connect the DHT22 sensor to GPIO4 with a 10k pull-up resistor between DATA and VCC. Wire the 2-channel relay module with IN1 on GPIO17 (fan) and IN2 on GPIO27 (pump). Connect the fan and pump to the relay NO terminals with appropriate power supplies.
Import the Flow
Open EdgeFlow in your browser, go to Menu → Import, and paste the JSON above. The flow will appear in the editor with all nodes pre-wired.
Configure the Telegram Bot
Open Telegram and message @BotFather to create a new bot. Copy the bot token.
Then message your bot and visit the API URL to get your chat ID:
https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates Double-click the "Send Alert" node in EdgeFlow and paste your bot token and chat ID.
Deploy and Test
Click the Deploy button. The DHT22 node will start reading every 30 seconds. Check the Debug panel to see live temperature and humidity data. Hold a warm object near the sensor to test the fan relay, or breathe on it to raise humidity.
Configuration Details
| Parameter | Value | Description |
|---|---|---|
| DHT22 Interval | 30 seconds | How often the sensor is polled (min 2s) |
| Fan Threshold | 28°C | Fan turns ON above this temperature |
| Humidity Alert | 80% | Telegram alert fires above this humidity |
| GPIO Fan Pin | GPIO17 | Relay IN1 for exhaust fan control |
| GPIO Pump Pin | GPIO27 | Relay IN2 for water pump control |
Expected Output
The DHT22 node outputs this message every 30 seconds:
{
"payload": {
"temperature": 26.3,
"humidity": 65.8
},
"temperature": 26.3,
"humidity": 65.8,
"tempUnit": "°C",
"timestamp": 1707750000000,
"_msgid": "a1b2c3d4"
} When temperature exceeds 28°C, the Telegram alert message looks like:
⚠️ Greenhouse Alert
Temp: 31.2°C | Humidity: 72.4%
Temperature is HIGH! Troubleshooting
DHT22 shows "NaN" or checksum errors
- Add a 10kΩ pull-up resistor between DATA and VCC
- Keep wires under 20cm for reliable communication
- Increase the polling interval to 5s or higher
- Check that VCC is connected to 3.3V (not 5V for bare sensors)
Relay clicks but fan doesn't spin
- Verify the fan is connected to the NO (Normally Open) terminal
- Check that the external 12V power supply is connected
- Try swapping COM and NO connections
Telegram bot not sending messages
- Make sure you sent at least one message to your bot first
- Verify the bot token and chat ID are correct
- Check that the Pi has internet connectivity
- Look at the Debug panel for error messages