Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 Controlled 250W DC Motor with BTS7960 Driver and Temperature-Based PWM

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Controlled 250W DC Motor with BTS7960 Driver and Temperature-Based PWM

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

Rocker Switch

Resistor

5408 Diode

Arduino Mega 2560

BTS7960 Motor Driver

250W 12V ELECTRIC MOTOR BRUSH MOTOR DC

Wiring Details

POWER SUPPLY 12V 5AMP

Rocker Switch

Resistor

5408 Diode

Arduino Mega 2560

BTS7960 Motor Driver

250W 12V ELECTRIC MOTOR BRUSH MOTOR DC

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.