Remote Temperature Monitoring and Control System Using Wi-Fi Arduino and Telegram
by hamedkiany in Circuits > Arduino
320 Views, 2 Favorites, 0 Comments
Remote Temperature Monitoring and Control System Using Wi-Fi Arduino and Telegram
Remote Temperature Monitoring System with ESP8266 & Telegram Integration
This project was developed for 'Electrónica Creativa' (Creative Electronics), a BEng Electronic Engineering 4th year module at the University of Málaga, School of Telecommunications (http://etsit.uma.es/) by Hamed Kiany and Xiang ming Fan.This project uses the ESP8266 microcontroller to build a system that checks and controls temperature from a distance. It also sends updates and takes commands through Telegram messages. The system helps track environmental conditions and allows users to manage it remotely. It includes features like turning lights on and off, sending alerts when the temperature is too high or low, checking battery levels, and more.
Main Features
Temperature Monitoring & Alerts
- The system reads temperature data from a DHT11 sensor.
- Users can set a temperature range (lowest and highest).
- If the temperature goes outside this range, the system sends an alert via Telegram.
- This is useful for places like greenhouses, server rooms, or storage areas.
Battery Monitoring
- The ESP8266 runs on a battery, and the system checks its charge level.
- If the battery drops below a set limit (e.g., 35%), it sends a Telegram alert.
- The battery level is shown as a percentage to make it easy to understand.
Remote Control with Telegram
Users can control the system through simple Telegram commands:
- /ledon and /ledoff → Turn the LED on or off.
- /temperature → Show the current temperature.
- /TemperatureRange Min Max → Set temperature limits for alerts.
- /sleep SleepTime → Put the system to sleep for a set time to save power.
- /status → Get system details (temperature range, battery level, LED state).
- /BatteryLevel → Check battery status.
- /OTA → Enable Over-the-Air (OTA) updates for remote software changes.
Power Saving Mode
- The system can enter deep sleep mode using the /sleep command.
- The user sets how long it should sleep, and it wakes up automatically after that time.
- This helps save battery, making the system last longer.
Wireless Updates (OTA)
- The ESP8266 allows software updates without needing to be physically connected.
- This makes it easy to fix issues or add new functions from a distance.
Wi-Fi Connection & Security
- The system connects to Wi-Fi using user-provided details.
- It communicates securely with Telegram using SSL protection.
- It syncs time automatically with the internet to keep logs accurate.
Supplies
Here's a list of materials and seller links you'll need for the Remote Temperature Monitoring System with ESP8266 & Telegram Integration:
Materials List:
- ESP8266 Microcontroller with extension
- A Wi-Fi enabled microcontroller (e.g., NodeMCU or Wemos D1 mini) to control the system and connect to the internet.
- Price : 1.89€
- DHT11 Temperature and Humidity Sensor
- A basic digital sensor for measuring temperature and humidity.
- Price : 0.65€
- LED
- A standard LED for indicating system status or as a visual indicator for control.
- MOSFET
- A MOSFET (e.g., SI2302ADS) to control the LED or other devices like fans, lights, etc.
- Price : 0.69€
- 10kΩ Resistor
- A pull-up resistor for the DHT11 sensor to ensure stable readings.
- Battery
- A rechargeable lithium-ion or LiPo battery (e.g., 3.7V 18650) to power the ESP8266 and sensors.
- Battery Charging Module (TP4056)
- A module to safely charge the Li-ion battery via micro-USB.
- Jumper Wires
- For making connections between the components (male-to-female and male-to-male).
- Breadboard
- For prototyping the circuit and making temporary connections.
- ESP8266 USB Cable
- A USB cable to connect the ESP8266 to the computer for programming.
- Diode (optional)
- A diode (e.g., 1N4007) for protecting the circuit when using a MOSFET to control external devices.
- Voltage Divider or Resistor (optional for Battery Monitoring)
- To monitor the battery voltage, you may need a resistor to create a voltage divider circuit.
- Arduino IDE or PlatformIO
- Software for programming the ESP8266 and uploading the code.
- Telegram Bot Token
- You need a Telegram bot, which can be created using the BotFather on Telegram to get the API token.
- Wi-Fi Network
- A local Wi-Fi network for the ESP8266 to connect to the internet and communicate with Telegram.
- Optional: Capacitors and Buzzer (for additional features)
- Capacitors may be needed for stability, and a buzzer can be added for audio alerts if desired.
This list includes all the necessary components to build the remote temperature monitoring and control system. Adjust quantities and specific parts based on your design and requirements.
Software
Code for Remote Temperature Monitoring System
Below is the code used to implement the Remote Temperature Monitoring System with ESP8266, DHT11 sensor, and Telegram integration. This code includes all necessary features: temperature measurement, communication with the Telegram bot, power-saving features like deep sleep, battery monitoring, and Over-the-Air (OTA) updates.
Installing Required Libraries in Arduino IDE
To run this project, you need to install the following libraries in the Arduino IDE. Follow the steps below to install them correctly.
📌 Required Libraries
- ESP8266WiFi – Manages Wi-Fi connection for ESP8266.
- Library Name: ESP8266WiFi
- 📦 Pre-installed with ESP8266 board package
- WiFiClientSecure – Enables encrypted (SSL) communication.
- Library Name: WiFiClientSecure
- 📦 Pre-installed with ESP8266 board package
- TelegramBot – Communicates with Telegram bots.
- Library Name: UniversalTelegramBot
- Installation: Available in Library Manager
- DHT – Reads temperature and humidity from the DHT sensor.
- Library Name: DHT sensor library
- Installation: Developed by Adafruit, available in Library Manager
- ArduinoOTA – Allows wireless firmware updates.
- Library Name: ArduinoOTA
- 📦 Pre-installed with ESP8266 board package
🔧 Steps to Install
- Open Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries...
- In the search bar, enter each library name (e.g., UniversalTelegramBot).
- Click Install for each library.
- Restart Arduino IDE to apply the changes.
After installing, you can include them in your code using:
✅ Now you’re ready to code and upload your project! 🚀
Complete Code:
Code Explanation:
- Wi-Fi Connection: The ESP8266 connects to a Wi-Fi network using the credentials you provide.
- DHT11 Sensor: The code reads the temperature data from the DHT11 sensor and formats it into a message.
- Telegram Bot: The system sends the temperature data to the user via the Telegram bot. It also listens for commands like /ledon and /ledoff to control the connected LED.
- Power Saving: After each cycle, the system enters deep sleep to save battery power. It wakes up after a specified period and repeats the process.
- OTA Updates: The system supports Over-the-Air (OTA) updates, allowing you to update the firmware without physically connecting the device.
How to Use the Code:
- Configure Wi-Fi and Telegram Bot Token: Replace YOUR_SSID, YOUR_PASSWORD, and YOUR_BOT_TOKEN with your actual Wi-Fi credentials and Telegram bot token.
- Upload the Code: Use the Arduino IDE to upload the code to your ESP8266 board. Ensure you select the correct board and port in the IDE.
- Set Up Telegram Bot: After uploading the code, interact with your Telegram bot to get temperature updates and send control commands.
This section provides clear instructions for anyone visiting your website to easily set up and use the provided code. It also highlights key parts of the code so they can understand its functionality and how to modify it for their own needs.
Downloads
Battery Voltage Checker
Battery Voltage Reading and Control Circuit
This part of the project handles battery voltage monitoring and integrates control functionality through an Arduino microcontroller. The circuit not only measures the battery's voltage but also allows the MOSFET to be switched on or off based on commands sent to the Arduino. This makes the circuit highly versatile for automation and remote control.
Circuit Description
Battery Input (V3)
The circuit is powered by an 2 x 3.7V DC battery (V3), which is the source voltage being monitored.
Voltage Divider (R4 and R5)
Resistors R4 (2.2kΩ) and R5 (1kΩ) form a voltage divider to step down the battery voltage to a safe level for both the MOSFET and the Arduino.
This ensures that the voltage at the MOSFET’s gate remains within acceptable limits.
MOSFET Control (M1 - SI2302ADS)
The SI2302ADS is an N-channel MOSFET. Its operation (on or off) is controlled by the voltage applied to its gate.
- The Arduino controls the MOSFET gate, allowing it to turn the MOSFET on or off.
- This feature enables the system to either read the battery voltage when needed or disable the measurement to save energy.
Output Voltage (Vout) and Connection to Arduino
- Vout is the scaled-down voltage output, which corresponds to the battery’s voltage.
- The A0 pin of the Arduino is connected to both R6 (1kΩ) and the MOSFET’s source terminal.
- The resistor R6 acts as a current-limiting resistor, ensuring stable and safe signal transmission to the ADC (Analog-to-Digital Converter) pin of the Arduino.
3.3V Reference
- A 3.3V reference is connected to the MOSFET’s source terminal, ensuring proper operation with the Arduino and other 3.3V logic systems.
Arduino Integration and Remote Control
- Control Logic: The Arduino is connected to the MOSFET’s gate, allowing it to toggle the MOSFET’s state. This provides precise control over when the battery voltage is read.
- Communication Protocol: The Arduino is programmed to listen for a command, such as "READ", sent through a serial interface (e.g., via USB, UART, or a wireless module like ESP8266).
- When the "READ" Command is Received:
- The Arduino turns the MOSFET on by setting the gate pin high.
- It measures the voltage at Vout using an ADC pin and calculates the actual battery voltage based on the voltage divider ratio.
- The measured voltage is sent back to the sender (e.g., a computer, smartphone app, or IoT system) as a response.
- When an "OFF" Command is Received:
- The Arduino sets the MOSFET’s gate pin low, turning the MOSFET off.
- This disconnects the circuit, reducing power consumption and protecting the system from unnecessary measurements.
How It Works
- The Arduino communicates with a user or system via serial commands.
- When a "READ" command is sent:
- The Arduino turns on the MOSFET.
- It reads the scaled voltage from Vout and calculates the battery voltage using the formula:
Vbattery = Vout * (R4+R5)/R5
- The Arduino sends the calculated battery voltage back to the user/system.
- When no monitoring is required, the "OFF" command disables the MOSFET to conserve power.
Applications
- Remote Voltage Monitoring:
- Ideal for IoT systems where battery levels need to be monitored remotely.
- Power Control:
- Allows the user to enable or disable voltage monitoring on demand, optimizing energy usage.
- Automation:
- Can be integrated into a smart home or industrial system to send alerts or take actions when the battery voltage drops below a threshold.
3D Printed Enclosure
Custom 3D Printed Enclosure for ESP8266-Based Project
This enclosure is designed to house an ESP8266 development board along with additional electronic components and wiring. It provides a clean, compact, and organized setup, offering easy access to key parts while protecting the electronics.
How to Use This Enclosure
- Print the Enclosure
- Download the STL file and print the enclosure using PLA or PETG material.
- Suggested print settings:
- Layer Height: 0.2mm
- Infill: 20-30%
- Print Time: ~4-6 hours, depending on the printer.
- Prepare the Electronics
- Place the ESP8266 NodeMCU board inside the enclosure, aligning it with the designated slots.
- Secure any additional PCB or prototyping board in the allocated space.
- Route wires through the provided slots to ensure a neat setup.
- Assemble the Enclosure
- Connect all necessary components and verify that the wiring is correct.
- Close the enclosure using the removable lid, which can either be snapped or screwed into place.
- Mount the Enclosure (Optional)
- If needed, use the pre-drilled mounting holes at the bottom to attach the enclosure to a wall, desk, or another surface.
Design Features
Custom Fit for ESP8266
- Specifically designed for an ESP8266 NodeMCU, keeping it securely mounted.
- Openings for GPIO pins, USB power input, and the reset button ensure accessibility.
Component Placement
- Dedicated space for a custom PCB or prototyping board.
- Allows expansion of the circuit by adding additional components.
Cable Management
- Pre-designed slots and holes for clean wire routing.
- Prevents tangling and provides a professional finish.
Modular Lid Design
- Removable lid for easy access during maintenance or modifications.
- Can be snapped or screwed into place.
Compact & Efficient Design
- Small footprint while accommodating all required components.
- Optional ventilation slots for better heat dissipation in long-running projects.
Mounting Options
- Pre-drilled holes allow secure attachment to walls, desks, or other surfaces.
Design Process
This enclosure was designed using Fusion 360 (or Tinkercad), based on the exact dimensions of the ESP8266 board and other components. The design includes:
- Space for wires
- Mounting holes
- A precise fit for the board
The final model was exported as an STL file for 3D printing.
Applications
This custom enclosure is ideal for:
✅ IoT projects using ESP8266/NodeMCU.
✅ Home automation systems.
✅ Battery-powered or sensor-based devices.
✅ Prototyping projects where a clean and organized setup is essential.
Download Files & Get Updates From GitHub
You can find all the necessary files, schematics, and the latest updates for the Remote Temperature Monitoring System with ESP8266 & Telegram Integration on my GitHub page.
🔗 GitHub Repository: Remote Temperature Monitoring System
This repository includes:
✅ Source code for ESP8266
✅ Circuit schematics and wiring diagrams
✅ 3D printed enclosure files (if applicable)
✅ Firmware updates and improvements
Make sure to check for updates regularly to get the latest improvements and fixes! 🚀