KAIO VINICIUS DE LIMA VIANA
Published © MIT

Sound lamp switch with Arduino

Project to detect presence and activate lamps in simple ways using an audio sensor connected to an Arduino

BeginnerShowcase (no instructions)1 hour125
Sound lamp switch with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED Replacement Lamp, Candelabra Screw
LED Replacement Lamp, Candelabra Screw
×1
lamp socket
×1
Relay (generic)
×1
SparkFun Audio-Sound Breakout - WTV020SD
SparkFun Audio-Sound Breakout - WTV020SD
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

TinkerCad - Digital Simulator

Consider it just a diagram to visualize the pins.
The audio sensor in the case is represented by a potentiometer.

https://www.tinkercad.com/things/aobyua6RNed-brilliant-wluff-wolt/editel?returnTo=%2Fdashboard

Code

Arduino Sound Sensor Code

C/C++
#define sensor 2
#define rele 3

int palmas = 0;
boolean temPalmas = true;
boolean contaPalma = true;
unsigned long tempo = 0;

void setup() {
  pinMode(sensor, INPUT);
  pinMode(rele, OUTPUT);
  
  digitalWrite(rele, HIGH);
}

void loop() {
 temPalmas = digitalRead(sensor);
 
 if(!temPalmas){
  if(contaPalma){
    palmas++;
    tempo = millis();
    contaPalma = false;
  }
  else{
    if(millis() - tempo > 200){
      contaPalma = true;
    }
  }
 }

 if(millis() - tempo > 400){
  switch(palmas){
    case 1:
    digitalWrite(rele, HIGH);
    break;

    case 2:
    digitalWrite(rele, LOW);
    break;
  }
  palmas = 0;
 }
}

Credits

KAIO VINICIUS DE LIMA VIANA

KAIO VINICIUS DE LIMA VIANA

1 project • 0 followers
Thanks to Rodrigo Santos.

Comments