Snap Circuits Door Alarm
This blend of Arduino and Snap Circuits makes a door alarm.
Components and supplies
1
Arduino UNO
1
Snap Circuits ® 300 Experiments
1
Snap-to-Pin Set, 10 pcs.
Project description
Code
The code
arduino
Just paste this code into your Arduino editor (don't worry you can copy my code) and hit upload.
1/* 2 LiquidCrystal Library - Hello World 3 4 Demonstrates the use a 16x2 LCD display. The LiquidCrystal 5 library works with all LCD displays that are compatible with the 6 Hitachi HD44780 driver. There are many of them out there, and you 7 can usually tell them by the 16-pin interface. 8 9 This sketch prints "Hello World!" to the LCD 10 and shows the time. 11 12 The circuit: 13 * LCD RS pin to digital pin 12 14 * LCD Enable pin to digital pin 11 15 * LCD D4 pin to digital pin 5 16 * LCD D5 pin to digital pin 4 17 * LCD D6 pin to digital pin 3 18 * LCD D7 pin to digital pin 2 19 * LCD R/W pin to ground 20 * LCD VSS pin to ground 21 * LCD VCC pin to 5V 22 * 10K resistor: 23 * ends to +5V and ground 24 * wiper to LCD VO pin (pin 3) 25 26 Library originally added 18 Apr 2008 27 by David A. Mellis 28 library modified 5 Jul 2009 29 by Limor Fried (http://www.ladyada.net) 30 example added 9 Jul 2009 31 by Tom Igoe 32 modified 22 Nov 2010 33 by Tom Igoe 34 modified 7 Nov 2016 35 by Arturo Guadalupi 36 37 This example code is in the public domain. 38 39 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld 40 41*/ 42 43// include the library code: 44#include <LiquidCrystal.h> 45 46// initialize the library by associating any needed LCD interface pin 47// with the arduino pin number it is connected to 48const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 49LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 50 51void setup() { 52 // set up the LCD's number of columns and rows 53 lcd.begin(16, 2); 54 pinMode(6, INPUT_PULLUP); 55 pinMode(7, OUTPUT); 56 pinMode(8, INPUT); 57} 58void loop() { 59 60 // Clear LCD 61 lcd.clear(); 62 63 // Check if switch is ON 64 if (digitalRead(6) == LOW) { 65 66 // Turn on relay 67 digitalWrite(7, LOW); 68 69 // Write armed status to LCD 70 lcd.setCursor(0,0); 71 lcd.print("Status: Armed"); 72 73 // Write door status to LCD 74 lcd.setCursor(2,1); 75 if (digitalRead(8) == HIGH) { 76 lcd.print("Door: Open"); 77 } else { 78 lcd.print("Door: Closed"); 79 } 80 81 // Switch is OFF 82 } else { 83 84 // Turn off relay 85 digitalWrite(7, HIGH); 86 87 // Write armed status to LCD 88 lcd.setCursor(0,0); 89 lcd.print("Status: Disarmed"); 90 91 } 92 93 delay(1000); 94 95} 96
The code
arduino
Just paste this code into your Arduino editor (don't worry you can copy my code) and hit upload.
1/* 2 LiquidCrystal Library - Hello World 3 4 Demonstrates the use a 16x2 LCD display. The LiquidCrystal 5 library works with all LCD displays that are compatible with the 6 Hitachi HD44780 driver. There are many of them out there, and you 7 can usually tell them by the 16-pin interface. 8 9 This sketch prints "Hello World!" to the LCD 10 and shows the time. 11 12 The circuit: 13 * LCD RS pin to digital pin 12 14 * LCD Enable pin to digital pin 11 15 * LCD D4 pin to digital pin 5 16 * LCD D5 pin to digital pin 4 17 * LCD D6 pin to digital pin 3 18 * LCD D7 pin to digital pin 2 19 * LCD R/W pin to ground 20 * LCD VSS pin to ground 21 * LCD VCC pin to 5V 22 * 10K resistor: 23 * ends to +5V and ground 24 * wiper to LCD VO pin (pin 3) 25 26 Library originally added 18 Apr 2008 27 by David A. Mellis 28 library modified 5 Jul 2009 29 by Limor Fried (http://www.ladyada.net) 30 example added 9 Jul 2009 31 by Tom Igoe 32 modified 22 Nov 2010 33 by Tom Igoe 34 modified 7 Nov 2016 35 by Arturo Guadalupi 36 37 This example code is in the public domain. 38 39 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld 40 41*/ 42 43// include the library code: 44#include <LiquidCrystal.h> 45 46// initialize the library by associating any needed LCD interface pin 47// with the arduino pin number it is connected to 48const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 49LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 50 51void setup() { 52 // set up the LCD's number of columns and rows 53 lcd.begin(16, 2); 54 pinMode(6, INPUT_PULLUP); 55 pinMode(7, OUTPUT); 56 pinMode(8, INPUT); 57} 58void loop() { 59 60 // Clear LCD 61 lcd.clear(); 62 63 // Check if switch is ON 64 if (digitalRead(6) == LOW) { 65 66 // Turn on relay 67 digitalWrite(7, LOW); 68 69 // Write armed status to LCD 70 lcd.setCursor(0,0); 71 lcd.print("Status: Armed"); 72 73 // Write door status to LCD 74 lcd.setCursor(2,1); 75 if (digitalRead(8) == HIGH) { 76 lcd.print("Door: Open"); 77 } else { 78 lcd.print("Door: Closed"); 79 } 80 81 // Switch is OFF 82 } else { 83 84 // Turn off relay 85 digitalWrite(7, HIGH); 86 87 // Write armed status to LCD 88 lcd.setCursor(0,0); 89 lcd.print("Status: Disarmed"); 90 91 } 92 93 delay(1000); 94 95} 96
Downloadable files
Schematic image
Schematic image
Comments
Only logged in users can leave comments