Arduino/elegoo-kit-lessons/Lesson 10 Ultrasonic Sensor Module/SR04_Example/SR04_Example.ino
2022-02-20 16:18:02 -05:00

22 lines
305 B
C++

//www.elegoo.com
//2016.12.08
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
a=sr04.Distance();
if(a>0){
Serial.print(a);
Serial.println("cm");
}
delay(10);
}