BrainyLED is a proximity enabled diode where a HC-SR04 sensor is connected with the arduino to provide a trigger if an object is detected in the sensor's vicinity. This trigger is set in such a way that the user can obtain an accurate read.
Therefore, a Threshold value is defined by the user so that whenever the sensor value is less that threshold it provides a trigger which is used to switch on the LED.
An alert system is setup using BOLT cloud to provide a telegram message whenever the LED switches ON and sends a message "ObjectDetectedInProximity!".
2. DEMONSTRATIONConfiguration file (Conf.py)
This file contains all the details about the Api's and other necessary values to provide a successful connection.
"""Configurations"""
bolt_api_key = "<Api_key>" # This is your Bolt Cloud API Key
device_id = "BOLTXX" # This is the device ID
telegram_chat_id = "@XXXX" # This is the channel ID of the created Telegram channel.
telegram_bot_id = "botXXXXX" # This is the bot ID of the created Telegram Bot.
Python File (proximity.py)
Contains the BOLT IoT code for establishing a connection with arduino using serial input.
import requests
import conf
from boltiot import Bolt
import json, time
mybolt = Bolt(conf.bolt_api_key, conf.device_id) #Create object to fetch data
response = mybolt.serialRead('10')
print (response)
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 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:
response = mybolt.serialRead('10') #Fetching the value from Arduino
data = json.loads(response)
status_value = data['value'].rstrip()
if str(status_value) == 'HIGH':
print ("Status is", status_value)
message = "Object detected in proximity!"
telegram_status = send_telegram_message(message)
else:
print ("Status is LOW!",status_value)
time.sleep(10)
Arduino code provided for smart LED with ultrasonic sensor.
#include <Ultrasonic.h>
Ultrasonic ultrasonic(5, 6);
int LED = 2;
int threshold = 100;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int distance = ultrasonic.distanceRead();
if(distance< threshold)
{
digitalWrite(LED, HIGH);
Serial.println("HIGH");
delay(10000);
}
else{
digitalWrite(LED,LOW);
}
delay(1000);
}
Comments
Please log in or sign up to comment.