

This circuit is designed to control two fans using an Arduino UNO microcontroller. It includes pushbuttons for user input, an LCD display for feedback, and an L298N DC motor driver to control the fan speeds and directions. The Arduino UNO is programmed to respond to button presses to change the state of the fans, which can rotate clockwise, counterclockwise, or stop. The LCD display provides a visual indication of the current state of each fan.
5V and GND are used to power the L298N motor driver and the LCD display.A4 (SDA) and A5 (SCL) are connected to the LCD display for I2C communication.D5, D6, D7, D9, D10, and D11 are connected to the L298N motor driver to control the fans.D2 and D3 are connected to the pushbuttons.5V and GND connection, which are controlled by the L298N motor driver.GND and another pin connected to a digital pin on the Arduino UNO (D2 or D3).VCC is connected to the 5V output from the Arduino UNO.GND is connected to the ground of the Arduino UNO.SDA and SCL are connected to A4 and A5 on the Arduino UNO for I2C communication.5V and GND are connected to the Arduino UNO for power.IN1, IN2, IN3, IN4, ENA, and ENB are connected to the Arduino UNO digital pins for control signals.OUT1, OUT2, OUT3, and OUT4 are connected to the fans to control their operation.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD initialization
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin assignments
const int button1Pin = 2;
const int button2Pin = 3;
const int fan1EnablePin = 5;
const int fan1In1Pin = 6;
const int fan1In2Pin = 7;
const int fan2EnablePin = 9;
const int fan2In1Pin = 10;
const int fan2In2Pin = 11;
// Variables for button states
int button1State = 0;
int button2State = 0;
int button1PressCount = 0;
int button2PressCount = 0;
unsigned long lastDebounceTime1 = 0;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay = 50;
void setup() {
// Initialize pins
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(fan1EnablePin, OUTPUT);
pinMode(fan1In1Pin, OUTPUT);
pinMode(fan1In2Pin, OUTPUT);
pinMode(fan2EnablePin, OUTPUT);
pinMode(fan2In1Pin, OUTPUT);
pinMode(fan2In2Pin, OUTPUT);
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fan Control");
delay(1000);
lcd.clear();
}
void loop() {
int reading1 = digitalRead(button1Pin);
int reading2 = digitalRead(button2Pin);
if (reading1 == LOW && (millis() - lastDebounceTime1 > debounceDelay)) {
lastDebounceTime1 = millis();
button1PressCount++;
if (button1PressCount > 3) button1PressCount = 1;
controlFan1(button1PressCount);
}
if (reading2 == LOW && (millis() - lastDebounceTime2 > debounceDelay)) {
lastDebounceTime2 = millis();
button2PressCount++;
if (button2PressCount > 3) button2PressCount = 1;
controlFan2(button2PressCount);
}
}
void controlFan1(int pressCount) {
switch (pressCount) {
case 1:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fan1: Clockwise");
digitalWrite(fan1In1Pin, HIGH);
digitalWrite(fan1In2Pin, LOW);
analogWrite(fan1EnablePin, 255);
break;
case 2:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fan1: Counter");
digitalWrite(fan1In1Pin, LOW);
digitalWrite(fan1In2Pin, HIGH);
analogWrite(fan1EnablePin, 255);
break;
case 3:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fan1: Stop");
analogWrite(fan1EnablePin, 0);
break;
}
}
void controlFan2(int pressCount) {
switch (pressCount) {
case 1:
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Fan2: Counter");
digitalWrite(fan2In1Pin, LOW);
digitalWrite(fan2In2Pin, HIGH);
analogWrite(fan2EnablePin, 255);
break;
case 2:
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Fan2: Clockwise");
digitalWrite(fan2In1Pin, HIGH);
digitalWrite(fan2In2Pin, LOW);
analogWrite(fan2EnablePin, 255);
break;
case 3:
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Fan2: Stop");
analogWrite(fan2EnablePin, 0);
break;
}
}
This code is responsible for the operation of the fans and the display of their status on the LCD. It includes debouncing for the pushbuttons and functions to control the fans based on the button presses.