I am newbie with arduino
.. i am making a security system with 2 ping sensors and LCD + Keypad
this is the code for ping sensor
```
**const int pingPin = 7;
int Buzzer = 8;
void setup() {
Serial.begin(9600);
pinMode(Buzzer, OUTPUT);
}
void loop()
{
int duration, distance;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
distance = (duration/2) / 29.1;
//distance value changes we will measure it first (elmakeet):
if (distance >= 80 || distance <= 0){
Serial.println("no object detected");
digitalWrite(Buzzer, LOW);
}
else {
Serial.println("object detected");
digitalWrite(Buzzer, HIGH);
}
}**
** __**ok . if there are any mistakes please tell me .... and for lcd and keypad i am using this code**__ **
**#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(2,3,4,9,10,11,12);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3',},
{'4','5','6',},
{'7','8','9',},
{'*','0',' ',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
const int buttonPin = 7;
int buttonState = 0;
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledPin 13
void setup(){
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}
void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}
void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
lcd.print("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
delay(600);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}
else{
digitalWrite(ledPin,LOW);
lcd.print("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
delay(600);
lcd.clear();
}
}**
```
__**i got it from here http://www.instructables.com/id/Password-access-with-arduino/?ALLSTEPS**__
the whole system is to control the +VCC on ping sensor " ON-OFF Control " i ll attach the VCC pin of the sensor instead off the ledPin as my sensor needs 5v ..... is it possible to make another password to turn it off i mean when i enter 4321 it turns on when i press 5678 turn off ???? :~ :~....and what is the function of "buttonPin = 7" ?? i couldnt get it
![]()
and if there are any tutorials about this system send it to me [/size][/b]