Control 5A DC Motor with Arduino (modify module)

Project Video
Project Details

This code is for video instruction to modify the DC 6V 12V 24V 28V 3A PWM module and control it using Arduino. Please watch the video instruction to understand it fully.

Project Code


/*
 * Modify 7833 PWM 5A Module to control with Arduino
 * MOdify the  "12V-36V 3A Pulse Width Modulator PWM DC Motor Speed Controller Control Switch"
 * 
 * 
 * Written by Ahmad Shamshiri
 * on Saturday July 27, 2019 at 18:23
 * in Ajax, Ontario, Canada
 * www.Robojax.com
 * Watch the video instruction: https://youtu.be/en-SJookvjo
 * See the module on eBay https://www.ebay.ca/sch/i.html?&_nkw=12V-36V+Pulse+Width+PWM&_sacat=0
 * or search for "12V-36V Pulse Width PWM"
 */
#define pwmPin 5
#define controlPin A0

void setup() {
  pinMode(pwmPin,OUTPUT);
  Serial.begin(9600);

}

void loop() {
  int potValue = analogRead(controlPin);

  int pwm =map(potValue, 0,1023, 0, 255);

    //pwm = toPWM(0);

  analogWrite(pwmPin,pwm);
  Serial.print("PWM:");  
  Serial.print(pwm);
  Serial.print(" it is:");  
  Serial.print(pwmToPercent(pwm));  
  Serial.println("%");    
  
  delay(500);
}

/*
 * @brief converts % value from 0 to 100% to 0-255
 * @param v is integer value representing % from 0-100
 * @return will return value from 0 to 255
 * Written by Ahmad Shamshiri for robojax.com
 * on July 30, 2019 in Ajax, Ontario, Canada
 */
int toPWM(int v){
  return map(v, 0,100,0,255);
}//

/*
 * @brief converts Arduino PWM value which is 0 to 255 to 0-100%
 * @param p is integer value representing  from 0-255
 * @return will return value from 0 to 255
 * Written bh Ahmad Shamshiri for robojax.com
 * on July 30, 2019 in Ajax, Ontario, Canada
 */
int pwmToPercent(int p)
{
 return map(p, 0,255,0,100); 
}