It will not read more than 40 CM yet the same code on an Arduino Uno will read up to 4 meters.
Why is that?
Code: Select all
#define ECHOPIN 17
#define TRIGPIN 16
void setup() {
Serial.begin(115200);
pinMode(ECHOPIN,INPUT_PULLUP);
pinMode(TRIGPIN, OUTPUT);
digitalWrite(ECHOPIN, HIGH);
}
void loop() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(15);
digitalWrite(TRIGPIN, LOW);
int distance = pulseIn(ECHOPIN, HIGH, 26000);
distance=distance/58;
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}