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

Arduino UNO Controlled Servo Dispenser with Ultrasonic Sensor and RTC

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Servo Dispenser with Ultrasonic Sensor and RTC

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a variety of components including an RTC DS3231 (Real-Time Clock), an I2C LCD 16x2 Screen, a buzzer, an HC-SR04 Ultrasonic Sensor, and a Servomotor SG90. The Arduino UNO serves as the central processing unit, controlling the servo based on distance measurements from the ultrasonic sensor and time from the RTC, displaying information on the LCD, and providing feedback through the buzzer.

Component List

Arduino UNO

RTC DS3231

I2C LCD 16x2 Screen

Buzzer

HC-SR04 Ultrasonic Sensor

Servomotor SG90

Wiring Details

Arduino UNO

RTC DS3231

I2C LCD 16x2 Screen

Buzzer

HC-SR04 Ultrasonic Sensor

Servomotor SG90

Documented Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Servo.h>

// Pin definitions
const int servoPin = 8;           // Pin connected to the servo motor
const int trigPin = 10;           // Pin connected to the trig pin of the ultrasonic sensor
const int echoPin = 11;           // Pin connected to the echo pin of the ultrasonic sensor
const int buzzerPin = 9;          // Pin connected to the passive buzzer

// Thresholds and intervals
const int distanceThreshold = 30; // Set distance threshold to 30 cm
const int movementThreshold = 5;  // Minimum change in distance to consider as movement
const long dispenseInterval = 10; // Interval for the servo to move in seconds

// Servo and sensor setup
Servo myServo;                    // Create a servo object
long previousDistance = 0;        // Variable to store the previous distance measurement
bool hasMoved = false;            // Flag to indicate if movement has been detected
int servoPosition = 0;            // Start servo at 0 degrees (original position)

// LCD and RTC setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the address and size to your LCD
RTC_DS3231 rtc;                    // Create an RTC object

// Buzzer timing variables
bool buzzerActive = false;
unsigned long buzzerStartTime = 0;
const unsigned long buzzerDuration = 2000; // 2 seconds for buzzing

void setup() {
  // Initial setup for serial communication, servo, pins, LCD, and RTC
  // ...
}

void loop() {
  // Main loop for checking distance, moving servo, and updating LCD
  // ...
}

// Function to activate the buzzer for 2 seconds
void activateBuzzer() {
  // ...
}

// Function to stop the buzzer
void stopBuzzer() {
  // ...
}

The provided code is a sketch for the Arduino UNO that interfaces with the connected components. It includes initialization of the servo, ultrasonic sensor, buzzer, LCD, and RTC. The main loop checks the distance measured by the ultrasonic sensor and moves the servo accordingly. It also updates the LCD with the current time or countdown until the next servo movement. The buzzer is activated at startup and when certain events occur, such as motion detection or countdown completion.