Skip to content

Gayanukaa/ESP32-Medibox

Repository files navigation

ESP32 Medibox

This project, ESP32 Medibox, is a smart medicine box designed to assist individuals in managing their medication schedules effectively. The system utilizes an ESP32 microcontroller to control various components, including sensors, actuators, and communication modules, to provide a comprehensive solution for medication management.

Overview

license last-commit repo-top-language repo-language-count

Developed with the software and tools below.

VS Code C++ Node-RED Arduino Wokwi PlatformIO

Circuit Diagram

The complete circuit diagram and simulation can be found on Wokwi.

Table of Contents

Features

  • WiFi Connectivity: Connects to WiFi for remote monitoring and control via MQTT.
  • Temperature and Humidity Monitoring: Measures environmental conditions using the DHT22 sensor.
  • Light Intensity Measurement: Uses LDRs to detect ambient light intensity and adjust the servo motor accordingly.
  • Servo Motor Control: Adjusts the position of a shaded sliding window based on light intensity.
  • Buzzer Notifications: Provides audio alerts for scheduled medication times.
  • Button Interface: Includes buttons for user interaction, such as canceling alarms or confirming actions.
  • Customizable Settings: Adjustable minimum angle and control factor for servo motor via MQTT.

Components

  • ESP32: The main microcontroller used in this project.
  • DHT22: Temperature and humidity sensor.
  • LDRs: Light-dependent resistors for measuring light intensity.
  • Servo Motor: For adjusting the position of the shaded window.
  • Buzzer: For audio notifications.
  • Buttons: For user interaction.

How It Works

The ESP32 Medibox is designed to help users manage their medication by providing various features:

  1. Monitoring: Continuously monitors temperature, humidity, and light intensity.
  2. Notifications: Provides scheduled notifications through a buzzer to remind the user to take their medication.
  3. Remote Control: Allows remote monitoring and adjustment of settings via MQTT.

The system is flexible, allowing for the customization of parameters such as the servo motor's minimum angle and controlling factor.

Node-Red Flow

The Node-RED flow for this project is available in the node-red-flow.json file. You can import this flow into your Node-RED instance to interact with the ESP32 Medibox via MQTT.

Running Node-RED

To visualize and control your ESP32 project using Node-RED, follow these steps:

  1. Install Node-RED:

    • If Node.js is not installed on your machine, install it first.
    • Open a terminal and run the following command to install Node-RED:
      npm install -g --unsafe-perm node-red
  2. Start Node-RED:

    • Run the following command in your terminal to start Node-RED:
      node-red
    • Node-RED will start and can be accessed via a web browser at http://localhost:1880.
  3. Create and Deploy Flows:

    • Use the Node-RED interface to create flows that interact with your ESP32.
    • Deploy your flows and visualize data or control components from your web browser.

With Node-RED, you can create sophisticated dashboards and control mechanisms, enhancing the interactivity and functionality of your ESP32 project.

MQTT Topics

The following MQTT topics are used in this project:

  • MQTT-ON-OFF: To control the buzzer (ON/OFF).
  • MQTT-SCH-ON: To manage the schedule for buzzer notifications.
  • MQTT-TEMP: To receive temperature readings.
  • MQTT-LDR: To receive light intensity data.
  • MQTT-MIN-ANG: To set the minimum angle of the servo motor.
  • MQTT-CTRL-FAC: To set the controlling factor for the servo motor.
  • MQTT-DROP-DOWN: To select predefined settings for the servo motor.

Getting Started

To get started with the ESP32 Medibox:

  1. Clone the Repository: Clone this repository to your local machine using the following command:

    git clone https://github.com/Gayanukaa/ESP32-Medibox.git
  2. Open the Project: Navigate to the project directory:

    cd ESP32-Medibox
  3. Install Dependencies: Ensure you have the necessary libraries installed. If you are using the Arduino IDE, install the following libraries via the Library Manager:

    • WiFi
    • PubSubClient
    • DHTesp
    • ESP32Servo
    • ArduinoJson

    If you are using PlatformIO, the required libraries are specified in the platformio.ini file and will be installed automatically during the build process.

  4. Configure WiFi and MQTT: Modify the setupWifi() and setupMqtt() functions in the code to include your WiFi credentials and MQTT broker details.

  5. Upload the Code: Connect your ESP32 to your computer and upload the code using the Arduino IDE or PlatformIO.

Building

This is a PlatformIO project. To build it, install PlatformIO, and then run the following command:

pio run

This command compiles the code and prepares it for uploading to the ESP32.

Simulating

To simulate this project, install Wokwi for VS Code. Open the project directory in Visual Studio Code, then:

  1. Press F1 and select "Wokwi: Start Simulator".
  2. The simulation environment will launch within VS Code, and you can interact with the simulated components.
  3. To interact with the simulated HTTP server, open your web browser and navigate to http://localhost:8180.

Wokwi allows you to test the functionality of your project without needing the physical hardware, making it easier to debug and validate your code.

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit them: git commit -m 'Add some feature'
  4. Push to the branch: git push origin feature/your-feature-name
  5. Submit a pull request.

License

This project is licensed under the MIT License.

Contact

If you have any questions or suggestions, please feel free to reach out to us at gayanukaamarasuriya@gmail.com.