Spring Sale: 5% OFF Over $89, Code: Elephant5; 10% OFF Over $149, Code:Elephant10



Arduino Project: Sound-control Light

Posted by Fiona Su on

thumb 

Introduction:
In this experiment, we use sound passing through MIC to control the on and off of the light.
Hardware Required:

  • Arduino Board *1
  • USB Cable *1
  • Potentiometer *1
  • Highly Sensitive MIC *1
  • Red M5 LED *1
  • 220Ω Resistor *2
  • Breadboard *1
  • Breadboard Jumper Wire*5

Connection for REV4:

thumb

Connection for Arduino Mega 2560 R3:

thumb 

The Connection Diagram for this experiment is relatively simple. It has no processing of the signal from the MIC, so signal is weak and insensitive. Instead of sound signal, we blow air to the MIC.
Sample Code:

int LEDpin = 7;                 // set pin for LED 
void setup() {
  Serial.begin(9600);
  pinMode(LEDpin,OUTPUT);
}
void loop() {
  
  int Soundvalue = analogRead(A0);  // read the input analog value
  Serial.println(Soundvalue);
  if(Soundvalue>700)
  {
   digitalWrite(LEDpin,HIGH);      // when the analog value is bigger than the set value, turn on the LED
   for(int i=0;i<5;i++){
   delay(1000);                    // wait for 5s
   }
  }
  else{
   digitalWrite(LEDpin,LOW);      // turn off the LED 
    }
}

Program description:
By rotating the potentiometer, the analog value of A0 changes; After adjusting the potentiometer, blow air into the MIC, and observe data in the serial monitor.
For example, the displayed data is less than 300 before blowing; after blowing, data is more than 700. Setup code if (Soundvalue > 700), control the on and off of the light; the on time of the light is controlled by the code for(int i=0;i<5;i++) { delay(1000); }, so the light is on 5*1s.
Result:
Connect the wire according to the connection diagram. 

Rotate the potentiometer to adjust the LED to a state where it’s between on and off.

thumb 

When the light is out, data as shown in serial port monitor as pic 1; when clapping hands, light is on for 5 seconds and data as shown in pic 2.

thumb

Pic 1

thumb

Pic 2

0 comments

Leave a comment

Please note, comments must be approved before they are published