Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_SR_LCD3.h>
- const int PIN_LCD_STROBE = 2;
- const int PIN_LCD_DATA = 3;
- const int PIN_LCD_CLOCK = 4;
- LiquidCrystal_SR_LCD3 lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE);
- int ledPin = A5; // choose the pin for the LED
- int inputPin = 12; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0; // variable for reading the pin status
- int button=7, push=0, ok=0, on=0, menu=0;
- int buzzer=A0;
- unsigned long turnoff;
- void setup() {
- pinMode(ledPin, OUTPUT); // declare LED as output
- pinMode(inputPin, INPUT); // declare sensor as input
- pinMode(button, INPUT);
- pinMode(buzzer, OUTPUT);
- lcd.begin(16,2);
- lcd.home();
- Serial.begin(9600);
- }
- void loop(){
- Serial.print(" BUTTON : ");
- Serial.println(digitalRead(button));
- while(digitalRead(button)==LOW){
- if(push==0 && ok==0){
- push=1;
- }else if(push==1 && ok==1){
- push=2;
- }else if(push==2 && ok==2){
- push=3;
- }else if(push==3 && ok==3){
- push=1;
- }else if(push==4 && ok==4){
- push=1;
- }
- }
- val = digitalRead(inputPin); // read input value
- if(push==0){
- lcd.clear();
- ok=0;
- }else if(push==1 || push==2 || push==3){
- ok=1;
- if(push==2){
- ok=2;
- }else if(push==3){
- ok=3;
- }
- lcd.clear();
- lcd.setCursor(0,0);
- if(push==1){
- lcd.print("Menu 1");
- }else if(push==2){
- lcd.print("Menu 2");
- }else if(push==3){
- lcd.print("Menu 3");
- }
- if((turnoff+3000) < millis() && on==1){
- val=LOW;
- on=0;
- }
- if (val == HIGH) {
- lcd.setCursor(0,1);
- lcd.print(" Motion Detected! ");
- if (pirState == LOW && on==0) {
- // we have just turned on
- Serial.println("Motion detected!");
- // We only want to print on the output change, not state
- pirState = HIGH;
- if(on==0){
- turnoff = millis();
- }
- on=1;
- if(push==2){
- lcd.setCursor(8,0);
- lcd.print("buz:ON");
- analogWrite(buzzer, 255);
- }
- }
- if(push==3){
- for(int i=0; i<5; i++){
- digitalWrite(ledPin, HIGH);
- delay(200);
- digitalWrite(ledPin, LOW);
- delay(200);
- }
- }else{
- digitalWrite(ledPin, HIGH); // turn LED ON
- }
- } else {
- digitalWrite(ledPin, LOW); // turn LED OFF
- lcd.setCursor(0,1);
- lcd.print(" Motion ended! ");
- if (pirState == HIGH){
- // we have just turned of
- Serial.println("Motion ended!");
- // We only want to print on the output change, not state
- pirState = LOW;
- lcd.setCursor(8,0);
- lcd.print("buz:OFF");
- analogWrite(buzzer, 0);
- }
- }
- }else if(push==4){
- ok=4;
- }
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement