我的Arduino项目
项目介绍
When your hand approaches the ultrasonic sensor, display the distance between your hand and the ultrasonic sensor
代码介绍
const int soundSensorPin = A0;
const int ledPin = 9;
const int soundThreshold = 550;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
int soundLevel = analogRead(soundSensorPin);
if (soundLevel > soundThreshold) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
电路图展示
成品展示
Your browser does not support the video tag.
Back