Introduction: Esp-32 Based Temperature and Humidity Tracing Via Telegram
This project is very simple device for tracing temperature an humidity values of an egg incubator via Telegram. It can notify you via Telegram bot if sensor values changes. You can also calibrate temp/humidity values or change notification settings. Usage is not limited for egg incubators, you can use this setting to track any temp / humidity related projects: Just attach the sensor to your own project.
To make it simple; there is no configuration to "Control" the temp and humidity, but project can be improved by adding relays.
All you need is a esp based microcontroller, a temperature/humidity sensor and wifi connection!
There is no need to compile an app or try to connect to an ip to configure settings. Everything can be controlled and traced from Telegram!
With the help of Preferences library in the code; your settings will be saved even in power outages!
Supplies
- Esp-32 Based microcontroller ( Esp-32 devkit V1 wroom-32 in this example)
- Dht-22 Temperature and humidity sensor ( Shrink tube is optional for long term usage - temperature and humididty won't harm circuit very much.)
- Cables to connect.
Step 1: Circuit
Circuit is quiet simple: 3 wires required for wiring. DHT-22 uses 3v to run,so wire esp-32 3v3 pin to dht22 (+) pin. Wire esp-32 GND pin to DHT-22 (-) pin. Wire esp-32 D21 pin to Dht-22 (out) pin.
I didn't use another voltage input rather than micro-usb socket. So 5v phone charger made it to work.
Step 2: Telegram Configuration
- Download and sign in to Telegram if you don't have.
- Write @BotFather in search area in Telegram. Write /start to it.
- Enter /newbot command to create a new bot for you.
- Botfateher will ask you its name. Give your bot a name and enter it.
- Botfather will give you a BOTTOKEN. A long key. You will need this in arduino code.
- In search area write idbot and you will see @myidbot. Enter it.
- Write /start command and after that write /getid command. It will give you a numeric CHAT ID . It is required in arduino code. With chat id, bot only responds to you, so only you can use and control your bot, and through your bot; your esp-32 device.
- If you want more than one user, you can find your group id by entering /getgroupid in @myidbot, follow its instructions and use it too.
- You can use another user's chat id, so that user can control the bot. (You don't have to be bot owner to use the bot) Only one chat id or group id can be used in the code.
Step 3: Arduino Code
- Download the code from : https://github.com/eminokkol/telegram-dht-dog or from the attachment.
- Open ino file with Arduino IDE software.If you don't have Arduino IDE software, you can download it from here.
- Change required fields in the code. Write your own BOTTOKEN, CHAT ID and wifi connection credentials. Default temperature mode is Celcius. If you want to use Fahrenheit, change #define DEGREE "C" to #define DEGREE "F". Define day_show 1 to show day counter, 0 to hide. Make sure to reset device via /reset command in order to make counter work properly. Reset makes the day count to "0".
- Cofigure your time zone in #define configure_time() area. Default is for Turkey, 3*3600 is GMT+3.
- Connect your esp-32 to your pc.
- In Arduino IDE, select board: "DOIT ESP32 DEVKIT V1" and your port.
- Upload your code to your microcontroller with Arduino IDE. (Don't forget to click "BOOT" button on wroom-32 when uploading starts.)
Attachments
Step 4: Telegram Bot Usage
In Telegram, search for your bot's name, when you find it, write /start command to see available commands.
All commands have detailed explanations.
When measured temperature is higher than warn_temp_h ; you will get notification.
When measured temperature is lower than warn_temp_l ; you will get notification.
When measured humidity is higher than warn_humi_h ; you will get notification.
When measured humidity is lower than warn_humi_l ; you will get notification.
If notification status is closed you won't get any notification but you can always check sensor values with /temperature command.
Notification interval is the period of time when a notification repeats(if there is an unusual condition of course). Without this setting, device sends you notification in every 3 seconds.
Temperature calibration is for calibrating your sensor temperature. For example if your dht-22 sensor measures 3 degrees less than another sensor that you trust more; you can set it to "3" . If it measure 3 degrees more, you can set it to "-3" .
Humidity calibration also works like above. You can set plus or minus values.
In your first installation, all settings will be zero. If you reset via /reset command, default values will be applied and microcontroller will reset itself. The default values of settings are just like this:
High temp : 39 (warn_temp_h)
Low temp: 34 (warn_temp_l)
High humidity : 100 (warn_humi_h)
Low humidity: 45 (warn_humi_l)
Notifications: closed (alarm_off)
Notification interval: 10 (intervalt)
Other values : 0 (calibr_temp , calibr_humi)
Step 5: Optional: Bot Menu
Bot menu is optional but it can be easier to access all commands.
For bot menu, you can go to BotFather->enter this command: "/mybots" -> select bot-> edit bot -> edit commands
and enter below without quotes:
"
start - Start bot
temperature - Current temp and humidity.
timenow - Current date and time of device
current_settings - Show calibration, low and high temp and humidity settings
warn_temp_h - Enter high temp warning temperature
warn_temp_l - Enter low temp warning temperature
warn_humi_h - Enter high humidity warning value (%)
warn_humi_l - Enter low humidity warning value (%)
alarm_on - Switch on Notifications
alarm_off - Switch off Notifications
state - Notification status
intervalt - Enter notification interval (minute)
calibr_temp - Enter temp calibration value
calibr_humi - Enter humidity calibration value
reset - Reset all settings to default values.
"
Step 6: Attaching Sensor
A quick tip for attaching sensor to an egg incubator: There are holes in all incubators on sale to get air inside it. Holes can be under the box sometimes. Wires can be inserted through theese holes and sensor can be attached inside. For example a Chinese made incubator's one hole was enough to insert all 3 cables for sensor. So when sensor is doing its job inside; your microcontroller can work outside without the harming effect of heat and humidity.
Step 7: Troubleshooting
- After uploading your code, if everyting is OK; you will see temp and humidity values in serial monitor in Arduino IDE. If you see "Failed to read from DHT sensor!" error, control cables. Control the pins. If the issue is not cables, control your sensor.
- In Telegram bot, you have to write /start command to make it start at first.
- If there is no answer in Telegram, your microcontroller may not be connected to wifi network.
- If your bot responds with "Unauthorized user" ; check your CHAT ID.