Hello everyone,
I would say this is my first major project using the Arduino, and I have to say I am proud of myself. What I present to you is an alarm that is triggered when the door opens. I used a photo resistor to detect the light values parallel to the door and refreshes every second. These values are displayed on an LCD screen. But, when the door opens, the light value drops and the photo resistor detects the change and sets off a chain of lights and the screen displays the message "Intruder!"
Here is a link to the Instructable I made that tells you how to make it. Attached is an extra photo of the final project.
Please leave feedback both here and on the Instructable. I would like constructive criticism (trust me I can take it), but for those complete computer geniouses keep in mind I'm 12. Thanks for reading!
Code for anyone who wants it:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 13, 6, 7);
const int sensorPin = A0;
int timer1 = 150;
int timer2 = 500;
int ledPins[] = {
2, 9, 3, 4, 8, 5 };
int pinCount = 6;
int sensorValue = 0;
int rawSensorValue;
void setup() {
lcd.begin(16, 2);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(sensorPin, INPUT);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
void loop() {
rawSensorValue = analogRead(sensorPin);
delay(1000);
sensorValue = rawSensorValue/4;
lcd.print("Sensor Value:");
lcd.print(sensorValue);
delay(5);
if(sensorValue < 140) {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer1);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer1);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
lcd.setCursor(0,1);
lcd.print("Intruder!");
delay(1000);
lcd.setCursor(0, 0);
lcd.clear();
}
else {
lcd.clear();
rawSensorValue = analogRead(sensorPin);
delay(1000);
sensorValue = rawSensorValue/4;
lcd.setCursor(0,0);
lcd.print("Sensor Value:");
lcd.print(sensorValue);
delay(5);
}
lcd.setCursor(0, 0);
}