Brijesh Chawan
Created June 30, 2020 © GPL3+

Overheating Detector

Overheating is a major issue in electronic devices (especially for prolonged users). With an LM 35 sensor and bolt cloud we can send alerts.

IntermediateFull instructions provided4 hours3
Overheating Detector

Things used in this project

Hardware components

Temperature Sensor
Temperature Sensor
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Buzzer
Buzzer
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App

Story

Read more

Code

conf.py

Python
Code for Credentials and Temperature Threshold
"""Configurations for telegram_alert.py"""
bolt_api_key = "342204d8-6fe2-4c85-8401-60c640ec6ece"              
device_id = "BOLT1115602"                  
telegram_chat_id = "@boltiotlearning"         
telegram_bot_id = "bot1381669554:AAFGB4kDaCD0isG72-EmSJJ3BhP_4Jrw1lg"        
threshold = 500                     

telegram_alert.py

Python
The main code for sending Telegram message and getting pin readings.
import requests                 # for making HTTP requests
import json                     # library for handling JSON data
import time                     # module for sleep operation

from boltiot import Bolt        # importing Bolt from boltiot module
import conf                     # config file

mybolt = Bolt(conf.bolt_api_key, conf.device_id)

def get_sensor_value_from_pin(pin):
    """Returns the sensor value. Returns -999 if request fails"""
    try:
        response = mybolt.analogRead(pin)
        data = json.loads(response)
        if data["success"] != 1:
            print("Request not successfull")
            print("This is the response->", data)
            return -999
        sensor_value = int(data["value"])
        return sensor_value
    except Exception as e:
        print("Something went wrong when returning the sensor value")
        print(e)
        return -999


def send_telegram_message(message):
    """Sends message via Telegram"""
    url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
    data = {
        "chat_id": conf.telegram_chat_id,
        "text": message
    }
    try:
        response = requests.request(
            "POST",
            url,
            params=data
        )
        print("This is the Telegram URL")
        print(url)
        print("This is the Telegram response")
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("An error occurred in sending the alert message via Telegram")
        print(e)
        return False


while True:
    # Step 1
    sensor_value = get_sensor_value_from_pin("A0")    
    print("The current sensor value is:", sensor_value)
    
    # Step 2
    if sensor_value == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue
    
    # Step 3
    if sensor_value >= conf.threshold:
        print("Sensor value has exceeded threshold")
	      response = mybolt.digitalWrite ('0', 'HIGH')
        message = "Alert! Your Device is overheating. Please turn off for some time. " 
        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)
	      response = mybolt.digitalWrite ('0', 'LOW')
	
	
    # Step 4
    time.sleep(10)

Credits

Brijesh Chawan

Brijesh Chawan

0 projects • 0 followers

Comments