Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to program an IoT-based coffee machine

By EG Projects May 18, 2021

Looking forward to a ready-made morning (or afternoon) cup of coffee? It’s possible to ensure the ideal cup at the ideal time is ready and waiting for you. This is thanks to an automated system that uses the Internet of things (IoT).

In this tutorial, we’ll develop an IoT-based coffee machine that operates at a set time without human interaction. It will also send notifications — such as when the cup is ready for you — via a desktop dashboard.

The Network Time Protocol (NTP) server will track the real-time, using “hours:minutes:seconds,” which it relays to the system. The system will also be pre-programmed for a set (desired) time. When the real and desired time match, the system sends an “ON” command to the coffee machine using a WiFi chip.

This alerts the coffee machine to work its magic, which will automatically turn “OFF” after a pre-set time to save power. A notification will be sent to your desktop that “Your coffee has been made” when it’s ready.

This covers the basics of how you can enjoy a ready-made coffee, with the ability to change the desired time to suit your preference. Now, let’s review the required components and the technology behind the system.

Components
Here’s what you’ll need to get started…

Dependencies:

  • Operating system: Windows / Linux / MacOSx
  • Programming languages: Python 2.7
  • Communication medium: WiFi

Technology:

  • MQTT protocol: message queue telemetry transportation or MQTT is a lightweight protocol for message transmission via the Internet. It works as a client-server architecture. The server is called “broker” and the clients are “clients.”
  • NTP server: used to sync the system clocks of the devices that are connected to the Internet with the coordinated universal time (UTC).
  • Wi-Fi module – ESP8266: the size of a small chip, this module can connect to any WiFi router and provide the Internet to devices that are not otherwise connected. We will use this to connect the IoT board with a broker on the Internet.

Block diagram

– The coffee machine is connected with a relay circuitry that switches it ON/OFF.

– The relay is controlled by the IoT board (the Atmega 328P controller)

– The board is connected to the Internet via the in-built ESP module.

– The board “communicates” with the MQTT broker (HiveMQ) online, and receives and sends MQTT-based messages.

– A computer desktop uses Python script for sending and receiving messages on the MQTT to the broker, which is connected to the coffee machine.

How it works?
A Linux/Windows-based machine runs the Python script. The script runs in a main loop where it compares the real-time, which is stored in a string, with a desired time. The desired time is written into the script and stored in a string using an “If” condition.

When the real-time matches the desired time string, a function call sends an “ON” signal to the coffee machine — which is connected to the Internet — over the MQTT. When it receives the “ON” command, it automatically turns the relay “ON” to make the coffee.

A time period is also set in the system, after which the coffee machine will turn “OFF.”

The circuit

The code
This project is divided into two parts:

1. The device that’s controlled (the coffee machine)
2. The main computer system, which stores the desired timing of the coffee and signals the machine to turn ON/OFF.

The IoT board code
This code is written and compiled in Arduino IDE. It also has two parts. One is for controlling the device and it uses an ATmega328 microcontroller. The other is for communication via the Internet and it uses the ESP8266 module.

Microcontroller’s control code
The microcontroller is programmed to receive strings on the universal asynchronous receiver/transmitter (UART) port from the ESP module. If the string’s command is “ON” or “OFF,” it switches the GPIO to HIGH or to LOW, respectively.

if(command == “machine/on”){
    digitalWrite(coffee_machine_connected_pin,HIGH);
    Serial.print(“offee machine is on”);
  }

The board also sends the response through the UART to the ESP. Both are programmed so that any message sent on the serial will be published to the MQTT broker.

ESP module code
The ESP is programmed to connect to WiFi using a WiFi manager library, which creates a hotspot when needed. Then, using an HTML page, it’s possible to configure the ESP with SSID and PASS.

wifiManager.autoConnect(“AutoConnectAP”);

Any message received by the ESP on the serial will be published to the MQTT broker. Also, anything the ESP receives from the MQTT broker will be sent to the serial port.

The code is like a network adapter framework.

if (Serial.available()) {
    String recivedData = Serial.readString();
    temp_str = recivedData;
    char temp[temp_str.length() + 2];
    temp_str.toCharArray(temp, temp_str.length() + 1);
    client.publish(topicPublish, temp);
  }

The code for sending data that’s received from the broker to the serial.

for (int i = 0; i < length; i++) {

    data_r_in_string  =  String(data_r_in_string + (char)payload[i]);
    //Serial.print((char)payload[i]);
  }
  Serial.print(data_r_in_string);

The Python script
First, it’s necessary to make a file named “timings.py” in which all of the variables are declared so that it’s easy to change the desired timing for the coffee.

#timings = hh:mm:ss
morning_coffee = “08:00:00”
afternoon_coffee = “12:00:00”
evening_coffee = “17:06:10”

The script named “system.py” imports all the timing from the “timing.py” file.

from timing import *

Then, it’s important to import the libraries required for communication with the MQTT broker.

import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish

Next, assign two variables with MQTT topics — one to send messages and the other to receive messages.

subscription_topic = “ts/coffee/report”
publish_topic = “ts/coffee/machine”

Now, declare a variable named “client” with the “mqtt client.”

client = mqtt.Client()

Make two function callbacks:

1. For receiving messages
2. For doing something based on a successful connection

client.on_connect = on_connect
client.on_message = on_message

Finally, connect the MQTT broker on a port, and start the “client” inside a non-blocking loop.

client.connect(“broker.hivemq.com”, 1883, 60)
client.loop_start()

After the connection is successful, we can send messages using this:

publish.single(topic, message_data, hostname=”broker.hivemq.com”)

Now it’s possible to create the loop, which will include the current time in a string variable.

current_time = time.strftime(“%H:%M:%S”)

Inside the loop, compare the current system time with all of the previous variables.

if(morning_coffee == current_time):
               print morning_coffee
send_signals(“machine/on”)
               Machine = “ON”

When the condition is matched, a signal is sent that turns the machine “ON.” After the coffee machine is turned “ON,” it must shut “OFF” after a specific time. For this, another loop is required that only starts after the machine is turned “ON.”

while(Machine==”ON”):
if(second > time_for_which_machine_will_be_on_s):
               send_signals(“machine/off”)
               Machine = “OFF”
               second = 0
               print “Machine is OFF”

This is how the system works for programming an IoT-based coffee machine.

 

You may also like:


  • What are the top development boards for AI and ML?

  • What are LoRa gateways and what types are available?

  • How does LoRa modulation enable long-range communication?

  • What is the role of embedded software in electric vehicles?

  • What are the top tools for developing embedded software?
  • battery selection low power design
    What are the battery-selection criteria for low-power design?

Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Exporting sensor readings as data...
  • Inconsistent Charge Termination Voltage with battery charger
  • 21V keeps getting shorted to my UART line.
  • Voltage mode pushpull is a nonsense SMPS?
  • Voltage mode push pull with extra DC blocking capacitor

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Why can't I breadboard this oscillator?
  • using a RTC in SF basic
  • Parts required for a personal project
  • Cataract Lens Options?

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • GigaDevice launches GD32C231 MCU series with 48MHz Cortex-M23 core and 64KB Flash
  • Advanced Energy releases 425 W CF-rated medical power supply in 3.5 x 6 x 1.5-inch format”
  • LEM combines shunt and Hall effect sensing in 2000 A current measurement unit
  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe