Secret Diary Alarm Using Piezo Speakers

Posted by rami

rami's picture

Description:

A basic & primitive security system for secret diaries. Using a photocell embedded in a diary to detect if and when a diary is opened, and a piezo speaker as an alarm.

 

Material:

bread board

arduino

photocell

piezo speaker

wires

 

Code:

 

int potPin = 0;    // select the input pin for the potentiometer
int speakerPin = 7;
 
int val = 0;
 
void setup() {
  pinMode(speakerPin, OUTPUT); 
  Serial.begin(9600);
  Serial.println("ready");
}
 
void loop() {
  digitalWrite(speakerPin, LOW);
  
  val = analogRead(potPin);    // read value from the sensor
  //val = val*200;                 // process the value a little
  //val = val/2;                 // process the value a little
   
  for( int i=0; i<.0001; i++ ) {  // play it for 50 cycles
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(val);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(val);
  }
}
 
5
Your rating: None Average: 5 (1 vote)