Arduino - Sensor ultrasonico única lectura

 
Vista:
sin imagen de perfil

Sensor ultrasonico única lectura

Publicado por Carlos (1 intervención) el 25/03/2022 03:29:29
Hola, he montado con un arduino nano un sensor ultrasonico jsn-sr04t, el cual al cargar el codigo ejemplo que esta en la pagina de arduino donde se utiliza la libreria Newping.h, en pantalla solo me muestra 23 cm y no cambia al alejarlo físicamente, alimentado por cable usb, alguien tiene la solución..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <NewPing.h>
 
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
 
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
 
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
 
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results. }
 
void loop() { delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm"); }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder