Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long ping()
- {
- pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
- digitalWrite(ultraSoundSignal, LOW); // Send low pulse
- delayMicroseconds(2); // Wait for 2 microseconds
- digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
- delayMicroseconds(5); // Wait for 5 microseconds
- digitalWrite(ultraSoundSignal, LOW); // Holdoff
- pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
- digitalWrite(ultraSoundSignal, HIGH); // Turn on pullup resistor
- // please note that pulseIn has a 1sec timeout, which may
- // not be desirable. Depending on your sensor specs, you
- // can likely bound the time like this -- marcmerlin
- // echo = pulseIn(ultraSoundSignal, HIGH, 38000)
- echo = pulseIn(ultraSoundSignal, HIGH); //Listen for echo
- ultrasoundValue = (echo / 58.138) ; //convert to CM then to centi-o-meters
- return ultrasoundValue;
- }
Add Comment
Please, Sign In to add comment