I am trying to build a very simple project. I want to use Ultrasonic sensor to measure distance. To do so, I connected the Ultrasonic sensor with Bolt Wifi Module. I am facing issues so your help will be appreciated.
A python code that should trigger the sensor to measure the distance and return the value. I will use this value to calculate the distance accurately(I am assuming sensor gives values and not distance). Once calculated, I will print the distance on screen (or python console).
Next, I want to plot the distance on the graph but the value returned by this sensor is not the distance so need a way to convert this value to distance before plotting.
Presently, I am using Bolt Cloud, but I am open to other Cloud platforms for solution too.
My Attempted Solution:
I tried coding this, here is my python code:
import requests, time, math, json
from boltiot import Bolt
import conf2 as conf #my Configuration File
data =  #Empty list for storing sensor values…
mybolt = Bolt(conf.bolt_api_key, conf.device_id) #My Bolt
#Function:Get Sensor Value
response = mybolt.digitalRead(2) data = json.loads(response) if data["success"]!=1: print("Request Failed") print("Response:",data) return -999 duration = int(data["value"]) distance= duration*0.034/2; return distance except Exception as e: print("Something went wrong") print(e) return -999
sensor_value = get_sv()
print("Sensor value is = ",sensor_value)
if sensor_value == -999: print("Request unsuccessful.Skipping...") time.sleep(5) continue if(sensor_value <= conf.threshold): print("Alert: Accident Occured") message = "Crashed! " + "The current sensor value is: " + str(sensor_value) data.append(sensor_value) time.sleep(5)
my JS Code on Bolt Cloud is:
setAxisName(‘Time Stamp’, ‘Distance’);
Please feel free to clear any ambiguity. You help is greatly appreciated, thanks in advance :slight_smile