Piezo alarm 5v .
i want to make a code so it allows me enable and disable these 2 sensors when i enter a password with keypad and when i enable them if any object detected they give signal to piezo alarm …
i tried many time but no good result =(
sorry for bad english
P.S : i am new with Arduino XD XD
this is ultrasonic code i made i couldnt make a one with keypad … i might use LCD too XD
#include <NewPing.h>
#define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 100 // Maximum distance we want to ping for (in centimeters).
#define ALARM 3
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
boolean triggered = false;
void setup(){
pinMode(ALARM, OUTPUT);
}
void loop(){
if(triggered == true){
alarm();
}
else{
delay(50);// Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
unsigned int distance = uS / US_ROUNDTRIP_CM;
Serial.println(distance);
if(distance < 50){
triggered = true;
}
}
}
void alarm(){
digitalWrite(ALARM,HIGH);
}
#define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonic sensor.
You said you have a 3 pin US range finder, yet the library your using needs the 4 pin US range finder. You need to change one of the two, either the code or the ping sensor.
this is a basic code i am using i know i have it 3 pins only and i changed it while testing the sensor but the whole problem is controlling the 2 sensors with Keypad 4X4 and LCD
Its very simple actually, but I do not see anything that has to do with a keypad or a Lcd. If you "Search the Arduino Forum" for keypad password and LCD, you'll most likely find tons of information and examples.
We see these questions all the time, "I need help making a password" or "I want to enter a password with a keypad..."
/*
Phi-panel serial sample program
Password entry
----------------------------------------
Programmed by Dr. John Liu
Revision: 08/12/2011
All rights reserved.
----------------------------------------
*/
char in_char[16]; // Buffer to store incoming characters
int response; // Stores whether the password is a match to the key
void setup()
{
Serial.begin(19200);
delay(100); // Make sure the panel is up and running.
}
void loop()
{
Serial.println("Enter password:"); // Print the question
get_passwd(in_char); // Get password from user, which will be stored in in_char[].
response=strcmp(in_char, "072811"); // Compare the input with key "072811". 0 means match.
if (response==0) Serial.println("Correct!");
else Serial.println("Incorrect!");
delay(3000);
}
void get_passwd(char in_char[])
{
int i=0;
while(1) {
if (Serial.available()) {
in_char[i]=Serial.read(); // Read in one character
if (in_char[i]=='\n') { // The \n represents enter key.
in_char[i]=0; // Terminate the string with 0.
Serial.write('\n'); // New line
break; // This breaks out of the while(1) loop.
}
Serial.write('*'); // Echo * to hide user input
i++;
}
}
}
The following video is entering password on a full panel. The lcd backpack version with the link I gave you works with 4X4 keypads but the code is identical.
You can now focus on doing your project, not about the user interface.