Clap" Prekidač Sa Arduino-M
Clap" Prekidač Sa Arduino-M
Šema:
Potrebni elementi:
Mikrofon
Kondenzator 100nF
Otpornik 10k
Otpornik 100k
Otpornik od 220 Ω do 470 Ω
LED dioda
Arduino Uno
Eksperimentalna pličica i žice za spajanje
Kod za arduino:
//---------------------------------------------------------------------
// Program: clap switch
//
// Description: Switches on an LED when hands are clapped.
// Electret microphone connected to A2, LED and series
// resistor connected to digital pin 2
//
// Date: 6 April 2016 Author: W.A. Smith
// http://startingelectronics.org
//---------------------------------------------------------------------
void setup() {
Serial.begin(9600); // using serial port to check analog
value
pinMode(2, OUTPUT); // LED on digital pin 2
}
void loop() {
int analog_val; // analog value read from A2
static bool led_state = false; // current state of LED
analog_val = analogRead(A2);