The below code is from this link
15A Single DC Motor Driver wiki-DFRobot[
^]
const int IN1=5;
const int IN2=4;
const int PWM=6;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(PWM, OUTPUT);
}
void loop() {
Motor_Brake();
delay(100);
Motor_Forward(200);
delay(3000);
Motor_Brake();
delay(100);
Motor_Backward(200);
delay(3000);
}
void Motor_Forward(int Speed) {
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
analogWrite(PWM,Speed);
}
void Motor_Backward(int Speed) {
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
analogWrite(PWM,Speed);
}
void Motor_Brake(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
}
However how do I actually control the motor, specifically forward / reverse?
How would I go about adding a potentiometer or forward & reverse switches?
Also I intend to use an ESP32 in this project. As such, I'm aware that I need to include the analogwrite.h library.
Is there anything else I should be made aware of?
Thanks.
What I have tried:
Nothing because I don't see how I can control the motor.