This circuit is designed to control a brushless motor using an Arduino UNO as the central processing unit. It includes a piezo buzzer for audible feedback, a pushbutton for user input, a speed controller to manage the motor's speed, and a current sensor to monitor the electrical current. Additionally, an SD module is incorporated for data logging purposes. The circuit is powered by a battery, and a resistor is used for pull-down configuration on the pushbutton.
D2
connected to Piezo BuzzerGND
connected to common ground net5V
connected to common 5V netD10
connected to SD Module (CS)D13
connected to SD Module (SCK)D11
connected to SD Module (MOSI)D12
connected to SD Module (MISO)D4
connected to Pushbutton (via Resistor)D6
connected to Speed Controller (Signal)A0
not connected (reserved for current sensor)L1
connected to Speed Controller (OUT3)L2
connected to Speed Controller (Out 2)L3
connected to Speed Controller (Out1)Signal
connected to Arduino UNO (D6)5V
connected to common 5V netGND
connected to common ground netV+
connected to Battery (+)Out1
, Out 2
, OUT3
connected to Brushless Motorpin 1
connected to Arduino UNO (D2)pin 2
connected to common ground net (via Resistor)Pin 3 (out)
connected to common 5V netPin 1 (in)
connected to Arduino UNO (D4) (via Resistor)+
connected to Speed Controller (V+)-
connected to ACS712 Current SensorCS
connected to Arduino UNO (D10)SCK
connected to Arduino UNO (D13)MOSI
connected to Arduino UNO (D11)MISO
connected to Arduino UNO (D12)VCC
connected to common 5V netGND
connected to common ground net1
connected to Battery (-)2
connected to common ground netGND
connected to common ground netOUT
not connected (reserved for analog input to Arduino)VCC
connected to common 5V net#include <SPI.h>
#include <SD.h>
#include <Servo.h> // Include the Servo library
// Pin Definitions
const int buttonPin = 4;
const int buzzerPin = 2;
const int currentSensorPin = A0;
const int chipSelect = 10; // Pin for the SD card module
// Program Variables
File dataFile; // Create a file object to write to the SD card
Servo esc; // Create a Servo object to control the ESC
bool programStarted = false;
bool buzzerStarted = false; // Ensures buzzer only activates after button press
bool buzzerOn = false; // Tracks if the buzzer should be on
unsigned long lastBuzzerTime = 0;
unsigned long lastThrottleTime = 0;
unsigned long lastSampleTime = 0;
int buzzerCount = 0;
int throttleValue = 1000; // Start at 1000 µs (0% throttle for ESC)
bool holdingThrottle = false; // Tracks if we're in the holding phase
void setup() {
pinMode(buttonPin, INPUT); // Button with pull-down resistor
pinMode(buzzerPin, OUTPUT);
esc.attach(6); // Attach the ESC to pin 6
esc.writeMicroseconds(throttleValue); // Initialize PWM to 1000 µs
digitalWrite(buzzerPin, LOW); // Ensure buzzer is OFF initially
Serial.begin(9600); // For current data output
// Initialize the SD card
// Create a new file (or open an existing one)
dataFile = SD.open("currentData.txt", FILE_WRITE);
if (dataFile) {
Serial.println("Writing to file...");
dataFile.println("Time (ms), Current (A)"); // Header row
dataFile.close();
} else {
Serial.println("Error opening file!");
}
}
void loop() {
// Check if the button is pressed to start the program
if (digitalRead(buttonPin) == HIGH && !programStarted) {
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
programStarted = true;
buzzerStarted = true; // Enable buzzer sequence only after button press
lastBuzzerTime = millis(); // Start the buzzer timing
buzzerCount = 0; // Reset buzzer count at program start
}
// Buzzer Activation (5 times, 0.25 second ON, 0.5 second OFF) after button press
if (buzzerStarted && buzzerCount < 5) {
unsigned long currentMillis = millis();
if (buzzerOn && currentMillis - lastBuzzerTime >= 250) { // Buzzer ON duration
digitalWrite(buzzerPin, LOW); // Turn buzzer OFF
buzzerOn = false;
lastBuzzerTime = currentMillis;
buzzerCount++; // Increase beep count after each OFF period
}
else if (!buzzerOn && currentMillis - lastBuzzerTime >= 500) { // Buzzer OFF duration
digitalWrite(buzzerPin, HIGH); // Turn buzzer ON
buzzerOn = true;
lastBuzzerTime = currentMillis;
}
}
// Throttle Ramp-Up (1000 µs to 1250 µs over 5 seconds) after buzzer completes
else if (programStarted && buzzerCount >= 5 && throttleValue < 1500 && !holdingThrottle) {
if (millis() - lastThrottleTime >= 100) {
lastThrottleTime = millis();
throttleValue += 15; // Increase PWM gradually to reach 1250 µs (approx. 25% throttle)
esc.writeMicroseconds(throttleValue); // Set ESC throttle
}
}
// Maintain 25% Throttle and Read Current Sensor Data (5 seconds at 50 Hz)
else if (programStarted && throttleValue >= 1500 && !holdingThrottle) {
holdingThrottle = true; // Enter holding phase
lastThrottleTime = millis(); // Reset timing for the hold duration
}
// Hold the throttle and read current sensor data for 5 seconds
if (holdingThrottle && millis() - lastThrottleTime < 5000) {
if (millis() - lastSampleTime >= 100) { // Sample current sensor at 50 Hz
lastSampleTime = millis();
// Read and calculate current from ACS712 sensor
int currentReading = analogRead(currentSensorPin);
float current = (currentReading - 512) *-1* (5.0 / 1024.0) / 0.066;
// Print current to Serial Monitor
Serial.println(current);
// Open the file to append the current reading with timestamp
dataFile = SD.open("test.txt", FILE_WRITE);
if (dataFile