Introduction: Light Sensitive Alarm

Picture of Light Sensitive Alarm

In this Instructables, you will know how to make a Light sensitive alarm. It will be able to detect different amounts of light and then play a song to your choosing.

Materials needed:

-1 Arduino Uno or any other Arduino

-1 LDR (light dependent resistor).

-1 buzzer or speakers

-1 project box

-breadboard and wires

Step 1: Making the Circuitry

Picture of Making the Circuitry

For the circuit connect the buzzer to GND and DP 9

For the LDR connect one side to GND and the other to A0 and add a resistor between the LDR and A0

Step 2: Another View

Picture of Another View

Step 3: Codeing

Below is the code used to make the alarm run, Ive set it so it plays the melody of Final count down

int rcvpin=A0;
int buzzpin=9;

void setup()

{

pinMode(rcvpin,INPUT);

pinMode(buzzpin,OUTPUT);

buzz(200);

buzz(200);

buzz(200);

delay(2000);

Serial.begin(9600);

}

void loop()

{

int ldrval=analogRead(rcvpin);

Serial.println(ldrval);

if(ldrval<=800)

{

//buzz(50);

playmelody();

}

}

#define C_note 261

#define C_sharp 277

#define D_note 293

#define D_sharp 311

#define E_note 329

#define F_note 349

#define F_sharp 369

#define G_note 391

#define G_sharp 415

#define A_note 440

#define A_sharp 466

#define B_note 246

int melody2[] = { F_sharp, 16, E_note, 16, F_sharp, 64, B_note, 64,

G_note, 16, F_sharp, 16, G_note, 32, F_sharp, 32, E_note, 64,

G_note, 16, F_sharp, 16, G_note, 64, B_note, 64,

E_note, 16, D_note, 16, E_note, 32, D_note, 32,

C_note, 32, E_note, 32, D_note, 64, F_sharp, 16,

E_note, 16, F_sharp, 64, B_note, 64,

0, 0 };

int melody[] = { C_sharp, B_note, C_sharp, F_sharp, D_note, C_sharp, D_note, C_sharp, B_note, D_note,

C_sharp, D_note, F_sharp, B_note, A_note, B_note, A_note, G_sharp, B_note, A_note,

G_sharp, A_note, B_note, A_note, B_note, C_sharp, B_note, A_note, G_sharp, F_note,

D_note, C_sharp, C_sharp, C_sharp, D_note, C_sharp, B_note, C_sharp };

void playmelody() {

int i=0;

while(melody2[i]>0) {

tone(buzzpin, melody2[i]);

delay(melody2[i+1]*10);

i=i+2;

}

noTone(buzzpin);

}

void buzz(unsigned char time)

{

analogWrite(buzzpin,170);

delay(time);

analogWrite(buzzpin,0);

delay(time);

}

Step 4: Fitting the Box

Picture of Fitting the Box

After wiring the breadboard and making sure the code works. move the breadboard on top of the Arduino to maximize space used. After that go ahead and drill out the holes for the LDR and power cord.

Step 5: Finished

Picture of Finished

After all that is done the LDR and power cord should fit perfectly

Comments

DIY Hacks and How Tos (author)2016-06-04

This is a great intro to Arduino project. It teaches all about the basics of inputs, outputs and comparators.

About This Instructable

247views

8favorites

License:

More by Co_jo:Light Sensitive Alarm
Add instructable to: