Hi everybody, new to the forum and Arduino So I am doing this project, what I am trying to do is to control a RC car by connecting the remote to the arduino. How I've does this is that I connected transistors to the arduino to work as switches for up,down,left and right(so 4 transistors in all). Whenever power is send from one of the corresponding arduino pins to the base of the transistor it acts as a switch and allows current to pass through it allowing the car to move in one of the directions. Right now I've used a switch case to take commands from the PC. So when I input 1 the car moves forward. But I find this a bit crude and also I am quite sure there is better way to do this. The biggest problem is that it can only move in 1 direction at a time so it cant turn while moving forward or backward. So please suggest changes to the code to compensate for this. Thanks In Advance
void setup()
{
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
Serial.println("All systems are a go....");
}
void loop()
{
if(Serial.available() > 0)
{
int input = Serial.read();
switch(input){
//Make Car go up
case '1':
digitalWrite(9, HIGH);
Serial.println("UP");
delay(50);
break;
//Make Car go down
case '2':
digitalWrite(10, HIGH);
Serial.println("DOWN");
delay(50);
break;
//Make Car turn Left
case '3':
digitalWrite(11, HIGH);
Serial.println("LEFT");
delay(50);
break;
//Make Car turn Right
case '4':
digitalWrite(12, HIGH);
Serial.println("RIGHT");
delay(50);
break;
case '0':
digitalWrite(9, LOW);
digitalWrite(10, LOW);
Serial.println("OFF");
break;
//Make car stop.
default:
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
break;
}
}
}
hi,
I have made a car like this.It's hard for arduino to drive moto directly.Because the output current of the arduino is very low.I suggest you using a L298 H-Bridge and a 9v battery to drive your moto.And I need to know how many motos do you have on your car.You can also show me a picture of your car.
I suggest you using a L298 H-Bridge and a 9v battery to drive your moto.
A 9V battery should be good for several feet.
Doesnt that depend on the motor?
While different motors have different current requirements, any remotely reasonably sized set of motors will use up the 500mAh of a 9-volt fairly quickly.
The OP does not need an H bridge, as he is not directly powering the motors. He is interfacing with the buttons used to control the motors, which are already equipped to switch the motors, so the rc car is taking care of this for him. Athulram, if your setup is working reliably, there is no need to change the hardware that you have.
If your only question is how to make the car turn and drive at the same time, how about specifying intermediary directions in the code as well (i.e. LF for left forward, RB for right backwards, etc). Or, depending on how the car is wired, you may be able to control the speed of the motors by varying the voltage at the transistor bases with PWM. Then you could specify the direction in degrees.
Do you have a further goal for your robot?
Sorry about the late response (timezone issues). I dont need H-bridges or anything like that because I am controlling the car using the remote control. I've used simonhack's code (with some changes now it works alot better) But even then I am open to changes. The reason I am doing this is so that the computer can control the car according to information from a webcam (stuff like obstacle avoidance etc). I've provided some pics and a hand drawn circuit.
BTW, I've used 1K ohm resistors as well as diodes to protect the Arduino, but is this necessary because the remote only has 2 AA batteries so it only will generate a max of 3 volts (just ~1.25V when I measured the wire's which need to be connected to the transistor with a Multi-meter). Can I remove them from the circuit or should I reduce the value of the resistors?