raj412
February 13, 2017, 7:20am
#1
ultra sonic sensor always showing 0.
can anyone help me to correct this
#define trigPin 13
#define echoPin 12
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(11, OUTPUT);
}
void loop()
{
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.print("distance is ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}
davidrh
February 13, 2017, 7:26am
#2
Post a drawing or photo of how you have wired your sensor up. Is it an SR04 type sensor?
raj412
February 13, 2017, 7:29am
#3
davidrh:
Post a drawing or photo of how you have wired your sensor up. Is it an SR04 type sensor?
sro4
trigger pin to 13
echo pin to 12
vcc to 5v (3.3v also showing 0)
raj412:
sro4
trigger pin to 13
echo pin to 12
vcc to 5v (3.3v also showing 0)
Welcome to the forum.
What about the gnd terminal of the sensor, and you need to post a circuit diagram, not a description.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you tell us your electronics, programming, Arduino, hardware experience?
Thanks.. Tom...
raj412
February 13, 2017, 7:52am
#5
i followed the same connections as shown in below attached figure