I am working on a hobby project: creating an rc-(radio controlled)-toy car.
I'm working with a Wemos D1 Mini (esp8266) microcontroller, L298N H-bridge (for controlling the motor) and I'm using the Arduino IDE to program it all.
The project is quite simple: make the car drive around via an virtual joystick on an app. The project is quite fun and a nice learning experience for me. The project is going pretty well until this point.
I can move the car forwards and backwards with a constant speed, but I'm not able to change the speed via a PWM signal. Actually, I'm not even sure if it is even possible to create a PWM signal on the Wemos D1 Mini, I have never done it before on this specific controller. I'm not an electrical engineer, so I'm not really familiar with very specific details about the controller itself.
Can somebody help me create a PWM signal to control the speed of the car?
This is what I have got now, very basic stuff:
void setup() {
pinMode(D2, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
}
void forward() {
digitalWrite(D5, LOW);
digitalWrite(D6, HIGH);
}
void backward() {
digitalWrite(D5, HIGH);
digitalWrite(D6, LOW);
}
void setVelocity(int value){
analogWrite(D2, value);
}
void loop() {
setVelocity(1023);
forward();
}
Thanks in advance!
Sincerly,
Stefan
analogWrite
to the enable pin onD2
.