I am making a 1/4th scale electric RC car and wish to use a 24V 350W DC motor. To control the car I am using Arduino Uno with NRF2401L transceiver. How can I control the speed of the motor, make it stop (hence acting as a brake as well) and also make it go forward and backward using Arduino?
On the Tx side I have 1 pot each for throttle and brake. How to map them both to control the same motor?
You need some sort of motor driver to sit between the Arduino and the motor.
You may get some ideas from the motor drivers on the Pololu website.
It may be a better idea (cheaper/easier-to-use) to get an Electonic Speed Control (ESC) that is controlled with the Servo library. The HobbyKing website may have something suitable.
I have no relationship with either supplier except as a customer.
To answer your last question I think it is necessary to know what motor driver you are using.
Possibly - but I don't see any info on that web page about how to control it. Maybe you can post a link to its datasheet.
If that controller is intended as a replacement part it is possible that its control interface is not convenient for an Arduino - for example it may designed for a high voltage (i.e. higher than 5v) or high current input.
Scrolling down on the page there is a tutorial given using arduino as well. But there is note mentioned that says "**Note that it is not for "RC PWM".
The code is given as
//define pin name
#define dir_1 7
#define pwm_1 6
#define switch_1 13
#define pot 1
void setup() {
pinMode(pwm_1,OUTPUT);
pinMode(dir_1,OUTPUT);
pinMode(pot,INPUT);
pinMode(switch_1, INPUT);
Serial.begin(9600); //I am using Serial Monitor instead of LCD display
}
void loop() {
int pwm_value=0;
int reading=0;
int prev_reading=0;
//controls the direction the motor
digitalWrite(dir_1,digitalRead(switch_1));
//controls the speed of the motor
for (int i=0;i<5;i++) //gets the average value of the pot value for better accuracy
reading+= analogRead(pot);
reading/=5;
pwm_value = reading>>2; //convert the 10-bit values to 8-bit values
analogWrite(pwm_1,pwm_value);
Serial.println("PWM:");
Serial.println(pwm_value); //Display the value of PWM
delay(100);
}
In this is the line "output=reading*0.2493" required since we are directly using values of pot received from the tx side? Also how do I map the Brake potentiometer to stop the motor? I am using that stopping that motor would stop the car and I will not have to use a separate Drum/Disc Brake.
I think the warning about RC PWM is because it cannot be controlled directly by an RC receiver. Unfortunately PWM has a different meaning for RC signals than it has for motor speed control.
The line "the line "output=reading*0.2493" is not in the code you posted so I don't understand the question.
That piece if code suggests that the driver is controlled in the normal way using analogWrite()
I don't know what this line does and I wonder if you have posted the complete code
pwm_value = reading>>2; //convert the 10-bit values to 8-bit values
The usual way to reduce the 10 bit value to 8 bits (i.e. to convert 1023 to 255) is to divide by 4
There were two codes given so by mistake pasted the other one..Sorry! Here is the complete code.
//define keycode for LCD push button
#define None 0
#define Select 1
#define Left 2
#define Up 3
#define Down 4
#define Right 5
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
LCD_Key keypad;
//define pin name
#define diy_pwm A2
#define pwm 3
#define dir 2
#define pot A1
void setup(){
lcd.begin(16, 2);
lcd.clear();
pinMode(pwm,OUTPUT);
pinMode(dir,OUTPUT);
pinMode(diy_pwm,OUTPUT);
pinMode(pot,INPUT);
}
void loop(){
int localKey; //initialization
int pwm_value;
int reading = 0;
int prev_reading = 0;
int output = 0;
lcd.setCursor(0,0); //LCD display on beginning
lcd.print("PWM:");
lcd.print(output);
lcd.setCursor(0,1);
lcd.print("DIR:");
lcd.print(digitalRead(dir));
while(1){
localKey = keypad.getKey();
if(localKey==Left){
digitalWrite(dir,!digitalRead(dir)); //toggle and display motor direction if LEFT button pressed
lcd.setCursor(0,1);
lcd.print("DIR:");
lcd.print(digitalRead(dir));
delay(200);
}
reading = 0; //get average five consecutive analog readings from A1 pin (pot)
for(int i =0;i<5;i++)
reading += analogRead(pot);
reading/=5;
output=reading*0.2493; //convert from 10 bit to 8 bit, 0.2493 = 255/1023
if(reading!=prev_reading){ //update LCD data if only the reading changes to prevent reading on
//LCD blinking
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("PWM:");
lcd.print(output);
prev_reading = reading;
}
analogWrite(pwm,output);
}
}
Do you mean that I can use this controller for my system?
According to the "Introduction", on the page "Controlling MD10C with Arduino", the MD10C driver is "designed to drive high current brushed DC motor up to 13A continuously (for Rev2.0)."
On the main page it says 30A continuously with 80A peak for 1 second. I don't know which is correct. If I were you, I'd download and study the datasheet.
Your 350W 24VDC motor will draw 14.6A at full power, so the MD10C driver might or might not be suitable.
If you do end up using that driver, avoid "locked anti-phase mode", because your motor will run at full speed when it's not receiving a PWM signal. Could be dangerous. "Sign Magnitude Mode" sounds much safer.
The motor might squeal with normal low-frequency PWM, too. Usually it's better to use a high frequency >20kHz so that it's out of the range of human hearing. That driver can only handle a maximum of 20kHz, so it's borderline in that regard.
I don't have time to read more of the info, but I'd suggest that you do so before buying that particular driver, to make sure it's suitable for your purpose.