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

Very simple alarm using a photoresistor

In this project we are going to make a very simple alarm that uses minimal components.

BeginnerFull instructions provided716
Very simple alarm using a photoresistor

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
Arduino Mega 2560
Arduino Mega 2560
I use an Arduino Mega 2560 but you can use any other Arduino board as well.
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Buzzer
Buzzer
×1

Story

Read more

Schematics

Schematics

Use a 10k resistor.

Code

Code

Arduino
int buzzer = 11;


void setup(){
 pinMode(buzzer,OUTPUT);
}



void alarm(){
 int i;
 int j = 0;
 while(j < 10){
   //output a frequency
   for(i=0;i<80;i++){
    digitalWrite(buzzer,HIGH);
    delay(1);//wait for 1ms
    digitalWrite(buzzer,LOW);
    delay(1);//wait for 1ms
   }
   
   //output another frequency
   for(i=0;i<100;i++){
      digitalWrite(buzzer,HIGH);
      delay(0.5);
      digitalWrite(buzzer,LOW);
      delay(0.5);
   }

  ++j;
 }
}



void loop(){
  int x = analogRead(A0);
  delay(10);
  
  if(abs(analogRead(A0) - x) > 2){
    alarm();
  }
}

Credits

galoebn
9 projects • 5 followers
Contact

Comments

Please log in or sign up to comment.