Hello everyone!
I am a complete newbie and know NOTHING about coding/programing. This has been many trials and error. The reason I start this is because my cat uses the toilet and likes to use a fresh clean bowl. I have gotten it setup to my internet so when I am not at home, I can flush it remotely. Just... in the mornings well... let's just say I don't get to it in time.
I have a ESP8266 ESP-12E board.
I currently bought both AM312 Mini Detector Module HC-SR312 and HC-SR501 Pir Motion IR Sensor Body Module Infrared for Arduino as I was not sure which would work. Any advice?
Also, I am not sure how to program the code of the PIR sensor to the one that I currently have. If you have any advice that would be lovely. I appreciate all the help as I am now pulling my hair out due to frustration.
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ESP32
#include <WiFi.h>
#endif
#include "SinricPro.h"
#include "SinricProSwitch.h"
#include <Servo.h>
Servo toiletServo;
#define WIFI_SSID "WIFI Info"
#define WIFI_PASS "PASSWORD"
#define APP_KEY "APPKEY INFO"
#define APP_SECRET "APPSECRET"
#define SWITCH_ID_1 "ID"
#define BAUD_RATE 9600
int pos = 0;
int servoPin = D1;
bool onPowerState1(const String &deviceId, bool &state) {
Serial.printf("Device 1 turned %s\r\n", state ? "on" : "off");
toiletServo.attach(servoPin);
for (pos = 0; pos <= 180; pos += 1) {
toiletServo.write(pos);
delay(15);
}
delay(1000);
for (pos = 180; pos >= 0; pos -= 1) {
toiletServo.write(pos);
delay(15);
}
delay(1000);
return true; // request handled properly
}
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}
void setupSinricPro() {
SinricProSwitch& mySwitch1 = SinricPro[SWITCH_ID_1];
mySwitch1.onPowerState(onPowerState1);
SinricPro.onConnected([]() { Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([]() { Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(BAUD_RATE);
Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
}
type or paste code here
