0% found this document useful (0 votes)
13 views7 pages

Condiment Dispenser Control With Low Level Notification

The document outlines the coding and setup process for a condiment dispenser control system that notifies users via Telegram when sauce levels are low. It includes details on hardware connections, Wi-Fi configuration, and Telegram bot integration, along with a step-by-step guide for installation and testing. The code utilizes Arduino libraries to manage sensor inputs and relay outputs for the dispenser functionality.

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

Condiment Dispenser Control With Low Level Notification

The document outlines the coding and setup process for a condiment dispenser control system that notifies users via Telegram when sauce levels are low. It includes details on hardware connections, Wi-Fi configuration, and Telegram bot integration, along with a step-by-step guide for installation and testing. The code utilizes Arduino libraries to manage sensor inputs and relay outputs for the dispenser functionality.

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

//Condiment Dispenser Control with Low Level Notification

//Initial coding by AI

//Modified by Rosedi 15 Sep 2023

#include <Arduino.h>

#include <WiFiClientSecure.h>

#include <UniversalTelegramBot.h>

// Define your Wi-Fi credentials

const char* ssid = "YourSSID";

const char* password = "YourPassword";

// Define your Telegram Bot Token and chat ID

const char* botToken = "YourBotToken";

const int chatID = YourChatID;

// Define pin for cup detection sensor

const int cupSensorPin = D1;

// Define pin for sauce level capacitive sensor

const int sauceLevelSensorPin = D2; // Connect to a digital GPIO pin

// Define pin for sauce dispenser relay control

const int dispenserRelayPin = D3; // Connect to a digital GPIO pin

// Define the sauce level threshold (customize this)

const int sauceLevelThreshold = LOW; // Adjust the threshold based on your sensor

// Initialize the Telegram bot

WiFiClientSecure client;

UniversalTelegramBot bot(botToken, client);


void setup() {

// Initialize hardware pins

pinMode(cupSensorPin, INPUT);

pinMode(sauceLevelSensorPin, INPUT_PULLUP); // Use INPUT_PULLUP to enable the internal pull-


up resistor

pinMode(dispenserRelayPin, OUTPUT);

// Connect to Wi-Fi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Connecting to WiFi...");

Serial.println("Connected to WiFi");

// Initialize Serial communication for debugging

Serial.begin(115200);

void loop() {

// Check for cup presence

int cupPresent = digitalRead(cupSensorPin);

if (cupPresent == HIGH) {

// Cup is present, check sauce level

int sauceLevel = digitalRead(sauceLevelSensorPin);

if (sauceLevel == sauceLevelThreshold) {

// Sauce is almost empty, send Telegram notification

sendTelegramMessage("Sauce container is almost empty!");


}

// Activate the sauce dispenser (relay)

activateDispenser();

} else {

// Cup is not present, deactivate the dispenser

deactivateDispenser();

delay(1000); // Adjust the delay to suit your application

void sendTelegramMessage(const String& message) {

Serial.println("Sending Telegram message...");

if (bot.sendMessage(chatID, message, "Markdown")) {

Serial.println("Message sent successfully");

} else {

Serial.println("Message delivery failed");

void activateDispenser() {

digitalWrite(dispenserRelayPin, HIGH); // Turn on the relay to activate the dispenser

void deactivateDispenser() {

digitalWrite(dispenserRelayPin, LOW); // Turn off the relay to deactivate the dispenser

}
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.

 Search for the "BotFather" bot.

 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.

2. Find Your Chat ID:

 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.

 Save your chat ID for later use.

3. Install the Required Libraries in Arduino IDE:

 Open the Arduino IDE.

 Go to "Sketch" -> "Include Library" -> "Manage Libraries..."

 Search for and install the following libraries:

 UniversalTelegramBot

 WiFiClientSecure

4. Prepare Your NodeMCU:

 Make sure you have your NodeMCU board ready with the necessary sensors and
connections (as discussed in your previous question).

5. Write the Arduino Code:

 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.

7. Set Up the Telegram Bot in Your Code:

 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.

8. Compile and Upload Code:

 Verify your code in the Arduino IDE, and then upload it to your NodeMCU.

9. Monitor Serial Output:

 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.

10. Test Your Bot:

 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.

11. Operate Your Automatic Sauce Dispenser:

 Test your automatic sauce dispenser system with the NodeMCU and sensors to
ensure it works as intended.

- Rosedi
15 Sep 2023

You might also like