To prevent collision by sensing the distance by ultrasonic sensor to send the data to the cloud and then it shows the message on ubuntu server of how much distance is there and if there is a chance of collision.
Hardware SetupStep 1:All the components required for the project are mentioned below and are easily available in market at a reasonable price.
Step 2:Connect the buzzer to the digital pin 3 of the bolt Iot module
Step 3:Connect the Vcc pin to 5v and the GND pin to GND of the bolt modult.
Step 4:Connect the trigger pin to 2 and echo pin to digital pin 1.
Step 5:complete the connection and connect the bolt iot module to a power source using usb cable and wait for it to connect to the cloud.
write the code and compile and upload it and wait for the output.
Software ProgrammingStep 1:create a new file by running the following command in the ubuntu terminal.
sudo nano collision_prevention.py Step 2:Now import the libraries and get your api key and device id from the bolt cloud platform and replace them in the code.
from boltiot import Bolt
api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
device_id = "BOLTXXXXX"
mybolt = Bolt(api_key, device_id)
thershold = 10Step 3:now write the function that will return the distance.
def get_distance():
response = mybolt.digitalWrite('2', 'HIGH')
time.sleep(2/1000000.0)
response = mybolt.digitalWrite('2', 'LOW')
data = mybolt.digitalWrite('1', 'HIGH')
duration = int(data)
distance= (duration*0.034)/2;
return distanceStep 4:Now we write the code that will run in an infinite loop and call the get_distance function.
while True:
sensor_value = get_distance()
print("Sensor value is = ",sensor_value)
if sensor_value<threshold:
print("too close please maintain distance to avoid collision", sensor_value)
else:
print("you are safe")Step 5:The complete code
from boltiot import Bolt
api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
device_id = "BOLTXXXXX"
mybolt = Bolt(api_key, device_id)
thershold = 10
def get_distance():
response = mybolt.digitalWrite('2', 'HIGH')
time.sleep(2/1000000.0)
response = mybolt.digitalWrite('2', 'LOW')
data = mybolt.digitalWrite('1', 'HIGH')
duration = int(data)
distance= (duration*0.034)/2;
return distance
while True:
sensor_value = get_distance()
print("Sensor value is = ",sensor_value)
if sensor_value<threshold:
print("too close please maintain distance to avoid collision", sensor_value)
else:
print("you are safe")NOTE : To exit the infinite loop click control + c.









Comments