INTRODUCTION.
Queue management systems and their potential in the times of social distancing.
VIDEO:
HOW IT WORKS
It is simply based on the formula of ultrasonic sensor.
but here formula is same but readings are different which we are going to see further in the project.the program will calculate the speed when the object is passed through the sensors and the distance between the sensors is 8 inch.So when we are calculating fps we will take (fps=666666/12) in the program. 12 is the inches of foot and 666666 is 8/12.
Both the sensors work at the same time and calculates the distance. if than distance is less than 100 than the sensor whoes reading is less than 100 led glows and a message is sent to the violators phone through twilio.and the photo of the person is captured in rpi camera module.
CONNECTIONS:
1.) connect the raspberry pi to arduino with a usb cable and use les/devttyACM0 port for serial communication between rpi and ardunio
2)rx of bolt with tx of arduino and vice versa
3)for forward ultra sonic sensor:
TRIG PIN GPIO26
ECHO PIN GPIO19
4)for backward ultra sonic sensor:
TRIG PIN GPIO17
ECHO PIN GPIO27
5)connect M1, M2, M3, M4 of arduino shiled to respective bo motors.
6)forward led and backward led to there respective ultrasonic sensor.(led are optional)
7)connect vcc and gnd of arduino shiled to bolt wifi module.
8)camera moudle to raspberry pi
9)power source:
a)power bank 10000maH
b)lipo battery 12v
c)DC 9V battery 2 in series.
A)SETUP THE ARDUINO:
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
void setup() {
Serial.begin(9600); // set baud rate
Serial.setTimeout(50);
Serial.println("WELCOME++++");
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
void loop() {
String ch;
if (Serial.available() > 0) {
ch= Serial.readString();
Serial.println(ch);
if (ch=="F") {
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
if(ch=="B"){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}
if(ch=="L"){
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
}
if(ch=="S"){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
if(ch=="LF"){
motor1.run(RELEASE);
motor2.run(FORWARD);
motor3.run(RELEASE);
motor4.run(FORWARD);
}
if(ch=="RF"){
motor1.run(FORWARD);
motor2.run(RELEASE);
motor3.run(FORWARD);
motor4.run(RELEASE);
}
if(ch=="LB"){
motor1.run(RELEASE);
motor2.run(BACKWARD);
motor3.run(RELEASE);
motor4.run(BACKWARD);
}
if(ch=="RB"){
motor1.run(FORWARD);
motor2.run(RELEASE);
motor3.run(FORWARD);
motor4.run(RELEASE);
}
if(ch=="R"){
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
}
}
}
B)setup the raspberry pi:1)for ultrasonic forward:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG=17
ECHO=27
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)
time.sleep(2)
def valf():
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distancej = pulse_duration*17150
distance = round(distancej, 2)
return distance
2)for ultrasonic back:import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG=19
ECHO=26
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)
time.sleep(2)
def valb():
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distancem = pulse_duration*17150
distance = round(distancem, 2)
return distance
3)for message service:import boltcrd
from boltiot import Sms, Bolt
import json, time
import credentials
mybolt = Bolt(boltcrd.api_key, boltcrd.device_id)
sms = Sms(credentials.account_sid,credentials.auth_token,credentials.my_mobile,credentials.my_cell)
def sendit():
while True:
print ("Reading sensor value")
response = mybolt.digitalRead('0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value<=100:
print("Making request to Twilio to send a SMS ")
response = sms.send_sms("maintain social distance" +str(sensor_value))
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)
time.sleep(10)
NOTE:create a boltcrd which have your API_KEY and BOLTIDAND credentials for twilio.
3)the main code:
from ultrab import valb
from ultraf import valf
import RPi.GPIO as GPIO
import time
from picamera import PiCamera
from servercode import sendit
GPIO.setmode(GPIO.BCM)
ledb=21
ledf=22
GPIO.setup(ledb,GPIO.OUT)
GPIO.setup(ledf,GPIO.OUT)
while True:
try:
x=valb()
print(x)
y=valf()
print(y)
if x<=100 or y<=100:
print("got it")
camera=PiCamera()
camera.capture("pritam.jpg")
print("captured")
if x>=y:
GPIO.output(ledb, True)
time.sleep(5)
GPIO.output(ledb, False)
if y>=x:
GPIO.output(ledf, True)
time.sleep(5)
GPIO.output(ledf, False)
sendit()
except:
GPIO.cleanup()
4)code to run the bot from mobile:# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'queuebot.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def startclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialBegin("9600")
print(response)
def LFclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("LF")
print(response)
def forwardclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("F")
print(response)
def RFclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("RF")
print(response)
def Lclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("L")
print(response)
def STclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("S")
print(response)
def RIclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("R")
print(response)
def LBclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("LB")
print(response)
def BAclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("B")
print(response)
def RBclick(self):
from boltiot import Bolt
api_key = "91a27806-4174-4001-9d24-b42a37a3a513"
device_id = "BOLT5778783"
mybolt = Bolt(api_key, device_id)
response=mybolt.serialWrite("RB")
print(response)
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(917, 1134)
self.layoutWidget = QtWidgets.QWidget(Dialog)
self.layoutWidget.setGeometry(QtCore.QRect(11, 105, 891, 981))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.start = QtWidgets.QPushButton(self.layoutWidget)
self.start.setObjectName("start")
self.gridLayout.addWidget(self.start, 0, 1, 1, 1)
self.LF = QtWidgets.QPushButton(self.layoutWidget)
self.LF.setObjectName("LF")
self.gridLayout.addWidget(self.LF, 1, 0, 1, 1)
self.forward = QtWidgets.QPushButton(self.layoutWidget)
self.forward.setObjectName("forward")
self.gridLayout.addWidget(self.forward, 1, 1, 1, 1)
self.RF = QtWidgets.QPushButton(self.layoutWidget)
self.RF.setObjectName("RF")
self.gridLayout.addWidget(self.RF, 1, 2, 1, 1)
self.L = QtWidgets.QPushButton(self.layoutWidget)
self.L.setObjectName("L")
self.gridLayout.addWidget(self.L, 2, 0, 1, 1)
self.ST = QtWidgets.QPushButton(self.layoutWidget)
self.ST.setObjectName("ST")
self.gridLayout.addWidget(self.ST, 2, 1, 1, 1)
self.RI = QtWidgets.QPushButton(self.layoutWidget)
self.RI.setObjectName("RI")
self.gridLayout.addWidget(self.RI, 2, 2, 1, 1)
self.LB = QtWidgets.QPushButton(self.layoutWidget)
self.LB.setObjectName("LB")
self.gridLayout.addWidget(self.LB, 3, 0, 1, 1)
self.BA = QtWidgets.QPushButton(self.layoutWidget)
self.BA.setObjectName("BA")
self.gridLayout.addWidget(self.BA, 3, 1, 1, 1)
self.RB = QtWidgets.QPushButton(self.layoutWidget)
self.RB.setObjectName("RB")
self.gridLayout.addWidget(self.RB, 3, 2, 1, 1)
self.retranslateUi(Dialog)
self.start.clicked.connect(self.startclick)
self.LF.clicked.connect(self.LFclick)
self.forward.clicked.connect(self.forwardclick)
self.RF.clicked.connect(self.RFclick)
self.L.clicked.connect(self.Lclick)
self.ST.clicked.connect(self.STclick)
self.RI.clicked.connect(self.RIclick)
self.LB.clicked.connect(self.LBclick)
self.BA.clicked.connect(self.BAclick)
self.RB.clicked.connect(self.RBclick)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.start.setText(_translate("Dialog", "start"))
self.LF.setText(_translate("Dialog", "LFORWARD"))
self.forward.setText(_translate("Dialog", "FORWARD "))
self.RF.setText(_translate("Dialog", "RFORWARD"))
self.L.setText(_translate("Dialog", "LEFT"))
self.ST.setText(_translate("Dialog", "STOP"))
self.RI.setText(_translate("Dialog", "RIGHT"))
self.LB.setText(_translate("Dialog", "LBACKWARD"))
self.BA.setText(_translate("Dialog", "BACKWARD"))
self.RB.setText(_translate("Dialog", "RBACKWARD"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
note:for this you need:pydroid apppyqt5 libraryboltiot libraryfor api connections install :pip install boltiotin terminal.
Comments
Please log in or sign up to comment.