#include "thingProperties.h"
#include <Arduino.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
HTTPClient client;
#define Buzzer 4
const int DIR = 12;
const int STEP = 14;
const int PIR_PIN = 35; // Change this to the actual pin number connected to your PIR sensor
const int step_per_rev = 1000;
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);
// Wait for connection
while(WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("Hello Buzz!");
pinMode(Buzzer, OUTPUT);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(PIR_PIN, INPUT);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
if (digitalRead(PIR_PIN) == HIGH) {
// PIR sensor is HIGH (motion detected)
digitalWrite(DIR, HIGH);
Serial.println("Motion detected! Working continuously...");
// Continue rotating the stepper motor
while (digitalRead(PIR_PIN) == HIGH) {
digitalWrite(STEP, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
}
// Stepper motor stopped due to no motion
Serial.println("Motion stopped. Stepper motor turned off for 10 seconds.");
// Add a delay to keep the motor off for 10 seconds (adjust as needed)
delay(10000);
} else {
// PIR sensor is LOW (no motion)
digitalWrite(STEP,HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
delay(1000);
// digitalWrite(Buzzer, HIGH);
// delay(1000);
// digitalWrite(Buzzer, LOW);
if(tt>30)
{
digitalWrite(Buzzer, HIGH);
Serial.println("puzer active");
//delay(1000);
}
else
digitalWrite(Buzzer, LOW);
}
void onMotionChange() {
// Add your code here to act upon Motion change
}
void onPuzerChange(){
// Add your code here to act upon Puzer change
}
void onMotorChange(){
// Add your code here to act upon Motor change
}
void onTtChange() {
// Add your code here to act upon Tt change
}