Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Chiraz Boudhrioua
Published

LED Light Using Sound and Light Sensors

We are going to hook up the sound sensor and the light sensor to an array of LED lights which will beat with music.

AdvancedShowcase (no instructions)1 hour2,619
LED Light Using Sound and Light Sensors

Things used in this project

Story

Read more

Custom parts and enclosures

project

Schematics

shematics

Code

led light using sound & light sensors

Arduino
void setup(){
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
}

String soundlevel(int a){
 String s;
  if(a<200) {
   s= "LOW";
  }
  if(a<350 && a>200) {
   s= "MEDUIM";
  } 
    if(a>350 && a<500) {
   s= "HIGH";
  }
   if(a>500) {
   s= "VERY_HIGH";
  }
  return s;
}
String lightlevel(int a){
 String s;
  if(a<70) {
   s= "Low";
  } 
   if(a>70 && a<200) {
   s= "Meduim";
  }
   if(a>200) {
   s= "High";
  }
  return s;
}
void outsound(String a){
  if(a=="LOW"){
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
  }
  if(a=="MEDUIM"){
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
  }  
 if(a=="HIGH"){
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
  } 
   if(a=="VERY_HIGH"){
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
  } 
}
void outlight(String a){
  if(a=="Low"){
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
  }
  if(a=="Meduim"){
    digitalWrite(7,HIGH);
    digitalWrite(8,LOW);
  }  
 if(a=="High"){
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH); 
  } 
}
void loop(){
  String r;
  int a = analogRead(A1);
  int b = analogRead(A2);

  a=(a*1.2);//sound amplification
  outsound(soundlevel(a));
  outlight(lightlevel(b));
}

Credits

Chiraz Boudhrioua
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.