产品简介
SR04超声波测距模块可提供2cm-400cm的距离感测,测距精度可达3mm。
样例
#include "SR04.h"
#define TRIG_PIN 2
#define ECHO_PIN 3
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
void setup() {
Serial.begin(9600);
Serial.println("Example written by Coloz From Arduino.CN");
delay(1000);}
void loop() {
a=sr04.Distance();
Serial.print(a);
Serial.println("cm");
delay(1000);}