Go Down

Topic: Door Alarm (Read 203 times) previous topic - next topic

chummer1010

Apr 26, 2015, 01:48 am Last Edit: Apr 26, 2015, 01:49 am by chummer1010
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:

Code: [Select]

#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);  

}
#include <cheesy.quote>

LarryD

12, imagine what you will be able to do when you are 21.
Be curious.

Congratulations on your project.

Remember as you program, adding proper comments is a must as your projects become more and more complex.
Most here would recommend to avoid using the delay() function by using the techniques found in the blink without delay example.
Also study the techniques found in State Machine programming.
Google will help you find more information on both.
One last thing, the more you use lcd.clear() the more likely the LCD is to appear to flash or wink.
The way you have it in your schematic isn't the same as how you have it wired up!

chummer1010

12, imagine what you will be able to do when you are 21.
Be curious.

Congratulations on your project.

Remember as you program, adding proper comments is a must as your projects become more and more complex.
Most here would recommend to avoid using the delay() function by using the techniques found in the blink without delay example.
Also study the techniques found in State Machine programming.
Google will help you find more information on both.
One last thing, the more you use lcd.clear() the more likely the LCD is to appear to flash or wink.
Yes, lack of adding comments is from lazyness.  :P 
I have learned that there are much better ways than the delay() function. I should probably look into other options.

One last thing, the more you use lcd.clear() the more likely the LCD is to appear to flash or wink.
Actually, the whole screen blinks every second when it refreshes. I wanted to find a way to just remove the light value and not the whole screen but I couldn't find out.

12, imagine what you will be able to do when you are 21.
Be curious.
I'm always curious. When I'm not with friends or at school, I spend my time thinking about new project ideas. Unfortunately, at my age especially, lacking of money to get new parts is a huge constraint for me. Half of my ideas I can't do completely because I don't have a certain part. But it also teaches me resourcefulness. My original idea for the door alarm was to put a laser in front of the door, and the door opening breaks the laser's path. I turned that idea into using a photo resistor that detects light change.

Thank you very much for the response. :)
#include <cheesy.quote>

LarryD

When I was your age, many many many  years ago, I collected old devices from neighbours and relatives.
You can strip what you need using a good soldering iron.
Save up and buy yourself a DVM.
Keep a diary.
Start writing an Idea Book as you think of things.
Do well in your school work.

firmware is where things are at, keep up with the Arduino.

The way you have it in your schematic isn't the same as how you have it wired up!

chummer1010

When I was your age, many many many  years ago, I collected old devices from neighbours and relatives.
You can strip what you need using a good soldering iron.
Save up and buy yourself a DVM.
Keep a diary.
Start writing an Idea Book as you think of things.
Do well in your school work.

firmware is where things are at, keep up with the Arduino.


All of these are great ideas. I will start to do these now. Then when I have more materials I can look back at my ideas. My dad has a few DVMs and a solder. I'm sure he wouldn't mind me borrowing them until I have my own for now :D

firmware is where things are at, keep up with the Arduino.
My dad told me the same thing once. I have noted that this is very true. Technology will be everywhere when I'm older, way more than now.
#include <cheesy.quote>

Go Up