Nidhishree
Published © GPL3+

SMART GARAGE USING BOLT IoT AND ARDUINO

Smart Garage lets you Open and Close the door of your garage using Google Assistant. Also equipped with smart lighting and parking assistant

IntermediateFull instructions provided3 hours6,637
SMART GARAGE USING BOLT IoT AND ARDUINO

Things used in this project

Hardware components

Arduino UNO Wifi Rev.2
Arduino UNO Wifi Rev.2
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
L293D motor driver module
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
DC Motor, 12 V
DC Motor, 12 V
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Bolt Cloud
Bolt IoT Bolt Cloud
Maker service
IFTTT Maker service
Assistant SDK
Google Assistant SDK
SMS Messaging API
Twilio SMS Messaging API

Story

Read more

Schematics

Block Diagram

Complete Connection Diagram

Code

Python Code for Sending SMS and Smart Lighting

Python
This python code will run on linux VPS which is connected to Bolt cloud. It will send SMS alerts when the garage is opened or closed.
#import conf file which contains bolt API key, bolt device ID, Twilio SID, Twilio AUTH token, TO number and FROM number

import conf,json,time
from boltiot import Bolt,Sms
mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)
sms = Sms(conf.SID,conf.AUTH_TOKEN,conf.TO_NUMBER,conf.FROM_NUMBER)

old_state = 0     #variable to save previous state information initialized to 0

while True:
   print("Reading value from Bolt")
   response = mybolt.digitalRead('1')
   data = json.loads(response)
   print (data)
   new_state = int(data['value'])   #retrieving new_state from the data
   if old_state != new_state:   #checking for change in state
   #Change in state indicates that the garage door is openend or closed
      try:
         if new_state == 1:    #value of new_state is 1 implies that garage door is open
            print("Making request to twilio to send SMS")   #sending an SMS to the TO NUMBER
            response = sms.send_sms("Garage is open")
            print ("Response received from twilio is:"+str(response))
            print ("Status of SMS at Twilio is :"+str(response.status))

         elif new_state == 0:     #value of new_state is 0 implies that garage door is closed
            print("Making request to twilio to send SMS")   #sending an sms to the TO NUMBER
            response = sms.send_sms("Garage is closed")
            print ("Response received from twilio is:"+str(response))
            print ("Status of SMS at Twilio is :"+str(response.status))

      except Exception as e:
         print("Error occured: Below are the details")
         print (e)
   old_state = new_state   #assign new_state value to the old_state for the next cycle
   time.sleep(20)     #wait for 20 seconds

Arduino UNO code for Smart Door and Parking Assistant

Arduino
This arduino code reads data from bolt wifi module and triggers further actions. DC motor code for smart door and ultrasonic code parking assistant with buzzer alert system included.
#include <Ultrasonic.h>    //Ultrasonic Simple - Prints the distance read by an ultrasonic sensor in centimeters
Ultrasonic ultrasonic(8,9);   //Pass as a parameter the trigger and echo pin
int bolt = 2;     //Reads the status of the pin connected to the bolt module
int enable = 3;   //Enable pin of LM293D motor driver
int in1 = 4;      //input pin 1 and 2 of LM293D motor driver
int in2 = 5;
int buz = 6;     // connected to the buzzer
int old_state = 0;    //variable to hold the previous state value of the pin connected to bolt. It is initialized to 0. Change in state indicates that the garage door is opened or closed.
int new_state;        // variable to hold the new state value
int distance;         // holds the distance between the vehicle and the garage wall
void setup() 
{
  //set bolt pin as input, motor pins as output, buzzer pin as output
  pinMode(bolt,INPUT);       
  pinMode(enable, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(buz, OUTPUT);
  //start serial communication with a baud rate of 9600
  Serial.begin(9600);
  //keep the motor off initially
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
}

void loop() 
{
  new_state = digitalRead(bolt);    //read the new state value from the pin conncted to bolt wifi module
  if (new_state != old_state)       //checking for change in state
  {
    if (new_state == 0)             //new state value is 0 indicates that the garage door should be closed
    {
      digitalWrite(buz,LOW);        //buzzer need not be ON when the garage is closed
      Serial.println("Closing Garage");   
      analogWrite(enable,255);     //rotate the motor in order to close the garage door
      digitalWrite(in1,HIGH);
      digitalWrite(in2,LOW);
      delay(4000);
      digitalWrite(in1,LOW);
      digitalWrite(in2,LOW);
      Serial.println("Garage Closed");
     }
     else if(new_state == 1)
     {
      Serial.println("Opening Garage");
      analogWrite(enable,255);     //rotate the motor in opposite direction to open the garage door
      digitalWrite(in1,LOW);
      digitalWrite(in2,HIGH);
      delay(4000);
      digitalWrite(in1,LOW);
      digitalWrite(in2,LOW);
      Serial.println("Garage Opened");
      }
  }
  old_state = new_state;      //assign new state value to old state for the next cycle of the loop
  if (new_state == 1)         //checking if the garage door is open
  {
    //trigger the ultrasonic sensor if the garage door is open
    distance = ultrasonic.read();
    Serial.print("Distance in CM: ");
    Serial.println(distance);
    if (distance < 30)   
    {
      Serial.println("STOP!");   
      digitalWrite(buz,HIGH);    //if the distance between the vehicle and garage wall is less than 30cms turn ON the buzzer
    }
    else
    {
      digitalWrite(buz,LOW);  
    }
    
  }
  
  delay(5000);    //repeat for every 5 seconds (5000ms)
}

Credits

Nidhishree

Nidhishree

1 project • 3 followers

Comments