Modify 20A DC PWM Motor Speed Controller and contro with Arduino

Project Video
Project Details

This code is for video on how to modify and use the DC 10-60V 20A PWM Motor Speed Controller with Arduino.

Project Code


/*
 * Modify 80NF70 PWM 20A Module to control with Arduino
 * MOdify the  "DC 10-60V 20A Motor Speed Control Regulator PWM Motor Speed Controller 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/ipFxYQkB5uw
 * See the module on eBayGet this module from eBay 
https://www.ebay.com/sch/i.html?&_nkw=20A+DC10-60V+PWM&_sacat=0
 * or search for "DC 10-60V 20A Motor Speed Control Regulator PWM Motor Speed Controller "
 * Watch full review of this module: https://youtu.be/kgs_FILyppk
 */
 
#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 bh 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); 
}