For context, I'm making an automated drying rug that rotates to another rug along a roller when its wet or a certain amount of people has walked past the IR sensors, then it would also send a telegram message to the cleaner to replace the rug for a cleaner one.
The servos (signifying a gate opening to deter people from using the rug) wont turn at all
The moisture sensor isnt updating on the phone arduino cloud app
The IR sensor data seems to not be adding up on the phone app too
Appreciate the assistance and thank you for your time, kind tinkerers.
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudSwitch carpetOverride;
int carpetWet;
int numberPeople;
bool carpetReplace;
bool carpetStatus;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
include "thingProperties.h"
include <ESP32Servo.h>
include <HTTPClient.h>
include <WiFi.h>
Servo myservo;
define greenpin 35
define redpin 33
define buzzpin 32
define irpin1 21
define irpin2 19
define moistpin 23
define servopin 15
define motorinput1 14
define motorinput2 12
define dryerinput3 27
define dryerinput4 26
unsigned long lastActivationTime = 0;
const int timeInterval = 3000; // Time interval in milliseconds
void setup()
{
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
myservo.attach(servopin);
pinMode(greenpin, OUTPUT);
pinMode(redpin, OUTPUT);
pinMode(buzzpin, OUTPUT);
pinMode(irpin1, INPUT);
pinMode(irpin2, INPUT);
pinMode(moistpin, INPUT);
pinMode(servopin, OUTPUT);
pinMode(motorinput1, OUTPUT);
pinMode(motorinput2, OUTPUT);
pinMode(dryerinput3, OUTPUT);
pinMode(dryerinput4, OUTPUT);
// Initial setup
digitalWrite(greenpin, HIGH);
digitalWrite(redpin, LOW);
carpetStatus = false;
}
void loop()
{
ArduinoCloud.update();
digitalWrite(greenpin, HIGH);
digitalWrite(redpin, LOW);
int people_count = 0;
// Only count people that are coming in
if (irpin1 == LOW)
{
lastActivationTime = millis();
}
if (irpin2 == LOW && millis() - lastActivationTime <= timeInterval)
{
people_count = people_count + 1;
numberPeople = people_count;
}
if(people_count > 5) //Reset the amount of people when it reaches the maximum number
{
people_count = 0;
carpetReplace = true;
sendTelegramMessage("Carpet need to be replaced! ");
}
numberPeople = people_count;
int carpetHumidLevel = analogRead(moistpin);
Serial.println(carpetHumidLevel);
carpetWet = carpetHumidLevel;
if(carpetHumidLevel > 300)
{
carpetcleaning();
}
}
void sendTelegramMessage(String message)
{
if (WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
String url = "https://api.telegram.org/bot" + botToken + "/sendMessage?chat_id=" + chatID + "&text=" + message;
http.begin(url);
int httpResponseCode = http.GET();
if(httpResponseCode > 0)
{
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
}
else
{
Serial.print("Error on sending post: ");
Serial.println(httpResponseCode);
}
http.end();
}
}
void carpetcleaning()
{
carpetStatus = true;
ArduinoCloud.update();
digitalWrite(greenpin, LOW); // Red LED lights up
digitalWrite(redpin, HIGH);
tone(buzzpin, 1000);
delay(1000);
tone(buzzpin, 0);
myservo.write(90); // Close the gate
delay(2000);
digitalWrite(motorinput1, LOW); // Carpet start rotating
digitalWrite(motorinput2, HIGH);
tone(buzzpin, 1000);
delay(1000);
tone(buzzpin, 0);
delay(10000); // Adjust time for carpet to fully flipped
digitalWrite(motorinput1, LOW); // Carpet stop rotating
digitalWrite(motorinput2, LOW);
tone(buzzpin, 1000);
delay(1000);
tone(buzzpin, 0);
digitalWrite(dryerinput3, LOW); // Dryer is on
digitalWrite(dryerinput4, HIGH);
delay(7000);
digitalWrite(dryerinput3, LOW); // Dryer is off
digitalWrite(dryerinput4, LOW);
tone(buzzpin, 1000);
delay(1000);
tone(buzzpin, 0);
carpetStatus = false;
ArduinoCloud.update();
delay(2000);
digitalWrite(greenpin, HIGH); // Green LED lights up
digitalWrite(redpin, LOW);
tone(buzzpin, 1000);
delay(1000);
tone(buzzpin, 0);
myservo.write(0); // Open the gate
}
void onCarpetOverrideChange()
{
if(carpetOverride)
{
carpetcleaning();
carpetOverride = false;
}
ArduinoCloud.update();
}
void onNumberPeopleChange()
{
// Add your code here to act upon NumberPeople change
}
void onCarpetStatusChange()
{
// Add your code here to act upon CarpetStatus change
}
void onCarpetReplaceChange() {
// Add your code here to act upon CarpetReplace change
}
/*
Since CarpetWet is READ_WRITE variable, onCarpetWetChange() is
executed every time a new value is received from IoT Cloud.
*/
void onCarpetWetChange() {
// Add your code here to act upon CarpetWet change
}
*edited out bot token and chat id