/*
PIR sensor tester
*/
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
int ledPin = 12; // choose the pin for the LED
int inputPin = 5; // 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
const char *ssid = "Wokwi-GUEST";
const char *password = "";
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
WiFi.begin(ssid, password);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Gerak Terdeteksi!");
// We only want to print on the output change, not state
pirState = HIGH;
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
HTTPClient http;
String url = "http://colortex.my.id/cek_lampu.php";
http.begin(client, url.c_str());
int httpCode = http.GET();
if (httpCode > 0) {
String response = http.getString();
int responseValue = response.toInt(); // Mengubah respons ke tipe data int
if (responseValue == 1) { // Membandingkan dengan nilai angka
delay(500);
}
}
}
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Gerak Berhenti!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}