I've been working on this for at least 5 hours now, trying to modify codes but nothing is working. Im trying to get the SRF05 to read distance, and when that distance is 20cm, turn on an LED. If not, leave the LED off. I know it's simple, but Im really lost. The closest I've gotten was to get the LED to flash off for a fraction of a second everytime the SRF05 sent a signal.
Im using the single pin mode, I know i have soldered it right, the basic code is working I just cant modify it. Heres the basic:
Arduino example for SRF05
Using a single pin for both trigger and echo.
int duration; // Stores duratiuon of pulse in
int distance; // Stores distance
int srfPin = 2; // Pin for SRF05
digitalWrite(srfPin, LOW); // Make sure pin is low before sending a short high to trigger ranging
digitalWrite(srfPin, HIGH); // Send a short 10 microsecond high burst on pin to start ranging
digitalWrite(srfPin, LOW); // Send pin low again before waiting for pulse back in
duration = pulseIn(srfPin, HIGH); // Reads echo pulse in from SRF05 in micro seconds
distance = duration/58; // Dividing this by 58 gives us a distance in cm
delay(50); // Wait before looping to do it again