

This circuit is designed to control a 12V geared motor and a blue LED using an Arduino UNO microcontroller based on input from a sound sensor and a limit switch. The motor's direction is controlled by an L298N DC motor driver, and the LED is switched on and off using a 1-channel 5V relay module. The system also includes a 12V power supply to power the motor and the LED. An I2C LCD screen is used to display the system status.
5V to Relay Module VCC+, Sound Sensor VCCGND to Limit Switch NO, Relay Module VCC- (GND), COM, I2C LCD Screen GND, Sound Sensor GND, L298N Motor Driver GNDVin to 12V Power Supply +, 12V Blue LED VCC, L298N Motor Driver 12VA4 to I2C LCD Screen SDAA5 to I2C LCD Screen SCLD10 to L298N Motor Driver ENAD6 to Limit Switch CD5 to L298N Motor Driver IN2D4 to L298N Motor Driver IN1D3 to Relay Module IND2 to Sound Sensor DigitalTerminal 1 to L298N Motor Driver OUT1Terminal 2 to L298N Motor Driver OUT2- to Arduino UNO GNDGND to Relay Module N.O.GND to Arduino UNO GND12V to Arduino UNO VinENA to Arduino UNO D10IN1 to Arduino UNO D4IN2 to Arduino UNO D5OUT1 to 12V Geared Motor Terminal 1OUT2 to 12V Geared Motor Terminal 2VCC to Arduino UNO 5VGND to Arduino UNO GNDDigital to Arduino UNO D2VCC+ to Arduino UNO 5VVCC- (GND) to Arduino UNO GNDIN to Arduino UNO D3COM to Arduino UNO GNDN.O. to 12V Blue LED GNDC to Arduino UNO D6NO to Arduino UNO GNDSDA to Arduino UNO A4SCL to Arduino UNO A5GND to Arduino UNO GND#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Pin Definitions
const int soundSensorPin = 2; // Digital pin for sound sensor
const int relayPin = 3; // Digital pin for relay (LED)
const int motorForwardPin = 4; // Motor driver forward control pin
const int motorBackwardPin = 5; // Motor driver backward control pin
const int limitSwitchPin = 6; // Limit switch pin
// LCD Setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address as necessary
// State Variables
bool drawerOpen = false;
void setup() {
// Initialize pins
pinMode(soundSensorPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(motorForwardPin, OUTPUT);
pinMode(motorBackwardPin, OUTPUT);
pinMode(limitSwitchPin, INPUT_PULLUP); // Use internal pull-up resistor
// Initialize LCD
lcd.begin();
lcd.backlight();
lcd.print("Ready to Clap");
}
void loop() {
// Check for clap
if (digitalRead(soundSensorPin) == HIGH) {
delay(200); // Debounce delay for sound sensor
if (!drawerOpen) {
openDrawer();
} else {
closeDrawer();
}
// Wait until clap is no longer detected
while (digitalRead(soundSensorPin) == HIGH) {
delay(50);
}
}
}
void openDrawer() {
digitalWrite(relayPin, HIGH); // Turn on LED
lcd.clear();
lcd.print("Opening Drawer");
digitalWrite(motorForwardPin, HIGH); // Move motor forward
// Run motor until limit switch is pressed
while (digitalRead(limitSwitchPin) == HIGH) {
delay(50); // Debounce limit switch
}
digitalWrite(motorForwardPin, LOW); // Stop motor
drawerOpen = true;
lcd.clear();
lcd.print("Drawer Open");
delay(1000); // Pause to display message
lcd.clear();
lcd.print("Ready to Clap");
}
void closeDrawer() {
digitalWrite(relayPin, LOW); // Turn off LED
lcd.clear();
lcd.print("Closing Drawer");
digitalWrite(motorBackwardPin, HIGH); // Move motor backward
// Run motor until limit switch is released
while (digitalRead(limitSwitchPin) == LOW) {
delay(50); // Debounce limit switch
}
digitalWrite(motorBackwardPin, LOW); // Stop motor
drawerOpen = false;
lcd.clear();
lcd.print("Drawer Closed");
delay(1000); // Pause to display message
lcd.clear();
lcd.print("Ready to Clap");
}
This code is designed to run on the Arduino UNO and controls the motor, LED, and LCD based on input from the sound sensor and limit switch. When a clap is detected by the sound sensor, the system will either open or close a drawer, indicated by the motor's movement and the LED's state. The LCD provides feedback on the system's status.