#include <EasyUltrasonic.h>
#include <LiquidCrystal_I2C.h>
int ledPin = 12; //led pin
int trigPin = 2; //ultrasonic
int echoPin = 3; //ultrasonic
int buzzPin = 4; //buzzer
int buttonPin = 5; //butotn
int pirPin = 6;
EasyUltrasonic ultrasonic;
LiquidCrystal_I2C lcd (0x27, 20, 4);
float defdist;
int lastState = LOW; //button
int currentState; //button
void setup() {
Serial.begin(9600); // or the computer can output a signal
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
ultrasonic.attach(trigPin, echoPin, 2, 400); // Sets the sensor pins as output/input (The default values for the minDistance and maxDistance parameters correspond to the HC-SR04 ultrasonic sensor distance range)
defdist = 400.00;
lcd.init();
lcd.backlight();
}
void loop() {
currentState = digitalRead(buttonPin);
float diff = ultrasonic.getDistanceCM();
if (diff < defdist || (digitalRead(buttonPin) == LOW) || (digitalRead(pirPin) == HIGH))
{
actions();
}
}
void actions(){
digitalWrite(ledPin, HIGH); //tells the arduino to turn on or off that specific pin
Serial.println("Change detected");
digitalWrite(buzzPin, HIGH);
lcd.print("Someone is detected!");
delay(2000);
digitalWrite(buzzPin, LOW);
digitalWrite(ledPin, LOW);
}
// IN ORDER TO START SIMULATING THE ELECTRONCIS
// 1. PRESS THE GREEN START BUTTON IN THE TOP MIDDLE
// 2. CLICK ON OF THE THREE INTERACTIVE ELECTRONICS (THE WHITE CIRCLE THING, A RED BUTTON, THE TWO CIRCLE WITH GRILLS)
// 3. IF CLICKED ON THE WHITE CIRCLE THING, PRESS SIMULATE MOTION
// 4. IF CLICKED ON THE TWO CRICLE THING, LOWER THE DEFAULT DISTANCE
// 5. IF CLICKED ON THE RED BUTTON, IT SHOULD AUTOMATICALLY WORK.