Pyndiah King
Published © GPL3+

Temperature sensor with buzzer alert SFM-27-1 using Telegram

Buzzer alert when temperature goes over a certain value. Message sent to user via Telegram APP.

IntermediateFull instructions provided2 hours1,373
Temperature sensor with buzzer alert SFM-27-1 using Telegram

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Buzzer Telegram DHT11 Sensor.zip

Python
Upload on Arduino IDE
/*
Pyndiah King
Project created using Brian Lough's Universal Telegram Bot Library.
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h> // Using Node MCU ESP8266 Library.
#include <UniversalTelegramBot.h>  // including the library of Telegram Bot
#include <ArduinoJson.h> // Using JSON Library.
#include "DHT.h"        // including the library of DHT11 temperature and humidity sensor
#define DHTTYPE DHT11   // DHT 11
// Replace with your network credentials
const char* ssid = "*****"; //WIFI Name.
const char* password = "*****"; //WIFI Password.
// Initialize Telegram BOT
#define BOTtoken "*****"  // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "*****" // Your bot ID.
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
// get value
#define dht_dpin D6 // Connect DHT11 vc pin to D6
DHT dht(dht_dpin, DHTTYPE);
int frequency = 1000; // Specified in Hz
int buzzPin = 4; // Connect buzz pin to D2
int timeOn = 1000; //Specified in milliseconds
int timeOff = 1000; //Specified in millisecods
void setup() {
dht.begin(); // Start
Serial.begin(9600); // Baud 9600
client.setInsecure();
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
//Display SSID
Serial.println(ssid); // Display SSID
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); //Start WIFI.
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(5);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
//Send message to Telegram for program start up.
bot.sendMessage(CHAT_ID, "Bot started up", "");
}
void loop() {
//Get Temperature and Humidity value from DHT11
// Variable h = Humidity Value.
float h = dht.readHumidity();
//Varible t = Temperature.Value
float t = dht.readTemperature();
delay(8);
//Convert float value to int
int stringTemp = round (t);
int stringHumi = round(h);
//Convert integer value to String
String a = String (stringTemp);
Serial.println(a);
String b = String(stringHumi);
Serial.println(b);
//Convert Humidy Value to Char
// Length (with one extra character for the null terminator)
int str_len = a.length() + 1;
// Prepare the character array (the buffer)
char char_array[str_len];
// Copy it over
a.toCharArray(char_array, str_len);
//Convert Temperature value to Char
// Length (with one extra character for the null terminator)
int str_lenb = b.length() + 1;
// Prepare the character array (the buffer)
char char_arrayb[str_lenb];
// Copy it over
b.toCharArray(char_arrayb, str_lenb);
//If Humidity value is Greater Than or Equal to 75
if (stringHumi >= 75) {
bot.sendMessage(CHAT_ID, "High Humidity : ", "");
bot.sendMessage(CHAT_ID, b);
}
else {
bot.sendMessage(CHAT_ID, "Low Humidity : ", "");
bot.sendMessage(CHAT_ID, b);
}
//If String value is Greater Than or Equal to 25
if (stringTemp > 25) {
bot.sendMessage(CHAT_ID, " High Temperature : ", "");
bot.sendMessage(CHAT_ID, a);
//Buzzer for one seconds.
tone(buzzPin, frequency);
delay(timeOn);
noTone(buzzPin);
delay(timeOff);
}
else {
bot.sendMessage(CHAT_ID, "Low Temperature : ", "");
bot.sendMessage(CHAT_ID, a);
}
bot.sendChatAction(CHAT_ID, "typing");
delay(1);
}

Credits

Pyndiah King
1 project • 0 followers
Contact
Thanks to Telegram Bot.

Comments

Please log in or sign up to comment.