Hi, I need help with a basic project. I have a car that I need to drive via WiFi. It has two motors. One for back and forward. One for left and right. It Does NOT drive like a tank.
The car is built already and it’s part done with Blynk. It has an issue though, it drives like a Tank. So when I press forward both motors spin and the car goes forward and steers left. So it Never drives in a straight line. The car has a steering wheel just like a regular car.
The sketch I have only allows me to use One joystick for both motors. This does not work for me, is undriveable like that. It goes forward and steers to one side and backwards and steers to the opposite side.
I need to separate the inputs into two joysticks. One joystick for steering and one for forward/backwards.
Can you help me with this ?
Here is the code I have
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define RightMotorSpeed 5
#define RightMotorDir 0
#define LeftMotorSpeed 4
#define LeftMotorDir 2
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "u-TK4OigDNek6bb1SiSn8o9O1ODjU9T-";
char ssid[] = "RC-CAR";
char pass[] = "k11092001";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(RightMotorSpeed, OUTPUT);
pinMode(RightMotorDir, OUTPUT);
pinMode(LeftMotorSpeed, OUTPUT);
pinMode(LeftMotorDir, OUTPUT);
}
void loop()
{
Blynk.run();
}
void halt()
{
digitalWrite(RightMotorSpeed, LOW);
digitalWrite(LeftMotorSpeed, LOW);
}
void forward()
{
digitalWrite(RightMotorDir, HIGH);
digitalWrite(LeftMotorDir, HIGH);
digitalWrite(RightMotorSpeed, HIGH);
digitalWrite(LeftMotorSpeed, HIGH);
}
void reverse()
{
digitalWrite(RightMotorDir, LOW);
digitalWrite(LeftMotorDir, LOW);
digitalWrite(RightMotorSpeed, HIGH);
digitalWrite(LeftMotorSpeed, HIGH);
}
void right()
{
digitalWrite(RightMotorDir, LOW);
digitalWrite(LeftMotorDir, HIGH);
digitalWrite(RightMotorSpeed, HIGH);
digitalWrite(LeftMotorSpeed, HIGH);
}
void left()
{
digitalWrite(RightMotorDir, HIGH);
digitalWrite(LeftMotorDir, LOW);
digitalWrite(RightMotorSpeed, HIGH);
digitalWrite(LeftMotorSpeed, HIGH);
}
BLYNK_WRITE(V0)
{
if (param[0])
forward();
else
halt();
}
BLYNK_WRITE(V1)
{
if (param[0])
reverse();
else
halt();
}
BLYNK_WRITE(V2)
{
if (param[0])
right();
else
halt();
}
BLYNK_WRITE(V3)
{
if (param[0])
left();
else
halt();
}```