Hey everyone!
I'm currently working on a RC car project, it's in its earliest stages and I'm being held back by what I believe to be a simple issue.
Attached I have a fritzing image of my current circuit,I have 2 DC motors wired to a L293D IC which is then in turn wired to the arduino with a joystick too. I'm trying to control the motors with the joystick, I get that I can do it simply : If >600 pin 6 high etc. to simply steer and choose direction but I don't understand how to write a sketch for PWM to control it to accelerate depending on how far the joystick is pushed? Or even how to declare the analogue pins as a few people have done it differently.
Any help would be greatly appreciated and i intend to use nrf24lo1 modules when i get them to extend the range if that will effect this now in any way?
Current sketch:
const int mainForward = 6;
const int mainBackward = 9;
const int steerLeft = 10;
const int steerRight = 11;
void setup()
{
pinMode(mainForward , OUTPUT);
pinMode(mainBackward , OUTPUT);
pinMode(steerLeft , OUTPUT);
pinMode(steerRight , OUTPUT);
}
void loop()
{
//go forward
digitalWrite(mainForward , HIGH);
digitalWrite(mainBackward , LOW);
digitalWrite(steerLeft , LOW);
digitalWrite(steerRight , LOW);
delay(1500);
//go backward for 5sec
digitalWrite(mainForward , LOW);
digitalWrite(mainBackward , HIGH);
digitalWrite(steerLeft , LOW);
digitalWrite(steerRight , LOW);
delay(1500);
//go Left for 5sec
digitalWrite(mainForward , LOW);
digitalWrite(mainBackward , LOW);
digitalWrite(steerLeft , HIGH);
digitalWrite(steerRight , LOW);
delay(1500);
//go Right for 5sec
digitalWrite(mainForward , LOW);
digitalWrite(mainBackward , LOW);
digitalWrite(steerLeft , LOW);
digitalWrite(steerRight , HIGH);
delay(1500);
//Stop for 5sec
digitalWrite(mainForward , LOW);
digitalWrite(mainBackward , LOW);
digitalWrite(steerLeft , LOW);
digitalWrite(steerRight , LOW);
delay(1500);
}