Advertisement
microrobotics

MRX-BL4805F Brushless DC Motor Controller

May 8th, 2023
1,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Given that the MRX-BL4805F industrial Brushless DC Motor controller can be controlled using an analog 0-5V signal or a PWM signal between 10-300Hz, you can use the Arduino's analog output (PWM) to control the motor speed.
  3.  
  4. Here's an example of Arduino code to control the MRX-BL4805F motor controller using PWM:
  5.  
  6. Requirements:
  7.  
  8. Arduino board (e.g., Uno, Mega, Nano)
  9. MRX-BL4805F Brushless DC Motor controller
  10. Jumper wires
  11. Motor power supply
  12.  
  13. In this example, the motor speed is controlled using the Arduino's PWM output on pin 3. The motor speed increases by 50 every 2 seconds (2000 milliseconds) within the 0-255 range, which corresponds to a 0-100% duty cycle. Connect the PWM output pin (in this case, pin 3) of the Arduino to the analog input or PWM input of the MRX-BL4805F motor controller for speed control.
  14. */
  15.  
  16. // Pin for the PWM output to control the motor speed
  17. #define PWM_PIN 3
  18.  
  19. // Speed control variables
  20. int motorSpeed = 0; // Motor speed (0-255 for PWM)
  21. unsigned long previousMillis = 0; // Stores the last time the motor speed was updated
  22. const unsigned long interval = 2000; // Motor speed update interval (in milliseconds)
  23.  
  24. void setup() {
  25.   // Set the PWM pin as an output
  26.   pinMode(PWM_PIN, OUTPUT);
  27. }
  28.  
  29. void loop() {
  30.   // Update the motor speed every 'interval' milliseconds
  31.   unsigned long currentMillis = millis();
  32.   if (currentMillis - previousMillis >= interval) {
  33.     previousMillis = currentMillis;
  34.    
  35.     // Set the motor speed
  36.     motorSpeed = (motorSpeed + 50) % 256; // Increase motor speed by 50 (0-255 range)
  37.     analogWrite(PWM_PIN, motorSpeed); // Write the PWM value to the pin
  38.   }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement