sarayu sree
Created December 28, 2020

Rainfall Detector- Voice notification, Mail, Telegram, SMS.

Don't let your pet get wet in rain outside, while you are taking a nap. get notified through this device by getting a voice notification.

71
Rainfall Detector- Voice notification, Mail, Telegram, SMS.

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Breadboard (generic)
Breadboard (generic)
×1
water sensor [REES52]
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Android App
Bolt IoT Android App
Notification Reader - Shouter
telegram

Story

Read more

Schematics

Circuit Connections

Code

Python Code

Python
"""bolt_api_key =  'This is your Bolt Cloud API Key.'
device_id =  'This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers.'
telegram_chat_id = 'This is the channel ID of the created Telegram channel. Paste after @ symbol.'
telegram_bot_id = 'This is the bot ID of the created Telegram Bot. Paste after bot text.'
threshold =  'set threshold here to 10'
SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find SID in your Twilio Dashboard'
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud account API key'
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'test@' + SANDBOX_URL  # No need to modify this. The sandbox URL is of the format test@YOUR_SANDBOX_URL
RECIPIENT_EMAIL = 'Enter your Email ID Here'"""


import requests, time, math, json
from boltiot import Sms,Bolt,Email
import conf	#my Configuration File

data = [] 	#Empty list for storing sensor values...
mybolt = Bolt(conf.bolt_api_key, conf.device_id) #My Bolt
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
mybolt.digitalWrite(0,"LOW")

#Function:Get Sensor Value
def get_sv(pin):
    try:
        response = mybolt.analogRead(pin)
        data = json.loads(response)
        if data["success"]!=1:
            print("Request Failed")
            print("Response:",data)
            return -999
        sensor_value = int(data["value"])
        return sensor_value
    except Exception as e:
        print("Something went wrong")
        print(e)
        return -999

#Function:Send Telegram Message
def send_tm(message):
    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 response=>")
        print(response.text)
        telegram_data = json.loads(response.text)
        return telegram_data["ok"]
    except Exception as e:
        print("Errror Occurred in sending the alert message")
        print(e)
        return False

#MAIN:->
while True:
    sensor_value = get_sv("A0")
    print("Sensor value is = ",sensor_value)

    if sensor_value == -999:
        print("Request unsuccessful.Skipping...")
        time.sleep(10)
        continue

    if(sensor_value >= conf.threshold):
        print("Alert:Water Level exceeded the threshold value")
        message = "hey Sarayu its raining outside.don't let your pet get wet.go get your pet inside"
        telegram_status = send_tm(message)
        response = sms.send_sms("Alert it's RAINING,The Current temperature sensor value is " + str(sensor_value))
        response = mailer.send_email("Alert", "The Current temperature sensor value is " + str(sensor_value))
        print("This is the telegram status:",telegram_status)
        mybolt.digitalWrite(0,"HIGH")
        time.sleep(60)
        mybolt.digitalWrite(0,"LOW")
    else:
        mybolt.digitalWrite(0,"LOW")

    data.append(sensor_value)
    time.sleep(10)

#END

JS Program

JavaScript
setChartLibrary('google-chart');
setChartTitle('Water Level Monitoring !!!');
setChartType('areaGraph');
setAxisName('Time Stamp', 'Water Level');
plotChart('time_stamp', 'temp');
//temp is the variable name

Credits

sarayu sree
1 project • 1 follower

Comments