Other Arduino Codes and Videos by Robojax
This video explains how modify the 60A PWM module and control it with Arduino. Either with potentiometer or just Arduino code.
If you don't want to control this module using external signal, and see this module fully tested under different loads, you may
have to see XY-1250 60A Module is tested and expaliend page.
see How to control 60A motor using Arduino with potentiometer.
/*
* file: PWM_for_XY1260_module_no_pot
* Modify XY-1250 12-50V 60A PWM to work with Arduino
* this code allows you to control the motor wihtout potentiometer See video for demonstration
*
* how ot use:
* to control speed at 100%
motorControl(100);
delay(3000);//keep it running for 3 seconds
* to control speed at 400%
motorControl(40);
delay(3000);//keep it running for 3 seconds
* to stop motor
motorControl(0); //set zero
delay(3000);//keep it running for 3 seconds
* Written by Ahmad Shamshiri
* on Saturday Jan 30, 2021, at 12:49
* in Ajax, Ontario, Canada
* www.Robojax.com
* Watch the video instruction: https://youtu.be/ZLZr2AZgmPI
*/
#define pwmPin1 3
#define pwmPin2 6
bool defaultMotorON = false;// or set to "true" to make the motor start
unsigned int defaultSpeed= 20;//20% set it in % 0=stop, 100=full speed
int toPWM(int);//prototype
void setup() {
pinMode(pwmPin1,OUTPUT);
pinMode(pwmPin2,OUTPUT);
Serial.begin(9600);
Serial.print("Control XY-1260 wihtout pot");
if(defaultMotorON){
analogWrite(pwmPin1,toPWM(defaultSpeed));
analogWrite(pwmPin2,toPWM(defaultSpeed));
}else{
analogWrite(pwmPin1,0);
analogWrite(pwmPin2,0);
}
}
void loop() {
motorControl(100);//set speed to 100%
delay(3000);//keep motor running at 100% for 3 seconds
motorControl(0);//stops motor
delay(4000);//keep motor stopped for 4 seconds
motorControl(45);//set speed to 45%
delay(3000);//keep motor running at 45% for 3 seconds
motorControl(0);//stops motor
delay(4000);//keep motor stopped for 4 seconds
//from 0 to 100% with 50milliscond delay (increasing speed)
for(int i=0; i<100; i++)
{
motorControl(i);//set speed with value of i from 0 to 100
delay(50);//give motor 50 milliseconds before going to the next value
}//for loop end
motorControl(0);//stops motor
delay(4000);//keep motor stopped for 4 seconds
//from 100% to 10 with 50milliscond delay (decreasing speed)
for(int i=100; i>0; i--)
{
motorControl(i);//set speed with value of i from 0 to 100
delay(50);//give motor 50 milliseconds before going to the next value
}//for loop end
motorControl(0);//stops motor
delay(4000);//keep motor stopped for 4 seconds
}//loop end
/*
* @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
*/
int toPWM(int v){
return map(v, 0,100,0,255);
}//
/*
* @brief controls the speed of motor wiht value from 0 to 100%
* @param speed is integer value representing % from 0-100
* @return none
* written Jan 30, 2021 by Ahmad Shamshiri
* www.robojax.com
*
*/
void motorControl(int speed)
{
int pwm= map(speed, 0,100,0,255);
analogWrite(pwmPin1,pwm);
analogWrite(pwmPin2,pwm);
}
If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal