I am planning to build an IoT project with the help of an ultrasonic sensor but I am not able to identify how to connect the ultrasonic sensor with the module. Please help me with the problem.
Hi, Connecting an ultrasonic sensor is really easy. I have attached the diagram below which might help you with the connections. You can connect the ultrasonic sensor to any of the digital pins(not compulsory to connect as shown in the figure) of the bolt Wi-Fi module. In some cases, you may require a voltage divider circuit between the echo and the digital pin of the module.
How should I apply the trigger and handle the echo?
How do I code this using the JS and use the serial monitor of BOLT IoT module??
Hi @harshkakasaniya
can you help me in handling echo i.e how to get duration from echo in pyhton. please reply asap.
As mentioned in the previous thread, Please check this project https://www.hackster.io/bolt-iot-developers-u-p-region/trash-talker-using-bolt-iot-f2af5e
Do let me know in case you need further assistance.
You could use a custom python script but Bolt is only a wifi microcontroller that works on APIs. To perform PulseIn functions, it is necessary for the program to be present in the mC to read the difference for the distance.
You could use a custom pulseIn function -
unsigned long rdPulseIn(int pin, int value, int timeout) { // the following comments assume that we're passing HIGH as value. timeout is in milliseconds
unsigned long now = micros();
while(pinReadFast(pin) == value) { // wait if pin is already HIGH when the function is called, but timeout if it never goes LOW
if (micros() - now > (timeout*1000)) {
return 0;
}
}
now = micros(); // could delete this line if you want only one timeout period from the start until the actual pulse width timing starts
while (pinReadFast(pin) != value) { // pin is LOW, wait for it to go HIGH befor we start timing, but timeout if it never goes HIGH within the timeout period
if (micros() - now > (timeout*1000)) {
return 0;
}
}
now = micros();
while (pinReadFast(pin) == value) { // start timing the HIGH pulse width, but time out if over timeout milliseconds
if (micros() - now > (timeout*1000)) {
return 0;
}
}
return micros() - now;
}
************* Cal it in the program like this *******************
distance = rdPulseIn(echoPin, HIGH, 37)/5.82; // distance in mm
The above program won’t necessarily work. It’s only a script I converted to micropython for my Pi project with HC-SR04.
To avoid these trouble. Simply use an analog pin viable IR sensor. It works with A0 pin of Bolt Module.