lets begin with this video which will give us a basic idea of what we are going to do.
INTRODUCTION.
In everyday life, so many injury due to accidents due to crossing their speed limit on the road so, for this, I made a small project which is related to this and we can also get the average speed of the vehicles by plotting the graph of their speed using the data visualization in the bolt device.
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.
SCHEMATIC DIAGRAM:CONNECTIONS.
- connecting ultra sonic sensor to arduino.
- An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back.
1st Ultra Sonic Sensor - Arduino Uno
1)VCC pin - 5v pin(arduino)
2)GND pin -GND pin(arduino)
3)Trig pin - 2 pin
4)ECHO pin - 3 pin
(use breadboard for connections )
2nd Ultra Sonic Sensor - Arduino Uno 1)VCC pin - 5v pin(bolt wifi module)
2)GND pin -GND pin(bolt wifi module)
3)Trig pin - 12 pin
4)ECHO pin - 11 pin
(use breadboard for connections )
- connections arduino the bolt WiFi module.
· 1)TX pin - 8 pin
2) RX pin - 9 pin
- Bolt Starting Serial communication with Arduino UNO using the link int web browser : "http://cloud.boltiot.com/remote/YourapiKey/serialBegin?baud=9600&deviceName=BOLTxxxxxx"
YourapiKey ---- give your device API key, You can get it from "Developer Console"
deviceName = give your device name,
You can get it from "BOLTIOT app" in Google store or app store keep baud rate to 9600.(see step() for more information)
(note:here the power supply will be done by the bolt usb and arduino usb cables, connected to your laptop)
step 2:(setup the arduino)- Programming Arduino UNO: This 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.
(note:remove tx and rx pin while uploading code to arduino.)
- · upload the arduino code in the arduino using arduino ide.
//Ping sensors
#define trigPin1 2 //defines ping sensor1 trigger to pinslot 2
#define echoPin1 3 //defines ping sensor1 echo to pinslot 3
#define trigPin2 12 //defines ping sensor2 trigger to pinslot 4
#define echoPin2 11 //defines ping sensor2 echo to pinslot 5
unsigned long time1,time2;
//duration of the traveldistance from ping sensor to object and back to ping sensor
unsigned long duration1=0; //ping sensor1 duration
unsigned long duration2=0; //ping sensor2 duration
//defining attributes for distance
int distance1; //distance, to calculate distance to object from ping sensor1
int distance2; //distance, to calculate distance to object from ping sensor2
float fps, elap,mph;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8,9);
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(9600);
pinMode(4,OUTPUT);
pinMode(trigPin1, OUTPUT); //ping sensor trigger OUTPUT
pinMode(echoPin1, INPUT); //ping sensor echo INPUT
pinMode(trigPin2, OUTPUT); //ping sensor2 trigger OUTPUT
pinMode(echoPin2, INPUT); //ping sensor2 echo INPUT
Serial.setTimeout(100);
}
//method to measure distance of ping sensor1
void measureDistance1() {
pinMode(trigPin1, OUTPUT); //ping sensor1 trigger OUTPUT
pinMode(echoPin1, INPUT); //ping sensor1 echo INPUT
digitalWrite(trigPin1, HIGH); //ping sensor1 sends ultrasonic wave
delayMicroseconds(10); //waits for 1 second (1000 microseconds)
digitalWrite(trigPin1, LOW); //ping sensor1 trigger is LOW
duration1 = pulseIn(echoPin1, HIGH); //ping sensor1 retrieves the sound
}
void measureDistance2() {
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
}
//method to calculate distance based on information recieved with measure distance -method for ping sensor1
int calculateDistance1() {
measureDistance1(); //calls for measureDistance() method
duration1=duration1/2; //divides duration of the sound from ping sensor1 to object and back to the sensor and divides it by 2 (sound travels 2 times)
distance1 = int(duration1/29); //duration is then divided by 29 (sound travels 29 microseconds per centimeter)
//Serial.print("Ping distance (CM) - "); //prints "Ping distance (CM) - ") to serial monitor
//Serial.println(distance1); //prints the distance number to serial monitor
delay(50); //waits for 0,5 seconds (500 microseconds)
}
//method to calculate distance based on information recieved with measure distance -method for ping sensor2
int calculateDistance2() {
measureDistance2();
duration2=duration2/2;
distance2 = int(duration2/29);
//Serial.print("Ping2 distance (CM) - ");
//Serial.println(distance2);
delay(50);
}
String data;
uint8_t dataRead = 0;
void loop() {
// put your main code here, to run repeatedly:
if (mySerial.available() > 0) {
delay(50);
String readData = "";
Serial.print("cmd from bolt:");
while (mySerial.available() > 0 ) {
readData = readData + (char)mySerial.read();
}
Serial.println(readData);
if (readData.indexOf("RD") != -1) {
String data = sensor_data_to_push();
mySerial.print(data);
Serial.print("data sent to bolt:");
Serial.print(data);
}
}
digitalWrite(4,HIGH);
Serial.println ("Waiting for projectile");
calculateDistance1(); //calls for calculateDistance1() -method
calculateDistance2(); //calls for calculateDistance2() -method
while (distance1 >15)
{
calculateDistance1();
}
while (distance1 <= 15)
{
time1 = micros();
calculateDistance1();
}
while (distance2 > 15)
{
calculateDistance2();
}
while (distance2 <=15)
{
time2 = micros();
calculateDistance2();
}
elap = time2 - time1;
fps = 666666/elap;
mph= 1.097*fps;
//Serial.print(elap);
Serial.println("Foot per Sec :");
Serial.print(fps);
if (mph >= 3 )
{
digitalWrite(4,LOW);
delay (5159);
}
}
String sensor_data_to_push() {
String data;
float temp = fps;
data =String(temp);
Serial.print("data is:");
Serial.println(data);
return data;
loop();
}
· open the serial monitor to see the speed of the object.
step3:(skip this step if you have already connected bolt to your phone)connecting the bolt wifi module to bolt app and to cloud.
1) Downloading Bolt App
Download the ‘Bolt IoT’ App for Android or iOS.
2) Creating an account
You will need to create an account on the Bolt Cloud to control the Bolt device. Did I mention that creating an account on the Bolt Cloud is FREE?
Open the Bolt App and click on 'REGISTER' to create a new account.
Fill all the required details and agree to the terms and conditions. Finally, click on 'CREATE A NEW ACCOUNT' to create your free account.
You will now receive an email on the email ID that you had given to verify your account. This is to verify that you are an actual human and not a robot.
Follow the instructions in the email to activate your Bolt Cloud account. Now, pull down on the screen using your fingers to refresh the mobile App screen which looks something like this below,
Congratulations, you have activated your account. You will then be greeted with a screen that says that you don't have any Bolts Modules linked to your account.
3) Adding Bolt to your account
Now, click on the 'ADD DEVICE' button to setup your Bolt device with your WiFi network.
Power ON the Bolt device by inserting the Micro USB cable into the USB port provided on the Bolt and connecting the other end of the cable to the Android charger or to your laptop.
NOTE: There are no ON/OFF buttons on Bolt. Once you power it ON, it is good to go.
You can also view this small video to know how you can power up your Bolt device.
Once you have powered ON the Bolt device, blue LED on the Bolt will begin to blink slowly and the green LED will be OFF.
When the blue LED blinks slowly, it means that the Bolt is now transmitting its own WiFi hotspot network and is ready to be setup via the Bolt IoT App on your phone.
Click on the '>' symbol on the app to progress further.
For Android Only: Before proceeding further, kindly switch OFF your mobile data and switch ON the location service in your mobile if not already and click on the "READY" button. This is required only in the Android App due to APIs by Google. We do not collect or store any of your location data.
If the Bolt has been detected by the App, it will show a screen similar to the one below. The blue LED on the Bolt will now blink fast. This means that it is under the setup process. To proceed, click on 'CONTINUE'.
The password for the WiFi hotspot transmitted by the Bolt WiFi Module is: bolt1234 While setting up with the Android mobile app, your mobile phone will automatically connect to the hotspot when you click next. On an iOS, you will have to connect to the Hotspot by going to your Setting -> WIFi.
Now, we will need to tell the Bolt which WiFi network it has to connect to.
NOTE: The Bolt WiFi module cannot detect 5 GHz based WiFi networks and will not be able to connect to it.
Select the WiFi network to which Bolt has to be connected. You can click on the WiFi name to choose the WiFi network to connect to.
Note: For the iOS App, you will have to manually enter the SSID or the WiFi Name of the device you want to connect to.
Enter the password of the WiFi network you had chosen in the previous screen.
The App will now send the WiFi credentials to the Bolt WiFi Module.
Now, click on 'DONE' and in the next screen, select your Country and click on 'SAVE' to complete the final step of the setup.
If everything has gone according to plan, the Bolt device will now restart automatically. The blue and green LED on the Bolt device will now be glowing steadily.
If the Bolt was able to connect to the WiFi network and is connected to the cloud, a green dot will appear beside the Bolt's device ID as shown below.
Debugging:
· If the Bolt is unable to connect to the WiFi network, the green LED will be OFF and the Blue LED will be blinking slowly. This generally happens if you have entered the wrong WiFi credentials (SSID or password) at the time of setup. Please try the setup process once again with the correct WiFi credentials.
· Check if your WiFi Router works at 2.4GHz. Bolt does not support 5GHz at the moment.
4) Accessing the Bolt Cloud to Build IoT Projects
Visit Bolt Cloud (cloud.boltiot.com) and login into your registered account using the same email ID and password that you have used on the Bolt IoT mobile App.
You will see your Bolt device with status as 'ONLINE' on your account on the dashboard.
Congratulations, you have managed to setup the Bolt and link it to your account in less than 10 minutes. What was your time? Let us know in the comments section.
step 4: setting up the bolt product in your pc1)To create a new product, click on the Products tab on your Cloud Dashboard
note:If you already have created a product and want to create more, you can click on the "Add Product" button next to your product list.
2)now follow the step:
a)give the product name.
b)click on input device.
c)click on UART. click done.
3)now for hardware confurigation.
a) choose 1 in field position
b) give the variable name as the 'temp'.
c)set the baud rate 9600.save hardware confurigation.
4)now the software confurigation.
a)give the code name.
b)select.js in extension. save the software confurigation.
use this code in the code section:
setChartType('lineGraph');
setAxisName('time','Speed in fps');
plotChart('time_stamp','temp');
5)link the product with bolt wifi module and upload the configurations.
step 5: to see the graph- · go to the bolt console or you can see it int bolt app
·
- · in pc, in the bolt console click on confurigation to see the graphical visualisation.
connecting bolt to the digital ocean server.
- to create a account click: https://m.do.co/c/c0d7bb6489f4
- download putty use the link of digital ocean and paste the below mentioned codes.
- to get the message service create a account in twilio:https://www.twilio.com/
a)setup the serial communication use this api.
"http://cloud.boltiot.com/remote/XXXXXXXXXXX(YOUR API KEY)/serialBegin?baud=9600&deviceName=BOLTXXXXXX(YOUR BOLT ID)"-api text
- · you can get your api key and bolt id in the bolt console.
- · type the api text in the google browser, to begin the serial communication between arduino and bolt wifi module.
b)type the python code in the putty with the help of ip address you will get on digital ocean.
- · create a python program name credentials.py below is the code.
account_sid="twilio sid"
auth_token="twilio auth token"
my_mobile="+91your phone number"
my_cell="+twilio number"
- · create another python program name server.py below is the code.
from twilio.rest import Client
from credentials import account_sid, auth_token, my_cell, my_mobile
import requests,json,time
client = Client(account_sid, auth_token)
def send_msg(sensor_data):
my_msg = "speed is more then 3fps"
message = client.messages.create(to=my_mobile, from_=my_cell, body=my_msg)
while True:
r = requests.get('http://cloud.boltiot.com/remote/your api key/analogRead?pin=A0&deviceName=BOLTXXXXXX')
data = json.loads(r.text)
print (data['value'])
try:
sensor_value = int(data['value'])
print (sensor_value)
if sensor_value > 119:
send_msg(str(sensor_value))
except Exception as e:
print ("Error")
print (e)
time.sleep(5)
- to make such more cool projects follow me on hackster.
- subscribe my you tube channel
- for any query: chpritampatro123@gmail.com(mail me).
Comments