Professional Documents
Culture Documents
Nerraarduino
Nerraarduino
The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity
according to how accurate you want to detect gas.
Hardware components
Breadboard (generic)
× 1
5 mm LED: Red
× 1
5 mm LED: Green
× 1
Buzzer
× 1
1
Pin Wiring MQ-2 sensor code
void loop() {
int analogSensor = analogRead(smokeA0);
2
Automatic Pet Watering System
The automatic watering system simple just read the water level in the water bowl with a HC-
SR04 ultra sonic sound sensor. It measure the distance to the surface of the water. If the level is less
then 3cm for more than 30sec it triggers a 5V relay whit a NO-contact . The relay are controlling a
12VDC supply to a mini watering pump in the water tank.
Hardware components
Relay (generic)
× 1
Schematics
3
Code for Automatic Pet Watering System
int rele = 3;
int normaldrift = 5;
int fyller = 8; // LEVEL SENSOR
//
long duration; //-------------------------------------------
int distance; --//
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 9, 10, 7);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
void setup() digitalWrite(trigPin, LOW);
{
//---------------------------------------------
5
------//
if (releDrift == HIGH)
{
lcd.clear();
Food Detector
Food Detector: (By Measuring Resistances)
Hardware components
6
Resistor 10k ohm
× 1
Breadboard (generic)
× 1
× 1
Schematics
Arduino Food Detect
Hardware components
5 mm LED: Red
× 8
5 mm LED: Yellow
× 8
5 mm LED: Green
× 8
8
Jumper wires (generic)
× 1
Breadboard (generic)
× 1
USB-A to B Cable
× 1
For controlling Arduino
9
Schematics (Mini Auto V9 Image) Traffic Light Mini Auto V9 Code
int emergency = 0;
void setup() {
//sets up pins 3,4,5 as outputs
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(13, OUTPUT); //set up pin13LED as output
pinMode(2, INPUT); //set up emergency switch as
input
}
void loop() {
emergency = digitalRead(2);
if (emergency == LOW) {
// do RED for 10sec, green for 10sec, and yellow
for 3sec.
digitalWrite(13, LOW);
digitalWrite(3 , HIGH);
delay(10000);
digitalWrite(13, HIGH);
digitalWrite(3 ,LOW);
digitalWrite(5 ,HIGH);
delay(10000);
digitalWrite(5 ,LOW);
digitalWrite(4 ,HIGH);
delay(3000);
digitalWrite(4 , LOW);
}
else{
digitalWrite(3, HIGH);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(3, LOW);
digitalWrite(13, HIGH);
delay(1000);
}
}
/* Notes:
Press the RESET button on your board to restart the
circuit, putting it back on RED.
To go into Emergency Mode: Hold the Emergency Button
and press RESET.
*/
10
Sensal - All Senses Alarm Clock
Wake up, get productive or sleepy with the help of all available senses only
when you need it
Hardware components
LED (generic)
× 3
3w
Resistor 1k ohm
× 1
11
Photo resistor
× 1
Breadboard (generic)
× 1
12
Schematics
13
Code: Arduino sketch for Sensal
14
dht.begin();//initialize dht11 sensor if ( ledBrightness == endLed ||
setSyncProvider(RTC.get); // the ledBrightness < lastBrightnessLevel) {
function to get the time from the RTC if(ledBrightness != startLed && blink ==
// Alarm daily true && (unsigned int)(millis() -
Alarm.alarmRepeat(alarmHour, alarmMinute , 0, previousMillis) >= interval )
MorningAlarm); // alarm time {
} previousMillis = millis();
lastBrightnessLevel = ledBrightness;
ledBrightness--;
void loop() analogWrite(LED_PIN, ledBrightness);
{ }
}
// turn LEDs on if alarm is on. (pause in // was brightness increasing?
milliseconds between brightness levels, else if (ledBrightness == startLed ||
//starting level of brightness , final level ledBrightness >= lastBrightnessLevel) {
of brightness, if (ledAlarmIsOn == true && ledBrightness
//should it blink in a given range) < endLed && ((unsigned int)(millis() -
AlarmLed(3000, 0, 40, false); previousMillis) >= interval) ){
AlarmLed(1500, 40, 70, false); previousMillis = millis();
AlarmLed(100, 60, 220, false); lastBrightnessLevel = ledBrightness;
AlarmLed(50, 60, 220, true); ledBrightness++;
readJoystick(); //read joystick movements analogWrite(LED_PIN, ledBrightness);
click (); // read joystick button state }
joystick(); // //control LED brightness with }
joystick }
screenBacklight(); // screen autobrightness void click () {
screens(screenNumX()); // showing different value_Z = digitalRead(axis_Z); // read
screens joystick butoon state
Alarm.delay (1); // Wait small time before // is button pressed now?
repeating, needed for aralm boolean buttonIsUp = digitalRead(axis_Z);
} // if was up (&&) and not up now»...
void print2digits(int number) { if (buttonWasUp && !buttonIsUp) {
if (number >= 0 && number < 10) { // ...it may be click or fault signal, so
lcd.write('_'); we wait a little
} delay(5);
lcd.print(number); // ... and read signal again
} buttonIsUp = digitalRead(axis_Z);
if (!buttonIsUp) { // if it is still
// this method is needed for alarm to work presed
void MorningAlarm() { // ...it is a click. Revert LED state
ledAlarmIsOn = true; ledEnabled = !ledEnabled;
} if (ledEnabled ) {
// control LED. (on-off-blinking in given range ledBrightness = 110;
of brightness) (pause in milliseconds between analogWrite(LED_PIN, ledBrightness);
brightness levels,
//starting level of brightness , final level of }
brightness, else if (ledAlarmIsOn) {
//should it blink in a given range) ledAlarmIsOn = false;
ledBrightness = 0;
void AlarmLed(unsigned int interval, int analogWrite(LED_PIN, ledBrightness);
startLed, int endLed, boolean blink) { }
// was brightness decreasing?
15
else { }
ledBrightness = 0; }
analogWrite(LED_PIN, ledBrightness); }
}
} // change screen number
} byte screenNumX() {
buttonWasUp = buttonIsUp; // remember last
state of the button lastScreenNum = screenNum;
} if (millis() >= (previousMillis1 + 500)) {
// comparing current time with previous time
plus 0.5 seconds
void screenBacklight() { previousMillis1 = millis();
// screen autobrightness if (value_X >= 0 && value_X < 490 )
if ( analogRead(LDR_PIN) >= 890 && screenNum++;
ledAlarmIsOn == false) { if (value_X > 510 && value_X > 980 )
screenNum++;
lcd.noBacklight(); }
} if (screenNum > 1) screenNum = 0;
else { return screenNum;
lcd.backlight(); }
}
} // change screen depending on screen number
void screens(byte x) {
//control LED brightness with joystick if (lastScreenNum != screenNum)
void joystick() { lcd.clear(); // if screen is changing, clear it
before change
if (ledEnabled) if (screenNum == 0 ) {
else if (value_Y > 980 && screenNum == 1 ) static int sday = 0;// Saved day number for
cursorNum ++; change check
analogWrite(LED_PIN, ledBrightness);
16
void readJoystick() {
// Display time centered on the upper line value_X = analogRead(axis_X); // read
lcd.setCursor(0, 0); horizontal (Х) joystick
print2digits(hour()); value_Y = analogRead(axis_Y); // read
lcd.print(' '); vertical (y) joystick
print2digits(minute()); }
lcd.print(' ');
print2digits(second());
if (cursorNum == 0 || cursorNum == 1) {
lcd.setCursor(0, 0);
}
lcd.print(alarmHour);
lcd.print(' ');
lcd.print(alarmMinute);
}
}
}
17
Build a Simple Cocktail Drinkbot with Arduino (By Ted Kinsman)
Big parties need a conversation piece, and what’s better than a drink-making
robot? Not only is it a good conversation starter, it also frees up the party host who would normally
be the bartender. It turned out that the drink robot was a really good idea.
The robot is really an Arduino microprocessor (Uno version) that controls a number of pumps. A
simple program allows the pumps to turn on for the required time to make a mixed drink. The idea
here, is to get building and understand the basic concepts to make your own drink robot.
PARTS
--MAI TAI PARTS--
Rum, 30 ml.
Curacao (Orange), 12 ml.
Orgeat (Almond Syrup), 5 ml.
Grenadine Syrup, 6 ml.
Pineapple Juice + Lime, 120 ml. 10 squeezed limes added to 1 gallon of pineapple juice
ROBOT PARTS
Arduino Uno
Small Motors (shouldn't draw more than 120 mA when pumping)
18
Aquarium Peristaltic Pumps (2)
Submersible 12-volt Pump
Elegoo Resister Block
Doorbell Switch
19
The resistor block is manufactured by Elegoo and has 8 Channels. It is controlled by 5-volts from the
Arduino Uno. Note: to turn a relay on with this board, a control pin has to be written to a LOW value.
The computer code presented below in this article can easily be modified to deliver any drink in any
strength desired. It should be noted that the device is not limited to only one drink. The design can
be modified to make numerous drinks each selected by a push button.
20
Code for Build a Simple Cocktail Drinkbot with Arduino
/*This program is DrinkRobotMaiTie and makes th #define LED11 11 // LED above pump4 connected t
e spectacular o pin 11
#define Curacao 2 // (pump2) Curacao (orange) l int sensorValue = 0; //value written to when a
iquor connected to pin 2 nalog value is read from doorbell
21
pinMode(LED9, OUTPUT); digitalWrite (Grenedine, HIGH);//pump 5 off
pinMode(Grenedine, OUTPUT);
}
pinMode(LED11, OUTPUT);
void loop() //this part of the code loops and
loops forever
pinMode(LED12, OUTPUT);
{
pinMode(doorbell, INPUT);
sensorValue = analogRead(sensorPin);
pinMode(pump6, OUTPUT);
digitalWrite (Rum, HIGH); //pump 1 off //this stops when the start button is pressed
digitalWrite (LED9, LOW); //if bottom is pressed the LEDs show which moto
r is running
digitalWrite (LED8, HIGH); //turns on LED on pi
digitalWrite (Curacao, HIGH); //pump 2 off n 8
digitalWrite (LED10, LOW);
delay(strobe); // controls how fast the
LEDs flash
digitalWrite (Orgeat, HIGH); //pump 3 off
22
delay(strobe); sensorValue = analogRead(sensorPin);
delay(strobe);
digitalWrite (Curacao, LOW); //pump 2 on
digitalWrite (LED12, LOW); //turns off LED on p digitalWrite (Grenedine, HIGH); //turns off pim
in 12 p 4
delay(strobe);
23
delay(8000); // waits 8 sec to pump 1/4 oz
of liquid
24
Arduino Temperature Control
This project is about control of temperature in values of 23 and 25 grades
and control for hysteresis using DHT22 and Arduino 101
The project does a temperature control, we model the following situation:
The system starts and shows the temperature, if the temperature reaches 25 degrees, then the
green led is activated and the room starts to cool until the temperature drops to 23 degrees, the
air conditioner turns off (red led) until the temperature rises again
25
COMPONENTS AND SUPPLIES
Arduino 101 & Genuino 101
× 1
× 1
× 1
LED (generic)
× 2
× 1
× 2
Breadboard (generic)
× 1
26
27
CODE
29
Eye Motion Tracking Using Infrared Sensor
Use an infrared sensor to sense eye movements and control an LED.
× 1
NeoPixel strip
× 1
30
Eye Motion Tracking
Schematics
31
Sensor
I used two sensors QTR - 1A for eye tracking. QTR - 1A are placed on a plastic sheet at a
distance of about the width of the eye.
32
The sensor part and the microcontroller part were fixed to the eyeglasses with a clip
respectively.
Arduino Code
When the iris approaches one sensor, the reflected light decreases and the sensor value
increases. Conversely, when the iris moves away, the reflected light increases and the sensor
value of the photo reflector decreases.
The right and left movement of the pupil of the LED eyeball senses the increase and decrease of
one sensor value and controls it.
When blinking, both sensor values decrease, so if the two sensor values decrease
simultaneously, the eyelids of the LED eyeball will go down.
#include <QTRSensors.h>
#include <Adafruit_NeoPixel.h>
#define NUM_SENSORS 2 // number of sensors used
#define NUM_SAMPLES_PER_SENSOR 10 // averaging
#define EMITTER_PIN QTR_NO_EMITTER_PIN
33
int iniSensorValL, sensorValL;
int iniSensorValR, sensorValR;
#define PIN A3
Adafruit_NeoPixel led = Adafruit_NeoPixel(68, PIN, NEO_GRB + NEO_KHZ800);
int blackNum = 24;
int pupilNum = 12;
uint32_t color;
int brightness = 40;
byte eyeColor;
int LR =7;
boolean lid = false;
int cnt = 0;
//Black eye L&R animation
int blackLED[15][24] = {{12,32,35,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,6
8,68,68,68},
{12,13,31,36,54,55,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{11,13,14,30,37,53,54,56,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{10,11,14,15,29,38,52,53,56,57,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{ 9,10,11,12,15,16,28,33,34,39,51,52,55,56,57,58,68,68,68,68,68
,68,68,68},
{ 0, 8, 9,10,11,12,13,16,17,27,32,35,40,50,51,54,55,56,57,58,59
,67,68,68},
{ 0, 1, 7, 8, 9,10,13,14,17,18,26,31,36,41,49,50,53,54,57,58,59
,60,66,67},
{ 1, 2, 6, 7, 8, 9,14,15,18,19,25,30,37,42,48,49,52,53,58,59,60
,61,65,66},
{ 2, 3, 5, 6, 7, 8,15,16,19,20,24,29,38,43,47,48,51,52,59,60,61
,62,64,65},
{ 3, 4, 5, 6, 7,16,17,20,21,23,28,39,44,46,47,50,51,60,61,62,63
,64,68,68},
{ 4, 5, 6,17,18,21,22,27,40,45,46,49,50,61,62,63,68,68,68,68,68
,68,68,68},
{ 4, 5,18,19,26,41,48,49,62,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{ 4,19,20,25,42,47,48,63,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{20,21,24,43,46,47,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68},
{21,23,44,46,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68,68
,68,68,68}};
//pupil L&R animation
int pupilLED[15][12] = {{33,34,68,68,68,68,68,68,68,68,68,68},
{32,33,34,35,68,68,68,68,68,68,68,68},
{12,31,32,33,34,35,36,55,68,68,68,68},
{12,13,30,31,32,33,34,35,36,37,54,55},
{13,14,29,30,31,32,35,36,37,38,53,54},
{14,15,28,29,30,31,36,37,38,39,52,53},
{15,16,27,28,29,30,37,38,39,40,51,52},
{16,17,26,27,28,29,38,39,40,41,50,51},
{17,18,25,26,27,28,39,40,41,42,49,50},
{18,19,24,25,26,27,40,41,42,43,48,49},
{19,20,23,24,25,26,41,42,43,44,47,48},
{20,21,22,23,24,25,42,43,44,45,46,47},
{21,22,23,24,43,44,45,46,68,68,68,68},
{22,23,44,45,68,68,68,68,68,68,68,68},
{22,45,68,68,68,68,68,68,68,68,68,68}};
//Blink animation
int eyelid = 0;
34
int eyelidNum[8] = {0,4,8,16,24,34,44,56};
int eyelidLED[56] = {64,65,66,67,58,59,60,61,56,57,62,63,49,50,51,52,47,48,53,54,38,39
,40,41,46,55,36,37,42,43,26,27,28,29,35,44,24,25,30,31,15,16,17,18,34,45,23,32,13,14,1
9,20,6,7,8,9};
QTRSensorsAnalog qtra((unsigned char[]) {0, 1}, NUM_SENSORS, NUM_SAMPLES_PER_SENSOR, E
MITTER_PIN);
unsigned int sensorValues[NUM_SENSORS];
void blink(int eyelid, int LR) {
if (eyelid != 8){
//Pewter
for(uint16_t i=0; i<led.numPixels(); i++) {
led.setPixelColor(i, led.Color(66, 66, 66));
}
//Black eye
for(uint16_t i=0; i<blackNum; i++) {
led.setPixelColor(blackLED[LR][i], color);
}
//pupil
for(uint16_t i=0; i<pupilNum; i++) {
led.setPixelColor(pupilLED[LR][i], led.Color(0, 0, 66));
}
//eyelid
for(int i=0; i < eyelidNum[eyelid]; i++) {
led.setPixelColor(eyelidLED[i], 0);
}
} else if (eyelid == 8){
led.clear();
}
led.show();
}
void setup() {
Serial.begin(115200);
led.begin();
led.setBrightness(brightness); // Initial Brightness 40
led.show(); // Initialize all pixels to 'off'
color = led.Color(0, 177, 55); //pupil color
delay(100);
qtra.read(sensorValues);
iniSensorValL = sensorValues[0];
iniSensorValR = sensorValues[1];
blink(eyelid, LR);
}
void loop() {
//QTR - 1A sensor value
qtra.read(sensorValues);
sensorValL = sensorValues[0];
sensorValR = sensorValues[1];
double rasioL = (double)sensorValL / iniSensorValL;
double rasioR = (double)sensorValR / iniSensorValR;
Serial.print(rasioL);
Serial.print(" ");
Serial.println(rasioR);
if(rasioL > 0.985 && rasioR < 0.985){ //right
for(int i = LR; i < 12; i++){
blink(0, i);
delay(40);
LR = i;
}
}else if(rasioL < 0.985 && rasioR > 0.985){ //left
for(int i=LR; i>2; i--){
blink(0, i);
35
delay(40);
LR = i;
}
}else if(lid == false && rasioL < 0.96 && rasioR < 0.96){ //Blinking close
for(int i = 1; i < 9; i++){
blink(i, LR);
delay(40);
lid = true;
}
}else if(lid == true && rasioL > 0.96 && rasioR > 0.96){ //Blinking open
for(int i = 8; i > 0; i--){
blink(i, LR);
delay(40);
lid = false;
}
}else if(lid == false && rasioL > 0.96 && rasioR > 0.96) { //normal
//cnt++;
//eyelid = 0;
if(LR <= 7){
for(int i=LR; i<=7; i++){
blink(0, i);
delay(40);
LR = i;
}
}else {
for(int i=LR; i>=7; i--){
blink(0, i);
delay(40);
LR = i;
}
}
Serial.println("通常時");
}
//Initial value refresh
if (cnt > 10){
iniSensorValL = sensorValL;
iniSensorValR = sensorValR;
cnt = 0;
}
}
36
COMPONENTS AND SUPPLIES
Arduino UNO & Genuino UNO
× 1
Wiring
Stack PHPoC WiFi shield on Arduino.
Connect pin GND, 3.3V, pin SCL and SDA of color sensor to GND, 3.3V, A4 and A5 of Arduino,
respectively. (see schematics section)
Data Flow
Arduino ---> PHPoC WiFi Shield ---> Web browser
Arduino reads RGB color values from sensor and send the values to PHPoC WiFi Shield. When
receiving the color values, PHPoC WiFi Shield send it to Web browser via websocket. Web
browser changes background color to the received color.
Since background image is png image, some parts of image is transparent. Therefore, we will
see the background color in transparent part of background image. In the demonstration, body
of Minion is transparent. When background color is changed, we will see the color of Minion is
changed.
Note that: PHPoC shield has a built-in program to pass data from Arduino to web browser.
Therefore, we don't need to care about it.
What We Need to Do
Set WiFi information for PHPoC shield (SSID and password)
Upload new UI to PHPoC shield
37
Write Arduino code
Setting WiFi Information for PHPoC Shield
See this instruction.
Upload new Web UI to PHPoC Shield
Download PHPoC source code remote_color.php (on code section) and background.png file.
background.png
Upload them to PHPoC shield using PHPoC debugger according to this instruction.
Write Arduino Code
Install three following libraries: PHPoC Library for Arduino, SparkFun ISL29125(see instruction).
Upload Arduino code (on code section) to Arduino.
Testing
Click serial button on Arduino IDE to see the IP address.
Open web browser, type http:// replace_ip_address /remote_color.php
Click connect button and test it.
CODE
39
40
Arduino Security and Alarm System Project
If you ever thought of making your own security system then this project is a great starting
point. Here we will utilize an ultrasonic sensor for detecting movement.
If a human or object passes in front of the sensor, the alarm will be activated. For deactivating the
alarm you will have to enter a password using a keypad.
Required Components
Now let’s see the required components for this project. Obviously, we need an Arduino board, an
ultrasonic sensor, an LCD display, a buzzer and a 4×4 keypad.
41
Circuit Schematics
So for the buzzer we need just a single pin but one with PWM support. The 4×4 keypad has 8 pins, 4
of them are for the rows and 4 of them for the columns of the keypad. Each button is actually a push
button switch which makes a short between one row and column when pressed.
So, for example, if we set the row 1 line low, and all column lines high, when we will press, for
example, the button 3, due to the short between the two lines, the column 3 line will drop to low so in
such a case we can register that the button 3 has been pressed.
As for the other two components on this project, the ultrasonic sensor and the LCD display, you can
check my previous detailed tutorials on how to connect and use them.
42
Arduino Alarm System Source Code
1. if (!alarmActivated) {
1. #include <LiquidCrystal.h> // includes the LiquidCrystal 2. if (screenOffMsg == 0 ){
Library 3. lcd.clear();
2. #include <Keypad.h> 4. lcd.setCursor(0,0);
3. 5. lcd.print("A - Activate");
4. #define buzzer 8 6. lcd.setCursor(0,1);
5. #define trigPin 9 7. lcd.print("B - Change Pass");
6. #define echoPin 10 8. screenOffMsg = 1;
7. 9. }
8. long duration; 10. keypressed = myKeypad.getKey();
9. int distance, initialDistance, currentDistance, i; 11. if (keypressed =='A'){ //If A is pressed, activate the alarm
10. int screenOffMsg =0; 12. tone(buzzer, 1000, 200);
11. String password="1234"; 13. activateAlarm = true;
12. String tempPassword; 14. }
13. boolean activated = false; // State of the alarm
14. boolean isActivated; 15. if (activateAlarm) {
15. boolean activateAlarm = false; 16. lcd.clear();
16. boolean alarmActivated = false; 17. lcd.setCursor(0,0);
17. boolean enteredPassword; // State of the entered password 18. lcd.print("Alarm will be");
to stop the alarm 19. lcd.setCursor(0,1);
18. boolean passChangeMode = false; 20. lcd.print("activated in");
19. boolean passChanged = false; 21.
20. 22. int countdown = 9; // 9 seconds count down before
21. const byte ROWS = 4; //four rows activating the alarm
22. const byte COLS = 4; //four columns 23. while (countdown != 0) {
23. char keypressed; 24. lcd.setCursor(13,1);
24. //define the cymbols on the buttons of the keypads 25. lcd.print(countdown);
25. char keyMap[ROWS][COLS] = { 26. countdown--;
26. {'1','2','3','A'}, 27. tone(buzzer, 700, 100);
27. {'4','5','6','B'}, 28. delay(1000);
28. {'7','8','9','C'}, 29. }
29. {'*','0','#','D'} 30. lcd.clear();
30. }; 31. lcd.setCursor(0,0);
31. byte rowPins[ROWS] = {14, 15, 16, 17}; //Row pinouts of 32. lcd.print("Alarm Activated!");
the keypad 33. initialDistance = getDistance();
32. byte colPins[COLS] = {18, 19, 20, 21}; //Column pinouts of 34. activateAlarm = false;
the keypad 35. alarmActivated = true;
33. 36. }
34. Keypad myKeypad = Keypad( makeKeymap(keyMap),
37. }
rowPins, colPins, ROWS, COLS);
38. }
35. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object.
39. if (k > 9 || keypressed == '#') {
Parameters: (rs, enable, d4, d5, d6, d7)
40. tempPassword = "";
36. void setup() {
41. k=5;
37. lcd.begin(16,2);
42. lcd.clear();
38. pinMode(buzzer, OUTPUT); // Set buzzer as an output
43. lcd.setCursor(0,0);
39. pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
44. lcd.print(" *** ALARM *** ");
40. pinMode(echoPin, INPUT); // Sets the echoPin as an Input
45.
41. }
42.
43
1. lcd.setCursor(0,1); 1. lcd.clear();
2. lcd.print("Pass>"); 2. lcd.setCursor(0,0);
3. } 3. lcd.print("Current Password");
4. if ( keypressed == '*') { 4. lcd.setCursor(0,1);
5. if ( tempPassword == password ) { 5. lcd.print(">");
6. activated = false; 6. }
7. alarmActivated = false; 7. if ( keypressed == '*') {
8. noTone(buzzer); 8. i=1;
9. screenOffMsg = 0; 9. tone(buzzer, 2000, 100);
10. } 10. if (password == tempPassword) {
11. else if (tempPassword != password) { 11. tempPassword="";
12. lcd.setCursor(0,1); 12. lcd.clear();
13. lcd.print("Wrong! Try Again"); 13. lcd.setCursor(0,0);
14. delay(2000); 14. lcd.print("Set New Password");
15. lcd.clear(); 15. lcd.setCursor(0,1);
16. lcd.setCursor(0,0); 16. lcd.print(">");
17. lcd.print(" *** ALARM *** "); 17. while(passChangeMode) {
18. lcd.setCursor(0,1); 18. keypressed = myKeypad.getKey();
19. lcd.print("Pass>"); 19. if (keypressed != NO_KEY){
20. } 20. if (keypressed == '0' || keypressed == '1' || keypressed == '2'
21. } || keypressed == '3' ||
22. } 21. keypressed == '4' || keypressed == '5' || keypressed == '6' ||
23. } keypressed == '7' ||
22. keypressed == '8' || keypressed == '9' ) {
24. else if (keypressed =='B') { 23. tempPassword += keypressed;
25. lcd.clear(); 24. lcd.setCursor(i,1);
26. int i=1; 25. lcd.print("*");
27. tone(buzzer, 2000, 100); 26. i++;
28. tempPassword = ""; 27. tone(buzzer, 2000, 100);
29. lcd.setCursor(0,0); 28. }
30. lcd.print("Current Password"); 29. }
31. lcd.setCursor(0,1); 30. if (i > 5 || keypressed == '#') {
32. lcd.print(">"); 31. tempPassword = "";
33. passChangeMode = true; 32. i=1;
34. passChanged = true; 33. tone(buzzer, 2000, 100);
35. while(passChanged) { 34. lcd.clear();
36. keypressed = myKeypad.getKey(); 35. lcd.setCursor(0,0);
37. if (keypressed != NO_KEY){ 36. lcd.print("Set New Password");
38. if (keypressed == '0' || keypressed == '1' || keypressed == 37. lcd.setCursor(0,1);
'2' || keypressed == '3' || 38. lcd.print(">");
39. keypressed == '4' || keypressed == '5' || keypressed == '6' 39. }
|| keypressed == '7' || 40. if ( keypressed == '*') {
40. keypressed == '8' || keypressed == '9' ) { 41. i=1;
41. tempPassword += keypressed; 42. tone(buzzer, 2000, 100);
42. lcd.setCursor(i,1); 43. password = tempPassword;
43. lcd.print("*"); 44. passChangeMode = false;
44. i++; 45. passChanged = false;
45. tone(buzzer, 2000, 100); 46. screenOffMsg = 0;
46. } 47. }
47. } 48. }
48. if (i > 5 || keypressed == '#') { 49. }
49. tempPassword = ""; 50. }
50. i=1; 51. }
51. 52. }
44