Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The below code is from this link 15A Single DC Motor Driver wiki-DFRobot[^]

/*
* @file Motor driver DRI0042_Test.ino
* @brief DRI0042_Test.ino  Motor control program
*
* control motor positive inversion
*
* @author bernie.chen@dfrobot.com
* @version  V1.0
* @date  2016-8-10
*/
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);//Forward, PWM setting 0-255
 delay(3000);
 Motor_Brake();
 delay(100);
 Motor_Backward(200);//Reverse, PWM setting 0-255
 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.
Posted
Comments
Patrice T 8-Jan-22 6:48am    
This is a general purpose programming forum.
You should try to find an Arduino users forum.
Richard MacCutchan 8-Jan-22 7:34am    
You should use the forum listed on that web page for questions about the articles you found there.
Summersky2017 9-Jan-22 4:14am    
I had a brief look on that forum and noticed discussions relating to bizarre topics so figured it wasn't going to be helpful.
Anyhow I posted my question and am looking forward to seeing the responses.
[no name] 9-Jan-22 0:28am    
That's just a driver. You now new an app to "talk" to the driver. The potentiometer would interface with the app. Pot -> (pot driver) -> app -> motor driver -> motor.
Summersky2017 9-Jan-22 4:17am    
Thanks for explaining. Do you have any suggestions for a suitable app?
I usually use ESPHome which is an add-on for Home Assistant to do this. However I'm not having much luck so I wanted to go back to basics by using arduino just to see if the basic functions can perform.
As you can likely tell, I'm a complete novice when it comes to software.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900