This circuit is designed to control a motor using an Arduino UNO microcontroller in conjunction with a L298N Motor Driver. The system's operation is influenced by the state of a rocker switch and two capacitive proximity sensors. An LCD display is included for user interface or status display purposes. The power supply is managed through a 12V 5A power supply unit, which is connected to a secondary power supply module and controlled by a rocker switch. The circuit is designed to respond to the proximity sensors and control the direction of the motor accordingly.
5V
to LCD Display 16x4 I2C VCC
A4
to LCD Display 16x4 I2C SDA
A5
to LCD Display 16x4 I2C SCL
GND
to LCD Display 16x4 I2C GND
VCC
to Arduino UNO 5V
SDA
to Arduino UNO A4
SCL
to Arduino UNO A5
GND
to Arduino UNO GND
+
to POWER SUPPLY 12V 5AMP 220V Positive Pole (AC)
-
to POWER SUPPLY 12V 5AMP 220V Negative Pole (AC)
+12v Power
to Rocker Switch (SPST) 2
// Pin definitions
const int rockerSwitchPin = 5; // Pin connected to the Rocker Switch
const int motorInput1 = 3; // Pin connected to Input 1 of the L298N Motor Driver
const int motorInput2 = 4; // Pin connected to Input 2 of the L298N Motor Driver
const int proximitySensor1 = 2; // Pin connected to SIG (BLK) of the first Capacitive Proximity Sensor
const int proximitySensor2 = 6; // Pin connected to SIG (BLK) of the second Capacitive Proximity Sensor
void setup() {
// Initialize the pins
pinMode(rockerSwitchPin, INPUT);
pinMode(motorInput1, OUTPUT);
pinMode(motorInput2, OUTPUT);
pinMode(proximitySensor1, INPUT);
pinMode(proximitySensor2, INPUT);
// Start with the motor off
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, LOW);
}
void loop() {
// Read the state of the Rocker Switch
int switchState = digitalRead(rockerSwitchPin);
// Read the state of the proximity sensors
int sensor1State = digitalRead(proximitySensor1);
int sensor2State = digitalRead(proximitySensor2);
// If the Rocker Switch is on, control the motor based on the proximity sensors
if (switchState == HIGH) {
if (sensor1State == HIGH) {
// If the first sensor is triggered, rotate the motor in one direction
digitalWrite(motorInput1, HIGH);
digitalWrite(motorInput2, LOW);
} else if (sensor2State == HIGH) {
// If the second sensor is triggered, rotate the motor in the opposite direction
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, HIGH);
} else {
// If no sensor is triggered, stop the motor
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, LOW);
}
} else {
// If the Rocker Switch is off, stop the motor
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, LOW);
}
// Add a small delay to debounce the switch and sensors
delay(50);
}
This code is designed to run on the Arduino UNO microcontroller. It initializes the pins connected to the rocker switch, motor driver inputs, and proximity sensors. In the main loop, it reads the state of the rocker switch and proximity sensors to control the motor's direction. If the rocker switch is turned on, the motor's direction is determined by which proximity sensor is triggered. If neither sensor is triggered or the rocker switch is off, the motor is stopped. A small delay is added to debounce the inputs.