sishea / Sumo

Code for my Pololu Zumo sumo robots
2 stars 2 forks source link

Parallax sensor #1

Open T1A5MA opened 6 years ago

T1A5MA commented 6 years ago

Hi!

We are trying to use this code, but with a Parallax proximity sensor. We are not getting the expected result, any ideas why?

sishea commented 6 years ago

Hi - on a very cursory look at the Parallax sensor, it looks like it provides a Pulse Width proportional to the distance, rather than the analog voltage in my example.

<158> distance = analogRead(DISTANCE_SENSOR); will need to be replaced with something like this (documentation here - https://www.arduino.cc/en/Reference.PulseIn): <158> distance = pulseIn(DISTANCE_SENSOR); and the parameters below modified to suit: <20> #define DETECTED_RANGE 100 // an object within this range is a target <21> #define CLOSE_RANGE 300 // object is in range to attack