Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Yella_Nikhil
Published

Trash Talker Using Bolt IoT

Things around us are dumb but not us. We can make them smart even a dustbin.

BeginnerFull instructions provided1 hour3,047
Trash Talker Using Bolt IoT

Things used in this project

Story

Read more

Schematics

Trash Talker circuit image

Code

Arduino code

Arduino
#include <Ultrasonic.h>
Ultrasonic ultrasonic(8,9);//(Trigger_Pin,Echo_Pin)
void setup() {
   Serial.begin(9600);
    }

void loop() {
  Serial.println(ultrasonic.distanceRead());
  delay(3000);
}

Python code to send alert

Python
from boltiot import Bolt, Sms #Import Sms and Bolt class from boltiot library  
import json, time,requests
SID="The SID in the Twilio account"
AUTH_TOKEN="Auth_token from twilio account"
TO_NUMBER="Phone number to which you want to send the message"
FROM_NUMBER="Number provided by Twilio"
Channel_ID="Telegram ChannelID"
Tele_BotID="Bot API key"
SMS=Sms(SID,AUTH_TOKEN,TO_NUMBER,FROM_NUMBER)                          
def Twilio_message(message):
        try:
                print('Sending message through twilio')
                response=SMS.send_sms(message)
                print('The status of twilio messsage is:',str(response.status))
        except Exception as e:
                print("Error occured in Twilio message",e)
                print(e)
                return False
def Tele_message(message):
        url='https://api.telegram.org/'+Tele_BotID+ '/sendMessage'
        data={'chat_id':Channel_ID,'text':message}
        try:
                response=requests.request("GET",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("Error occured in sending message via Telegram")
                print(e)
                return False
Bolt_ID="your bolt id"
API_Key='bolt api key"
garbage_full_limit = 7 # the distance between device and  garbage in dustbin
mybolt = Bolt(API_Key,Bolt_ID)#This is to access the bolt device and send commands
response = mybolt.serialRead('10')#fetch data from arduino
message="Hello Brother, the trash can is full"
while True:
        response = mybolt.serialRead('10')  #Fetching the value from Arduino 
        data = json.loads(response)
        garbage_limit = data['value'].rstrip()
        print("Garbage level is", garbage_limit)
        if int(garbage_limit)<garbage_full_limit:
                Twilio_message(message)
                Tele_message(message)
        time.sleep(10)

Credits

Yella_Nikhil
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.