Arduino Mega 2560 Controlled 250W DC Motor with BTS7960 Driver and Temperature-Based PWM
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a 250W 12V DC electric motor using an Arduino Mega 2560 and a BTS7960 motor driver. The circuit includes a power supply, a rocker switch, a resistor, and a diode. The Arduino Mega 2560 is programmed to adjust the motor speed based on temperature readings from an analog sensor.
Component List
POWER SUPPLY 12V 5AMP
- Description: Provides 12V DC power to the circuit.
- Pins:
- 220V Positive Pole (AC)
- 220V Negative Pole (AC)
- GND
- GND (DC)
- 12V-24V Output (DC)
Rocker Switch
- Description: Used to control the power supply to the motor driver.
- Pins:
- Output
- Input
Resistor
- Description: Limits the current in the circuit.
- Properties:
- Resistance: 10000 Ohms
- Pins:
- Pin1
- Pin2
5408 Diode
- Description: Protects the circuit from reverse voltage.
- Pins:
- Cathode
- Anode
Arduino Mega 2560
- Description: Microcontroller used to control the motor driver and read sensor data.
- Pins:
- IOREF
- RESET
- 3V3
- 5V
- GND
- VIN
- A0 to A15
- D0 to D53
- PWM pins
- AREF
- SDA
- SCL
BTS7960 Motor Driver
- Description: Motor driver used to control the 250W 12V DC electric motor.
- Pins:
- Pin 1 to Pin 12
250W 12V ELECTRIC MOTOR BRUSH MOTOR DC
- Description: The motor being controlled in the circuit.
- Pins:
- POSITIF
- NEGATIF
Wiring Details
POWER SUPPLY 12V 5AMP
- GND is connected to:
- Arduino Mega 2560 (GND)
- BTS7960 Motor Driver (Pin 1, Pin 12)
- Resistor (Pin2)
- 12V-24V Output (DC) is connected to:
- Rocker Switch (Input)
Rocker Switch
- Output is connected to:
- BTS7960 Motor Driver (Pin 11)
- Arduino Mega 2560 (VIN)
Resistor
- Pin1 is connected to:
- BTS7960 Motor Driver (Pin 2, Pin 3, Pin 4, Pin 6, Pin 7)
- Pin2 is connected to:
- Arduino Mega 2560 (GND)
- BTS7960 Motor Driver (Pin 1, Pin 12)
- POWER SUPPLY 12V 5AMP (GND)
5408 Diode
- Cathode and Anode are not connected in the provided net list.
Arduino Mega 2560
- GND is connected to:
- BTS7960 Motor Driver (Pin 1, Pin 12)
- Resistor (Pin2)
- POWER SUPPLY 12V 5AMP (GND)
- 5V is connected to:
- BTS7960 Motor Driver (Pin 5)
- VIN is connected to:
- BTS7960 Motor Driver (Pin 11)
- Rocker Switch (Output)
- D8 PWM is connected to:
- BTS7960 Motor Driver (Pin 8)
BTS7960 Motor Driver
- Pin 1 is connected to:
- Arduino Mega 2560 (GND)
- Resistor (Pin2)
- POWER SUPPLY 12V 5AMP (GND)
- Pin 2, Pin 3, Pin 4, Pin 6, Pin 7 are connected to:
- Resistor (Pin1)
- Pin 5 is connected to:
- Arduino Mega 2560 (5V)
- Pin 8 is connected to:
- Arduino Mega 2560 (D8 PWM)
- Pin 9 is connected to:
- 250W 12V ELECTRIC MOTOR BRUSH MOTOR DC (NEGATIF)
- Pin 10 is connected to:
- 250W 12V ELECTRIC MOTOR BRUSH MOTOR DC (POSITIF)
- Pin 11 is connected to:
- Arduino Mega 2560 (VIN)
- Rocker Switch (Output)
- Pin 12 is connected to:
- Arduino Mega 2560 (GND)
- Resistor (Pin2)
- POWER SUPPLY 12V 5AMP (GND)
250W 12V ELECTRIC MOTOR BRUSH MOTOR DC
- POSITIF is connected to:
- BTS7960 Motor Driver (Pin 10)
- NEGATIF is connected to:
- BTS7960 Motor Driver (Pin 9)
Code Documentation
Arduino Mega 2560 Code
sketch.ino
void setup() {
// Set pin D11 (OC1A) as output
pinMode(11, OUTPUT);
// Stop Timer1
TCCR1A = 0;
TCCR1B = 0;
// Set Timer1 to Fast PWM mode with ICR1 as top value
TCCR1A = (1 << WGM11);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
// Set top value for 20kHz frequency
ICR1 = 799; // 16MHz / (20kHz * 2) - 1
// Set initial duty cycle to 50%
OCR1A = 400; // 50% of 799
// Enable output on OC1A (pin D11)
TCCR1A |= (1 << COM1A1);
}
void loop() {
// Example: Adjust duty cycle based on some condition
int sensorValue = analogRead(A0);
float temperatureC = sensorValue * (5.0 / 1023.0) * 100.0; // Convert to Celsius
// Map the temperature to a PWM duty cycle (0-799)
int dutyCycle = map(temperatureC, 20, 40, 0, 799); // Adjust the range as needed
// Constrain the duty cycle to be within 0-799
dutyCycle = constrain(dutyCycle, 0, 799);
// Set the new duty cycle
OCR1A = dutyCycle;
// Add a delay to avoid rapid changes
delay(500); // Adjust the delay as needed
}
documentation.txt
#include <TimerOne.h>
This documentation provides a comprehensive overview of the circuit, including a summary, component list, wiring details, and the code used in the Arduino Mega 2560.