NP Vishwajith
Published

The 30-40 Finder, Specific Area Monitoring Device using BOLT

Hey there meet the 30-40 finder, why 30-40? Well it monitors between a distance of 30 cm and 70 cm and so got a fancy name for it.

BeginnerFull instructions provided2 hours407
The 30-40 Finder, Specific Area Monitoring Device using BOLT

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Arduino UNO
Arduino UNO
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Schematics

Schematic File

Schematic Pic

BreadBoard Schematic

Here is a breadboard view of this project

Code

Python Code

Python
from boltiot import Bolt, Sms
import json, time

'''Using the boltiot library for configuring the bolt device , Sms is used to send custom message to any phone number
json is library present by default in python it is used to turn json type data into a python dictionary
time is used for delaying the code so that you wont receive infinite messages.'''

SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find  on 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 accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'

mybolt = Bolt(API_KEY, DEVICE_ID)#Create a bolt object
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)

while True:
   response = mybolt.serialRead('10')# Fetching the serial data from Arduino
   data = json.loads(response) #Using json to load the response as a python dictionary
   dist = data['value'].rstrip() #rstrip is used to remove any special characters in the data
   print(f"Object found at {dist} cm")
   respond = sms.send_sms(f"An object has been found at {dist} cm")#SMS is send if object is detected
   time.sleep(50) #The while loop executes only once every 50 seconds

Arduino Code

Arduino
#include <Servo.h> //The servo header files can be used to operated servo motors with ease

// The trigger and echo of the ultrasonic sensor are connected to digital pins 5 and 6 of Arduino
const int trigPin = 5; 
const int echoPin = 6;
//Duration and distance are for measuring distance between sensor and obstacle
long duration;
int distance;
Servo myServo; // Creates an object myservo of type Servo
 
void setup() 
{
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  Serial.begin(9600);
  myServo.attach(11);
  // The control pin of servo is attached to digital pin 11 of Arduino
 // Make sure that the control is connected to a digital PWM pin and not a normal digital pin 
}
void loop() //The main loop
{
  for(int i=15;i<=165;i++)
  {  
    myServo.write(i);//write function writes the value into servo so it will spin that much degrees
    //from its initial position
    delay(30);
    distance = calculateDistance();//A calculateDistance function that returns the distance between
    //Obstacle and sensor
    if (distance > 30 && distance < 70)//The distance is printed in serial port only if the 
    //obstacle is between 30 and 70 cm  from the sensor
      {
      Serial.println  (distance); 
      }
  }
  for(int i=165;i>15;i--)//Same as above but the servo is going in reverse
  {  
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    if (distance > 30 && distance < 70)
      {
      Serial.println  (distance); 
      }
  }
}

int calculateDistance()//A function that returns the distance between sensor and obstacle as an
//integer
{ 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); //An ultrasonic signal is send
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW); // The signal is recieved 
  duration = pulseIn(echoPin, HIGH); // Calculates the duration it takes for the signal to travel 
  distance= duration*0.034/2; // The duration is turned into distance 
  return distance;
}

Credits

NP Vishwajith
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.