Greetings ,
I have Arduino UNO and I connected 4x4 keypad and two led green and red and also a servo motor .
If I enter 789 the green led will be ON and servo motor rotates by 90 degree . If the password is wrong , nothing happened .
I want to add HC-SR04 ULTRASONIC MOTION SENSOR to my project, and it will be ON and detects motion
and if any motion detected it will make alarm sound . But if the password entered is correct it will be OFF .
Please help me with this issue
Here is my code (Not my own code copied from a website and edited it ) :
#include <Keypad.h>
#include <Servo.h>
Servo servo_Motor;
char* password = "789";
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'', '0', '#', 'D'}
};
byte rowPins[ROWS] = { 10,9,8,7 };
byte colPins[COLS] = { 6,5,4,3 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int redPin = 12;
int greenPin = 13;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
servo_Motor.attach(11);
setLocked(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '' || key == '#')
{
position = 0;
setLocked(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
setLocked(false);
}
delay(100);
}
void setLocked(int locked)
{
if (locked)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
servo_Motor.write(11);
}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
servo_Motor.write(90);
}
}
Thanks in advance