Advertisement
MrLunk

IBT-2 / BTS7960 hi power Motor Controller 43A 24V - Arduino

Jun 28th, 2017
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. /*
  2. IBT-2 / BTS7960 hi power Motor Controller 43A 24V - Arduino code
  3.  
  4. This can easily be used for 1:10 Radio Controlled car models with for instance Mabuchi motors
  5. and a Ni-MH 7.2Volt 3600mA RC batterypack and a brushed RC DC-Motor.
  6.  
  7. Wiring schematic: https://imgur.com/gallery/77B0A
  8.  
  9. -------
  10. Speed and direction controlled by a potentiometer attached to analog input 0.
  11. One side pin of the potentiometer (either one) to ground; the other side pin to +5V
  12.  
  13. Connection to the IBT-2 board:
  14. IBT-2 pin 1 (RPWM) to Arduino pin 5(PWM)
  15. IBT-2 pin 2 (LPWM) to Arduino pin 6(PWM)
  16. IBT-2 pins 3 (R_EN), 4 (L_EN), 7 (VCC) to Arduino 5V pin
  17. IBT-2 pin 8 (GND) to Arduino GND
  18. IBT-2 pins 5 (R_IS) and 6 (L_IS) not connected
  19. */
  20.  
  21. int SENSOR_PIN = 0; // center pin of the potentiometer
  22.  
  23. int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
  24. int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
  25.  
  26. void setup()
  27. {
  28. pinMode(RPWM_Output, OUTPUT);
  29. pinMode(LPWM_Output, OUTPUT);
  30. }
  31.  
  32. void loop()
  33. {
  34. int sensorValue = analogRead(SENSOR_PIN);
  35.  
  36. // sensor value is in the range 0 to 1023
  37. // the lower half of it we use for reverse rotation; the upper half for forward rotation
  38. if (sensorValue < 512)
  39. {
  40. // reverse rotation
  41. int reversePWM = -(sensorValue - 511) / 2;
  42. analogWrite(LPWM_Output, 0);
  43. analogWrite(RPWM_Output, reversePWM);
  44. }
  45. else
  46. {
  47. // forward rotation
  48. int forwardPWM = (sensorValue - 512) / 2;
  49. analogWrite(LPWM_Output, forwardPWM);
  50. analogWrite(RPWM_Output, 0);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement