Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an intruder alarm with a photoresistor, as many LEDs as you like, one buz

ID: 3349176 • Letter: C

Question

Create an intruder alarm with a photoresistor, as many LEDs as you like, one buzzer, and a button. The board must behave as follows: 1. When the photoresistor senses light, the LED(s) flash, and the buzzer produces a custom siren sound (feel free to use an enhanced version of the police siren from SF-2 challenge or if you want the intruder to have a pleasant time, play any song you want) 2. When the button is pushed, the board resets and allows you to set things back to normal in 5 sec. (add a 5 sec. delay to deactivate the alarm) 3. After 5 sec, the alarm should be active again 4. When there is no light, LED(s) and the buzzer are off. 5 Repeat this

Explanation / Answer

const int Photosensor = A0;

const int ledpin = 9;

const int buzzer = 8;

const int button = 2;

int value ; //read photosensor

int buttonstate = 0;

void setup () {

pinMode (Photosensor, INPUT);

pinMode (button, INPUT);

pinMode (ledpin, OUTPUT);

pinMode (buzzer, OUTPUT);

}

void loop () {

buttonstate = digitalRead(button);

value = analogRead (Photosensor);

if (value > 25) {

if (buttonstate == LOW) {

tone(buzzer, 1000);

digitalWrite(ledpin, HIGH);

delay (1000);

digitalWrite(ledpin, LOW);

delay (1000);

}

else

{

digitalWrite (ledpin, LOW);

noTone (buzzer);

delay (5000); //delay for 5 s if button is ON

}

}

else {

digitalWrite (ledpin, LOW);

noTone (buzzer);

delay(1000);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote