Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- IBT-2 / BTS7960 hi power Motor Controller 43A 24V - Arduino code
- This can easily be used for 1:10 Radio Controlled car models with for instance Mabuchi motors
- and a Ni-MH 7.2Volt 3600mA RC batterypack and a brushed RC DC-Motor.
- Wiring schematic: https://imgur.com/gallery/77B0A
- -------
- Speed and direction controlled by a potentiometer attached to analog input 0.
- One side pin of the potentiometer (either one) to ground; the other side pin to +5V
- Connection to the IBT-2 board:
- IBT-2 pin 1 (RPWM) to Arduino pin 5(PWM)
- IBT-2 pin 2 (LPWM) to Arduino pin 6(PWM)
- IBT-2 pins 3 (R_EN), 4 (L_EN), 7 (VCC) to Arduino 5V pin
- IBT-2 pin 8 (GND) to Arduino GND
- IBT-2 pins 5 (R_IS) and 6 (L_IS) not connected
- */
- int SENSOR_PIN = 0; // center pin of the potentiometer
- int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
- int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)
- void setup()
- {
- pinMode(RPWM_Output, OUTPUT);
- pinMode(LPWM_Output, OUTPUT);
- }
- void loop()
- {
- int sensorValue = analogRead(SENSOR_PIN);
- // sensor value is in the range 0 to 1023
- // the lower half of it we use for reverse rotation; the upper half for forward rotation
- if (sensorValue < 512)
- {
- // reverse rotation
- int reversePWM = -(sensorValue - 511) / 2;
- analogWrite(LPWM_Output, 0);
- analogWrite(RPWM_Output, reversePWM);
- }
- else
- {
- // forward rotation
- int forwardPWM = (sensorValue - 512) / 2;
- analogWrite(LPWM_Output, forwardPWM);
- analogWrite(RPWM_Output, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement