Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Brushless Motor with SD Data Logging and Buzzer Alert System

Image of Arduino UNO Controlled Brushless Motor with SD Data Logging and Buzzer Alert System

Circuit Documentation

Summary

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.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • Provides digital and analog I/O pins
  • Includes communication interfaces such as SPI and I2C
  • Operates at 5V

Brushless Motor

  • Three-phase motor that requires an electronic speed controller (ESC)
  • Typically used in applications requiring high power and efficiency

Speed Controller

  • Electronic Speed Controller (ESC) for brushless motors
  • Provides power to the motor and controls its speed
  • Accepts signal input to set motor speed

Piezo Buzzer

  • An electronic device that emits sound when voltage is applied
  • Used for audible alerts or feedback

Pushbutton

  • A simple switch mechanism for controlling some aspect of a machine or a process
  • Normally open, closes the circuit when pressed

Resistor

  • A passive two-terminal electrical component that implements electrical resistance
  • Used here as a pull-down resistor for the pushbutton

Battery

  • Provides power to the circuit
  • Voltage and capacity are not specified in the provided information

SD Module

  • A module that allows the Arduino to read from and write to SD cards
  • Used for data logging purposes

ACS712 Current Sensor

  • A hall effect-based linear current sensor
  • Capable of measuring both AC and DC currents

Wiring Details

Arduino UNO

  • D2 connected to Piezo Buzzer
  • GND connected to common ground net
  • 5V connected to common 5V net
  • D10 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)

Brushless Motor

  • L1 connected to Speed Controller (OUT3)
  • L2 connected to Speed Controller (Out 2)
  • L3 connected to Speed Controller (Out1)

Speed Controller

  • Signal connected to Arduino UNO (D6)
  • 5V connected to common 5V net
  • GND connected to common ground net
  • V+ connected to Battery (+)
  • Out1, Out 2, OUT3 connected to Brushless Motor

Piezo Buzzer

  • pin 1 connected to Arduino UNO (D2)
  • pin 2 connected to common ground net (via Resistor)

Pushbutton

  • Pin 3 (out) connected to common 5V net
  • Pin 1 (in) connected to Arduino UNO (D4) (via Resistor)

Resistor

  • One end connected to Pushbutton, other end to common ground net and Arduino UNO (D4)

Battery

  • + connected to Speed Controller (V+)
  • - connected to ACS712 Current Sensor

SD Module

  • CS 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 net
  • GND connected to common ground net

ACS712 Current Sensor

  • 1 connected to Battery (-)
  • 2 connected to common ground net
  • GND connected to common ground net
  • OUT not connected (reserved for analog input to Arduino)
  • VCC connected to common 5V net

Documented Code

#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