Arduino-Controlled Medication Reminder System with GSM Alert and Weight Sensing
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a medication reminder system with three compartments, each operated by a DC motor. The second compartment is equipped with a weight sensor to detect if medication has been taken. If the medication is not taken, the system will trigger an alert call using a GSM module. The first and third compartments operate without weight detection. The system also includes an RTC module for timekeeping and a DFPlayer Mini for voice messages. An Arduino UNO serves as the microcontroller to manage the logic and control signals for the entire system.
Component List
DC Motor
- Description: A standard DC motor used for mechanical movements.
- Purpose: To actuate the compartments of the medication reminder system.
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: To control the logic and timings of the medication reminder system.
HX711 - Bridge Sensor Interface
- Description: A precision 24-bit analog-to-digital converter (ADC) designed for weigh scales and industrial control applications.
- Purpose: To interface with the load cell for weight measurement.
Load Cell - Red/white/black/green
- Description: A transducer that converts force into an electrical signal.
- Purpose: To detect the weight of medication in the second compartment.
DFPlayer MINI
- Description: A small and low-cost MP3 module with a simplified output directly to the speaker.
- Purpose: To provide voice messages for the medication reminder system.
L298N DC motor driver
- Description: A dual H-bridge motor driver capable of driving a pair of DC motors or a stepper motor.
- Purpose: To control the direction and speed of the DC motors.
RTC MODULE
- Description: A real-time clock module to keep track of the current time and date.
- Purpose: To provide time-based triggers for the medication reminder system.
SIM800L GSM Module
- Description: A complete Quad-band GSM/GPRS solution in an SMT type, allowing you to benefit from small dimensions and cost-effective solutions.
- Purpose: To make alert calls or send SMS when medication is not taken.
12v Power Supply
- Description: A power supply module that provides a 12V output.
- Purpose: To power the motor drivers and the Arduino UNO.
Wiring Details
DC Motor
- Motor 1: Connected to
OUT1andOUT2on the first L298N motor driver. - Motor 2: Connected to
OUT3andOUT4on the second L298N motor driver. - Motor 3: Connected to
OUT1andOUT2on the second L298N motor driver.
Arduino UNO
5VandGNDpins are used to power the SIM800L GSM Module, RTC MODULE, and DFPlayer MINI.Vinis connected to the 12V power supply.A4(SDA) andA5(SCL) are connected to the RTC MODULE for I2C communication.- Digital pins
D13andD12are connected to the SIM800L GSM Module for serial communication. - Digital pins
D11,D10,D9,D8,D7,D6,D5,D4, andD3are connected to the L298N motor drivers for motor control signals. GNDis also connected to the 12v power supply's-terminal.
HX711 - Bridge Sensor Interface
E+,E-,A-,A+are connected to the corresponding pins on the Load Cell.
L298N DC Motor Driver
12VandGNDare connected to the 12v power supply.- Control pins
ENA,IN1,IN2,IN3,IN4, andENBare connected to the corresponding control pins on the Arduino UNO.
RTC MODULE
VCCandGNDare powered by the Arduino UNO.SDAandSCLare connected to the Arduino UNO for I2C communication.
SIM800L GSM Module
VDDandGNDare powered by the Arduino UNO.SIM_TXDandSIM_RXDare connected to the Arduino UNO for serial communication.
DFPlayer MINI
VCCandGNDare powered by the Arduino UNO.RXandTXare connected to the Arduino UNO for serial communication.
12v Power Supply
+is connected to the12Vinput on the L298N motor drivers andVinon the Arduino UNO.-is connected to theGNDon the Arduino UNO.
Documented Code
/*
* Medication Reminder System
* This Arduino sketch controls a medication reminder system with three
* compartments, each operated by a DC motor. The second compartment is
* monitored by a weight sensor to detect if medication has been taken. If
* not, the system will trigger an alert call using a GSM module. The first
* and third compartments will only open and close without triggering any
* alert.
*/
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Wire.h>
#include <RTClib.h>
// Define motor control pins
#define motor1PWM 3 // PWM pin to control speed of motor 1 (First compartment)
#define motor1In1 4 // IN1 pin of motor driver for motor 1
#define motor1In2 5 // IN2 pin of motor driver for motor 1
#define motor2PWM 6 // PWM pin to control speed of motor 2 (Second compartment)
#define motor2In1 7 // IN1 pin of motor driver for motor 2
#define motor2In2 8 // IN2 pin of motor driver for motor 2
#define motor3PWM 9 // PWM pin to control speed of motor 3 (Third compartment)
#define motor3In1 10 // IN1 pin of motor driver for motor 3
#define motor3In2 11 // IN2 pin of motor driver for motor 3
// RTC module for timekeeping
RTC_DS3231 rtc;
// GSM module for making calls or sending SMS
SoftwareSerial mySerial(12, 13); // RX, TX for GSM
// Single weight sensor for the second compartment
#define weightSensorPin A0
float weightThreshold = 2.0; // Adjust this based on your sensor and medicine weight
void setup() {
// Set motor control pins as outputs
pinMode(motor1PWM, OUTPUT);
pinMode(motor1In1, OUTPUT);
pinMode(motor1In2, OUTPUT);
pinMode(motor2PWM, OUTPUT);
pinMode(motor2In1, OUTPUT);
pinMode(motor2In2, OUTPUT);
pinMode(motor3PWM, OUTPUT);
pinMode(motor3In1, OUTPUT);
pinMode(motor3In2, OUTPUT);
// Initialize the GSM module and other serial communications
mySerial.begin(9600);
Serial.begin(9600);
// Initialize the DFPlayer Mini MP3 module (for voice messages)
mp3_set_serial(Serial);
mp3_set_volume(20); // Adjust volume as needed
// Initialize the RTC module
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
}
void loop() {
DateTime now = rtc.now();
// First compartment (no weight detection, just open and close)
if (now.hour() == 8 && now.minute() == 0) {
openAndCloseCompartment(motor1PWM, motor1In1, motor1In2);
}
// Second compartment (with weight detection)
else if (now.hour() == 12 && now.minute() == 0) {
handleSecondCompartment();
}
// Third compartment (no weight detection, just open and close)
else if (now.hour() == 18 && now.minute() == 0) {
openAndCloseCompartment(motor3PWM, motor3In1, motor3In2);
}
// Add a small delay to prevent looping too quickly
delay(60000); // Delay 1 minute before the next loop
}
// Function to control motors for compartments without weight detection
void openAndCloseCompartment(int motorPWM, int motorIn1, int motorIn2) {
// Open the compartment (rotate motor forward)
digitalWrite(motorIn1, HIGH);
digitalWrite(motorIn2, LOW);
analogWrite(motorPWM, 150); // Decrease motor speed by lowering PWM value (0-255)
delay(5000); // Run motor for 5 seconds to open the compartment
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, LOW);
delay(7000); // Wait for 7 seconds
// Close the compartment (rotate motor backward)
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, HIGH);
analogWrite(motorPWM, 150); // Maintain same speed for