This circuit is designed to control a Brushless DC (BLDC) motor using an Arduino UNO microcontroller. The system includes an IR sensor for RPM measurement, a potentiometer for speed control, and a 16x2 LCD display for showing the RPM of the motor. The motor's speed is controlled by PWM signals generated by the Arduino, which are then fed to the motor through a set of IRFZ44N MOSFETs. Diodes are used for flyback protection. The circuit is powered by an external power supply.
#include <LiquidCrystal.h>
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 4, 5, 6, 3);
const int potPin = A0; // Potentiometer pin
const int motorPin1 = 9; // MOSFET gate pin for BLDC motor
const int motorPin2 = 10; // MOSFET gate pin for BLDC motor
const int motorPin3 = 11; // MOSFET gate pin for BLDC motor
const int irSensorPin = 2; // IR sensor pin
volatile unsigned long rpmCount = 0;
unsigned long lastTime = 0;
unsigned long rpm = 0;
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("RPM: ");
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(irSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(irSensorPin), rpmCounter, RISING);
}
void loop() {
int potValue = analogRead(potPin);
int motorSpeed = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin1, motorSpeed);
analogWrite(motorPin2, motorSpeed);
analogWrite(motorPin3, motorSpeed);
unsigned long currentTime = millis();
if (currentTime - lastTime >= 1000) {
noInterrupts();
rpm = rpmCount * 60; // Convert to RPM
rpmCount = 0;
lastTime = currentTime;
interrupts();
lcd.setCursor(0, 1);
lcd.print(rpm);
lcd.print(" "); // Clear any extra characters
}
}
void rpmCounter() {
rpmCount++;
}
This code is responsible for reading the potentiometer value to control the speed of the BLDC motor, measuring the RPM using an IR sensor, and displaying the RPM on a 16x2 LCD. The setup()
function initializes the LCD and configures the pins. The loop()
function reads the potentiometer, maps its value to a PWM signal, and writes it to the motor control pins. It also calculates and displays the RPM every second. The rpmCounter()
function is an interrupt service routine that increments the RPM count every time the IR sensor detects a rotation.