1#define pirPin 7
2
3long unsigned int lowIn;
4long unsigned int pause = 5000;
5boolean lockLow = true;
6boolean takeLowTime;
7
8#include <LiquidCrystal_I2C.h>
9#include <Wire.h>
10
11LiquidCrystal_I2C lcd(0x27,20,4);
12
13
14void setup() {
15 Serial.begin(9600);
16 pinMode(pirPin, INPUT);
17
18
19 lcd.init();
20 lcd.backlight();
21 lcd.begin(16,2);
22 lcd.setCursor(0,0);
23 lcd.print("Welcome To :");
24 lcd.setCursor(0,1);
25 lcd.print("Techwan Canel");
26 delay(3000);
27
28}
29
30void loop() {
31
32
33 PIRSensor();
34
35
36}
37
38void PIRSensor() {
39
40 if(digitalRead(pirPin) == HIGH) {
41 if(lockLow) {
42 lockLow = false;
43 Serial.println("Motion detected");
44 lcd.clear();
45 lcd.setCursor(0,0);
46 lcd.print("Check Motion");
47 lcd.setCursor(0,1);
48 lcd.print("Motion Detected");
49 delay(50);
50 }
51 takeLowTime = true;
52 }
53 if(digitalRead(pirPin) == LOW) {
54 if(takeLowTime){
55 lowIn = millis();
56 takeLowTime = false;
57 }
58 if(!lockLow && millis() - lowIn > pause) {
59 lockLow = true;
60 Serial.println("Motion ended");
61 lcd.clear();
62 lcd.setCursor(0,0);
63 lcd.print("Check Motion");
64 lcd.setCursor(0,1);
65 lcd.print("Motion Ended");
66 delay(50);
67 }
68 }
69}
70
rthanusha
8 months ago
Hello, may i know how to do this code in android studio?