I need some help. For some reason I can't wrap my head around my problem. I want to be able to control the ultrasonic sensor with a potentiometer. The result would be I can increase and decrease the distance that the sensor needs to be triggered. for some reason I can't find an example.I was thinking that I can treat the pot like a photoresistor. can anyone help me out with this problem? By the way, when the ultrasonic sensor is triggered I want a buzzer to go off.
So you want to compare the distance detected by an ultrasonic range detector with a distance value you set with a potentiometer?
void loop() {
int range = getRangeFromSensor();
int setpoint = map(analogRead(potPin), 0, 1023, minDistance, maxDistance);
digitalWrite(buzzerPin, range < setpoint);
}
Yes. I think so. What want to do is change the range, like you said, with the potentiometer. The script you gave me might do the trick. Let me try it out and see if it works. Thanks.
sir,
i tried your code but it doesn't seem to work. My led which I am using remains off. Itry turning the potentiometer hoping something will happen but everything remains blank.
I would be really thankful to you if you could provide me the whole code. I will be very grateful to you for that.
Thanks & Regards,
I think it would be a good idea if you provided us with the code you are running which you say doesn't work. Also details of what sensor(s), potentiometer, LED and Arduino you are using and exactly how everything is wired.
No-one can produce code without knowing what the code is supposed to work with and what it is supposed to do.
Steve