Motor controller l9110 PWM problems

Hello,

I have a problem with my l9110. I want to make my motor drive in 2 speeds forward and backward. But when i type the code it only moves in forward direction and doesn’t change direction like it’s suppose to.
This is the basic code on which i am testing:

void setup() {
pinMode(D3,OUTPUT);
pinMode(D2,OUTPUT);

}

void loop() {
int h1=512;
int h2=1024;
int l=0;

analogWrite(D2,l);
analogWrite(D3,h1);
delay(300);

analogWrite(D3,h2);
delay(300);

analogWrite(D2,l);
analogWrite(D3,l);
delay(300);

analogWrite(D2,h1);
analogWrite(D3,l);

And i also tried another code for speeding up the motor. When i put it forward it speeds normally, but when it has to start speeding backwards it starts backwards but in full spreed. This is the second code.

analogWrite(D2,b);
for(i=0;i<=1024;i++){
analogWrite(D3,i);
delay(50);

if(i==1024){
analogWrite(D3,b);
for(i=0;i<=1024;i++){
analogWrite(D2,i);
delay(50);
}
}

}

I’v tried it on both Arduino and ESP and it’s the same result.

Which Arduino are you using? The UNO and other AtMega328 based Arduinos have a range of values for analogWrite() from 0 to 255.