Condiment Dispenser Control With Low Level Notification
Condiment Dispenser Control With Low Level Notification
//Initial coding by AI
#include <Arduino.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
const int sauceLevelThreshold = LOW; // Adjust the threshold based on your sensor
WiFiClientSecure client;
pinMode(cupSensorPin, INPUT);
pinMode(dispenserRelayPin, OUTPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
delay(1000);
Serial.println("Connecting to WiFi...");
Serial.println("Connected to WiFi");
Serial.begin(115200);
void loop() {
if (cupPresent == HIGH) {
if (sauceLevel == sauceLevelThreshold) {
activateDispenser();
} else {
deactivateDispenser();
} else {
void activateDispenser() {
void deactivateDispenser() {
}
Block Diagram
Communication via Telegram Set Up
1. Create a Telegram Bot:
Open the Telegram app on your mobile device or use the web version.
Start a chat with the BotFather and use the /newbot command to create a new bot.
Follow the instructions provided by the BotFather to choose a name and username
for your bot.
Once your bot is created, the BotFather will provide you with a unique API token.
Save this token; you will need it to authenticate your bot with Telegram.
You'll need to know the chat ID where you want to receive messages from your bot.
To do this, send a message to your bot using the Telegram app.
Then, visit the following URL in your web browser, replacing YOUR_BOT_TOKEN
with the token provided by BotFather:
https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates.
Look for the "chat" object in the JSON response; it contains your chat ID.
UniversalTelegramBot
WiFiClientSecure
Make sure you have your NodeMCU board ready with the necessary sensors and
connections (as discussed in your previous question).
Write or modify your Arduino code to include the Telegram bot functionality. You
can use the sample code provided in my previous responses as a starting point.
6. Configure Wi-Fi:
Ensure that your NodeMCU is connected to your Wi-Fi network. Update the ssid and
password variables in your code with your network's credentials.
Update the botToken variable in your code with the API token you received from
the BotFather.
Update the chatID variable in your code with the chat ID you obtained.
Verify your code in the Arduino IDE, and then upload it to your NodeMCU.
Open the Arduino IDE's Serial Monitor to view debug messages and ensure that your
NodeMCU is connecting to Wi-Fi and communicating with Telegram.
In your Telegram app, send a message to your bot. It should respond with the
notification you specified in your code when it detects low sauce levels and a cup
presence.
Test your automatic sauce dispenser system with the NodeMCU and sensors to
ensure it works as intended.
- Rosedi
15 Sep 2023