/*
Ember Mug 4
This sketch controls the Ember Mug 4, which maintains the ideal temperature
for beverages using an ESP32. It features a DHT22 temperature sensor, a relay
module to control the heater, a LED bar graph to indicate the desired temperature,
a seven-segment display to show the current temperature, and tactile buttons
to adjust the ideal temperature.
The circuit:
* DHT22 sensor connected to pin 15
* Relay module connected to pin 4
* LED bar graph connected to pins 2, 4, 5, 18, 19, 21, 22, 23
* Seven segment display connected to pins 12, 13, 14, 27, 32, 33, 25
* Ultrasonic sensor connected to pins 5 (trigger) and 18 (echo)
* Push buttons connected to pins 19 (increase) and 21 (decrease)
* LED indicator connected to pin 23
Created 27 November 2024
By Claudio Moreno
*/
#include <Arduino.h>
#include "Device.h"
#include "DHTSensor.h"
#include "LedBarGraph.h"
#include "RelayController.h"
#include "UltrasonicSensor.h"
#include "SevenSegmentDisplay.h"
#include "CommunicationManager.h"
// WiFi Configuration
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
// Pin definitions
#define DHT_PIN 15
#define LED_BAR_PINS {2, 4, 5, 18, 19, 21, 22, 23}
#define RELAY_PIN 4
#define ULTRASONIC_TRIG_PIN 5
#define ULTRASONIC_ECHO_PIN 18
#define SEVEN_SEGMENT_PINS {12, 13, 14, 27, 32, 33, 25}
#define BUTTON_INCREASE_PIN 19 // Pin for the increase button
#define BUTTON_DECREASE_PIN 21 // Pin for the decrease button
int ledBarPins[] = LED_BAR_PINS;
int sevenSegmentPins[] = SEVEN_SEGMENT_PINS;
DHTSensor dhtSensor(DHT_PIN);
LedBarGraph ledBarGraph(ledBarPins, sizeof(ledBarPins) / sizeof(ledBarPins[0]));
RelayController relayController(RELAY_PIN);
UltrasonicSensor ultrasonicSensor(ULTRASONIC_TRIG_PIN, ULTRASONIC_ECHO_PIN);
SevenSegmentDisplay sevenSegmentDisplay(sevenSegmentPins, sizeof(sevenSegmentPins) / sizeof(sevenSegmentPins[0])); // Pass size
CommunicationManager commManager;
Device device(dhtSensor, ledBarGraph, relayController, ultrasonicSensor, sevenSegmentDisplay, commManager);
void setup() {
Serial.begin(115200);
// Display company information
Serial.println("Ember, Inc.");
Serial.println("Developers: Claudio Jesús Moreno Rosales");
device.begin();
// Initialize buttons
pinMode(BUTTON_INCREASE_PIN, INPUT_PULLUP);
pinMode(BUTTON_DECREASE_PIN, INPUT_PULLUP);
}
void loop() {
// Check button states
if (digitalRead(BUTTON_INCREASE_PIN) == LOW) {
device.increaseIdealTemperature();
delay(200);
}
if (digitalRead(BUTTON_DECREASE_PIN) == LOW) {
device.decreaseIdealTemperature();
delay(200);
}
device.update();
delay(100);
}