ক্ল্যাপ সুইচ: হাততালি দিলেই বাতি অন-অফClap Switch with Arduino
হাততালির শব্দে microphone board মুহূর্তের জন্য spike করে। নির্দিষ্ট মান পার হলেই relay উল্টে যায়; এক সেকেন্ডের cooldown থাকায় একই হাততালির প্রতিধ্বনি সাথে সাথে আবার বন্ধ করে দিতে পারে না — বিছানার পাশের বাতির ক্লাসিক প্রজেক্ট।
The microphone board spikes for a moment on a clap. A spike above the limit flips the relay; a one-second cooldown means the echo of the same clap cannot flip it straight back — the classic bedside lamp for people who cannot find the switch.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × Arduino Uno Arduino Uno
- 1 × Sound sensor (microphone) শব্দ সেন্সর (মাইক্রোফোন)
- 1 × Relay module (5V, 1 channel) রিলে মডিউল (5V, ১ চ্যানেল)
- 1 × Light bulb বাল্ব
- 9 × Jumper wires জাম্পার তার
তার লাগানো · Wiring
| Sound sensor (microphone) VCC | → | Arduino Uno 5V |
| Sound sensor (microphone) GND | → | Arduino Uno GND |
| Sound sensor (microphone) AO | → | Arduino Uno A0 |
| Relay module (5V, 1 channel) VCC | → | Arduino Uno 5V |
| Relay module (5V, 1 channel) GND | → | Arduino Uno GND |
| Relay module (5V, 1 channel) IN | → | Arduino Uno D7 |
| Relay module (5V, 1 channel) COM | → | Arduino Uno 5V |
| Relay module (5V, 1 channel) NO | → | Light bulb a |
| Light bulb b | → | Arduino Uno GND.3 |
Code (Arduino C++)
// Clap switch: the microphone board's AO spikes for a moment on a clap. A spike
// above the limit toggles the lamp through a relay; a one-second cooldown keeps
// the echo of the same clap (or a double clap) from flipping it straight back.
const int mic = A0, relayPin = 7;
const int CLAP = 600;
bool lampOn = false;
long lastClap = -1000; // so the very first clap is not swallowed by the cooldown
void setup() {
pinMode(relayPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int raw = analogRead(mic);
if (raw > CLAP && millis() - lastClap > 1000) {
lastClap = millis();
lampOn = !lampOn;
digitalWrite(relayPin, lampOn ? HIGH : LOW);
Serial.println(lampOn ? "Lamp ON (clap)" : "Lamp OFF (clap)");
}
delay(50);
}
আরো project · More projects
- MOSFET দিয়ে DC মোটরের গতি নিয়ন্ত্রণ (PWM)DC motor speed control with a MOSFET (PWM)
- স্মার্ট পার্কিং: কোন স্লট খালি তার হিসাবSmart parking: free-slot counter per floor
- পড়ে যাওয়া ধরার এলার্ম (MPU6050)Elderly fall detection (MPU6050 freefall alarm)
- নয়েজ মিটার: শব্দের মাত্রা ৩টা LED তেNoise meter: classroom loudness on 3 LEDs