Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Medication Reminder System with GSM Alert and Weight Sensing

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Medication Reminder System with GSM Alert and Weight Sensing

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

Arduino UNO

HX711 - Bridge Sensor Interface

Load Cell - Red/white/black/green

DFPlayer MINI

L298N DC motor driver

RTC MODULE

SIM800L GSM Module

12v Power Supply

Wiring Details

DC Motor

Arduino UNO

HX711 - Bridge Sensor Interface

L298N DC Motor Driver

RTC MODULE

SIM800L GSM Module

DFPlayer MINI

12v Power Supply

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