0% found this document useful (0 votes)
3 views

Condiment Dispenser Control with Low Level Notification 2

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Condiment Dispenser Control with Low Level Notification 2

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CONDIMENT DISPENSER CONTROL WITH ALERT NOTIFICATION VIA TELEGRAM

Hardware Connections

1. NodeMCU V3:

 Connect the NodeMCU V3 to your computer for programming.

2. Infrared Sensor for Cup Presence:

 Connect the VCC pin to a 3.3V output on NodeMCU (e.g., 3V3 or VIN).

 Connect the GND pin to a ground (GND) pin on NodeMCU.

 Connect the OUT pin to cupSensorPin (e.g., D1).

3. Infrared Sensor for Chili Sauce Level:

 Connect the VCC pin to a 3.3V output on NodeMCU (e.g., 3V3 or VIN).

 Connect the GND pin to a ground (GND) pin on NodeMCU.

 Connect the OUT pin to sauceLevelSensorPin (e.g., D2).

4. DC Motor and Relay:

 Connect one terminal of the DC motor to one of the relay's common (COM)
terminals.

 Connect the other terminal of the DC motor to one of the relay's normally open (NO)
terminals.

 Connect the relay's coil terminals (usually labeled as Coil+ and Coil-) to an
appropriate power source. This may vary based on the relay's voltage and type.

 Connect the relay's control pin (relayPin) to one of the digital pins on NodeMCU
(e.g., D3).

5. Power Supply:

 Provide power to NodeMCU through its micro USB port or an external power source,
depending on your setup.

6. Wi-Fi Module (not shown):

 Ensure the NodeMCU has a stable Wi-Fi connection for sending Telegram messages.
You may need to connect it to your Wi-Fi router using the appropriate credentials.

Rosedi 29/9/23
Coding

#include <Wire.h>

#include <Adafruit_MotorShield.h>

#include <WiFi.h>

#include <UniversalTelegramBot.h>

// Define your Wi-Fi credentials

const char* ssid = "Your_SSID";

const char* password = "Your_PASSWORD";

// Telegram Bot Token (get this from BotFather)

#define BOT_TOKEN "YOUR_BOT_TOKEN"

// Telegram Chat ID (get this by messaging the Bot directly and checking the updates)

#define CHAT_ID "YOUR_CHAT_ID"

// Define your infrared sensor pins

const int cupSensorPin = 5; // GPIO5 for cup presence sensor (D1)

const int sauceLevelSensorPin = 4; // GPIO4 for sauce level sensor (D2)

// Define your relay control pin

const int relayPin = 0; // GPIO0 for controlling the relay (D3)

// Initialize motor and relay

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *motor = AFMS.getMotor(1); // Motor connected to M1

void setup() {

// Initialize Serial for debugging

Serial.begin(115200);
// Connect to Wi-Fi

connectToWiFi();

// Initialize relay and motor

AFMS.begin();

pinMode(relayPin, OUTPUT);

digitalWrite(relayPin, LOW); // Turn off the relay initially

// Initialize infrared sensors

pinMode(cupSensorPin, INPUT);

pinMode(sauceLevelSensorPin, INPUT);

void loop() {

// Check for cup presence

if (digitalRead(cupSensorPin) == HIGH) {

// Cup is present, turn on the relay to activate the motor

digitalWrite(relayPin, HIGH);

} else {

// Cup is not present, turn off the relay to deactivate the motor

digitalWrite(relayPin, LOW);

// Check for chili sauce level

if (digitalRead(sauceLevelSensorPin) == LOW) {

// Chili sauce level is empty, send a notification

sendTelegramMessage("Chili sauce level is empty!");

delay(5000); // Avoid sending repeated notifications

}
// Add any additional logic or sensors as needed

void connectToWiFi() {

// 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");

void sendTelegramMessage(String message) {

// Initialize Telegram bot with WiFiClient

WiFiClient client;

UniversalTelegramBot bot(BOT_TOKEN, client);

// Send the message to the specified chat ID

bot.sendMessage(CHAT_ID, message, "Markdown");

You might also like