Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Pwm motor control with 2 Potentiometers
- laser pwm motor control.ino
- Demonstrates use of 2 potentiometers with Arduino and PWM signal.
- Laser etcher control board 2021
- */
- // Motor A dual fans
- int pwma = 0;
- // Motor B air pump
- int pwmb = 1;
- // Speed control potentiometers
- int SpeedControl1 = A2;
- int SpeedControl2 = A3;
- // Motor Speed Values - Start at zero
- int MotorSpeed1 = 0;
- int MotorSpeed2 = 0;
- void setup()
- {
- // Set all the motor control pins to outputs
- pinMode(pwma, OUTPUT);
- pinMode(pwmb, OUTPUT);
- }
- void loop() {
- // Read the values from the potentiometers
- MotorSpeed1 = analogRead(SpeedControl1);
- MotorSpeed2 = analogRead(SpeedControl2);
- // Convert to range of 0-255
- MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
- MotorSpeed2 = map(MotorSpeed2, 0, 1023, 0, 255);
- // Adjust to prevent "buzzing" at very low speed
- if (MotorSpeed1 < 8)MotorSpeed1 = 0;
- if (MotorSpeed2 < 8)MotorSpeed2 = 0;
- // Set the motor speeds
- analogWrite(pwma, MotorSpeed1);
- analogWrite(pwmb, MotorSpeed2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement