Light sensitive bag

This is a light sensitive bag that beeps when the amount of light is higher than the declared threshold. If the light is closer to the sensor it displays a faster sound(beeps). If the light source is far from the sensor it displays a slower sequence of beeps.
This may be useful if you want to carry light sensitive stuff in your bag.

Basically I used a simple circuit with a Piezzo working as a beeper and a light sensor to measure the amount of light.

 

 

CODE

//Nuno Laginha
//MTI Fall 2008int switchPin = 2;          //switch connected on analog pin 2
int knockPin = 11;          //switch connected on analog pin 11
int val = 0;void setup()                    
{
    pinMode(knockPin, OUTPUT);
    Serial.begin(9600);       //set speed
}

void loop()                 //run over and over again
{
  
    
  val = analogRead(switchPin);//reads voltage value
  
  val = val / 4;
  
  if(val<80){              //if current value higher than 80 (threshold)

  analogWrite(knockPin, 0); //don’t beep
  }else{
  analogWrite(knockPin, val); //beep accordingly with the voltage
  delay(val); //set delay equal to actual voltage
  analogWrite(knockPin, 0);
  delay(val);
  analogWrite(knockPin, val);
  delay(val);
  analogWrite(knockPin, 0);
  delay(val);
  analogWrite(knockPin, val);
  delay(val);
  analogWrite(knockPin, 0);
  delay(val);
  }
    
  Serial.println(val);            //prints voltage value

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s