Arduino deneyi 09
Clap-Triggered Light
Beginner · 45 min · Event detection
Detect a clap or other sharp sound and light an LED briefly.
Malzemeler
- Arduino Uno
- Digital microphone/sound module
- LED
- 220 Ω resistor
- Breadboard and jumper wires
Bağlantı
- Connect module VCC to 5V, GND to GND and OUT to pin 2.
- Connect pin 13 through 220 Ω to the LED anode and its cathode to GND.
Kod
const int micPin = 2, ledPin = 13;
unsigned long lastTrigger = 0;
void setup() {
pinMode(micPin, INPUT); pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(micPin) == HIGH && millis() - lastTrigger > 300) {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
lastTrigger = millis();
}
}
Ne olmalı?
A sharp sound produces one controlled flash instead of repeated triggers.
Meydan okuma
Count claps and switch the LED state after two detections.
Güvenlik ve sorun giderme
- Bağlantıyı değiştirmeden önce gücü kes.
- Her LED ile direnç kullan.
- Kart ve port seçimini Arduino IDE'de kontrol et.
- Her kablonun koddaki pin numarasıyla eşleştiğini doğrula.
Not: Ders metinleri İngilizcedir. Orijinal Türkçe çalışma kâğıdı PDF olarak indirilebilir.
