1. Arduino Uno
2. Sparkfun Sound Detector
3. 5V Relay
4. NPN Transistor
5. 1K Res
6. (2) Candle Incandescent Bulbs
7. Cuhlness
- // Flashing Light Prize (3) Arduino Scat
- // pkvi
- // Sound Detector Pins
- #define PIN_GATE_IN 2
- #define IRQ_GATE_IN 0
- #define PIN_LED_OUT 13
- #define PIN_ANALOG_IN A0
- // Relay Pin
- int relay = 7;
- // Sound Value
- int val;
- // SparkFun Sound Detector Interrupt
- void soundISR()
- {
- int pin_val;
- pin_val = digitalRead(PIN_GATE_IN);
- digitalWrite(PIN_LED_OUT, pin_val);
- }
- void setup()
- {
- // Testing
- Serial.begin(9600);
- // Sound Detector Pin Assignment
- pinMode(PIN_LED_OUT, OUTPUT);
- pinMode(PIN_GATE_IN, INPUT);
- // Relay Pin Assignment
- pinMode(relay, OUTPUT);
- // Sound Decector Interrupt
- attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);
- }
- void loop()
- {
- // Read Sound
- val = analogRead(PIN_ANALOG_IN);
- // Testing
- Serial.println(val);
- // If Sound Exceeds X
- if (val > 55) {
- digitalWrite(relay, HIGH);
- delay(600);
- digitalWrite(relay, LOW);
- delay(200);
- } else {
- digitalWrite(relay, LOW);
- }
- delay(10);
- }