Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <NewPing.h>
- #define TRIGGER_PIN 5
- #define ECHO_PIN 6
- #define MAX_DISTANCE 200
- NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Lendo... ");
- }
- void loop()
- {
- delay(5000); // Espera 5 seg entre os pings
- unsigned int u = sonar.ping(); // Envia o ping.
- Serial.print("Ping: ");
- Serial.print(sonar.convert_cm(u)); //Converte (se =0 esta fora do alcance ou nao recebeu o echo)
- Serial.println("cm");
- Serial.println("u " + String(u)); // Qual valres imprime aqui?
- if (u > 20)
- {
- Serial.println("sim");
- } else
- {
- Serial.println("nao");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement