Skip to content

Instantly share code, notes, and snippets.

@MindstormFan
Created June 10, 2019 20:20
Show Gist options
  • Save MindstormFan/2e7db4857a17d377efa37f1bcd8b81a0 to your computer and use it in GitHub Desktop.
Save MindstormFan/2e7db4857a17d377efa37f1bcd8b81a0 to your computer and use it in GitHub Desktop.
/www.elegoo.com
//2016.12.9
#include "pitches.h"
#include <LiquidCrystal.h>
int ledPin = 6; // LED on Pin 6 of Arduino
int pirPin = 2; // Input for HC-S501
int buzzer = 5;//the pin of the passive buzzer
int pirValue; // Place to store read PIR Value
int duration = 500; // 500 miliseconds
int melody[] = {NOTE_B0, NOTE_DS8};
int interruption = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
digitalWrite(ledPin, LOW);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Interruptions are: ");
}
void loop() {
pirValue = digitalRead(pirPin);
digitalWrite(ledPin, pirValue);
Serial.println(pirValue);
if(pirValue == 1) {
tone(buzzer, melody[0], duration);
++interruption;
lcd.setCursor(0, 1);
lcd.print((int)interruption);
delay(6000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment