Hi everybody,
yesterday I got my ultrasonic sensor
HC-SR04 (from eBay,
see here). But I couldn't get it work till now. There is a library from ITead Studios for this 4 pin model (there you find
the datasheet, too). Because that one didn't deliver anything else than zeros, I wrote my own sketch for debugging:
int trigger = 5;
int echo = 6;
unsigned int duration;
void setup() {
Serial.begin(9600);
pinMode(trigger, OUTPUT);
digitalWrite(trigger, LOW);
pinMode(echo, INPUT);
}
void loop() {
Serial.print("Trigger: ");
Serial.print(digitalRead(trigger));
Serial.print(" - ");
digitalWrite(trigger, HIGH);
Serial.print(digitalRead(trigger));
Serial.print(" - ");
delayMicroseconds(10);
digitalWrite(trigger, LOW);
delayMicroseconds(5);
Serial.println(digitalRead(trigger));
duration = pulseIn(echo, HIGH);
Serial.print("Echo: ");
Serial.println(duration);
}
It still doesn't work. The board is a
Duemilanove, the triggerPin wired to digital pin 5, the echoPin to 6. Vcc comes from the board, but the board is connected to a 5V power supply (e.g. my LAN breakout board works fine with this solution). I measured 5V stable at the sensor, but there seems to be no current.
Is there something I might have missed? Or is it a malfunction of the sensor?
Thx for your answers and a merry christmas!