Heng Long BB Unit Control Using Phone Via Bluetooth

by thomas9363 in Circuits > Arduino

105 Views, 0 Favorites, 0 Comments

Heng Long BB Unit Control Using Phone Via Bluetooth

BBArduinoTitle.gif
empty.png

Heng Long is a renowned brand recognized for its specialization in the manufacturing of radio-controlled tanks, particularly in the 1/16 scale. These tanks are notable for their inclusion of a circuit board that functions as the central control unit, managing a variety of tank features and functions such as power distribution, regulation, tank movement, turret rotation, audio effects, lighting, and other diverse functionalities. Many tanks have a firing mechanism, often referred to as a BB unit. It propels small plastic BB pellets emulating the firing action of authentic tanks. You can purchase the BB unit from online marketplaces including Amazon, eBay, and AliExpress.

 

The central goal of the project is to construct a firing station using Heng Long BB unit. The station can be controlled by an Android App via Bluetooth. The station can be moved and fired in different directions. Instead of utilizing the brand's proprietary circuit board, this unit is integrated with either a microcontroller UNO or a microprocessor Raspberry Pi. This article provides instructions on using Arduino UNO.

Supplies

Here's a concise list of the materials used in my project:

  • Arduino Uno or similar Arduino microcontroller board.
  • Sensor Shield V5.0 for ease of sensor and component connections.
  • 5mW laser module for laser functionality.
  • IRF520 MOSFET module for controlling high-power components.
  • Power supply.
  • Heng Long BB unit and 6mm pellets for the firing mechanism.
  • Two servos along with mounting brackets to establish a pan-tilt mechanism.
  • Two tubes extracted from ballpoint pens, with an inner diameter slightly larger than 6mm, for barrel and magazine.
  • A smartphone for Android-based Bluetooth control.

Understand the BB Unit

gearbox.png

The BB unit comes sealed in a plastic housing and lacks a barrel and magazine. It has two sets of wires coming out from the housing. One set of wires is connected to a motor responsible for rotation, while the other set appears to be linked to a limit switch.

 

As shown above, there are various components including pinions, gears, and a rack inside the plastic housing. When the motor's pinion rotates, it engages with a series of gears. These gears progressively reduce the rotational speed while increasing torque. The last gear meshes with teeth on a rack, causing the rack to move linearly along its axis. This converts rotational motion into linear motion.

 

The linear motion of the rack pushes a "bolt" backward against the force of a compressed coil spring until it hits a limit switch. Once the "bolt" hits the limit switch, the coil spring is suddenly released, propelling the bolt forward with force. This mechanism is used for firing the BB pullet. After firing, the gear system is reset to its initial position. The gear pinion rack spring assists in retracting and resetting the gear pinion rack, preparing it for the next firing cycle.

 

There is limited information available online about the BB unit's specifications. Initial tests are conducted using a 5V power supply to prevent burnout of the motor. The motor draws approximately 0.7A of current. The 'bolt' on top of the unit moves backward and suddenly releases with force as a cycle. The firing cycle continues as long as the motor keeps rotating. In this project, the firing action should be user-initiated, meaning the user controls shooting by pressing the firing button.

 

The limit switch appears to have a crucial role in the system and serves as a sensor to detect the position of the bolt. When the status of the limit switch changes from open to closed, it sends a signal to a microcontroller. This signal requests the microcontroller to stop the motor rotation and consequently halt the firing process.

Building BB Unit on Top of a Pan-tilt Mechanism

BBGunPanTilt.png
empty.png

A barrel is needed to provide a straight and stable path for the projectile to travel, and a magazine is necessary to store and reload pellets. I cut two tubes from ballpoint pens to build them. The pan-tilt mechanism is constructed using parts from an old robotic arm. You can buy a kit directly from on line stores. Additionally, I added a laser module to the side of the unit, coaxial with the barrel. The overall construction is depicted above. 

Connecting to Electronics

BBArduinoSetup.png

A wiring diagram is presented above. To simplify the wiring, I plug an Arduino sensor shield 5.0 into the Arduino UNO. Since the motor draws approximately 0.7 amps of current, which is more than a digital pin on the UNO can provide. I use an IRF520 MOSFET to handle the high current. To ensure the safe transfer of data via Bluetooth, a voltage divider is placed between the bluetooth module and Arduino. This lowered the Arduino's 5V Vcc to a 3.3V logic level. 

Arduino Code

The code is available for downloading on my GitHub Repository.

Two important things about the code.

1. Receiving data from APP: the data is received as an integer array (255, button, X, Y).

 

  if (Serial.available() > 0) { //recieve byte from phone
   in_byte = Serial.read(); //store in byte into a variable
   if (in_byte == (255)) { //make sure that every number goes into the correct index
     array_index = 0;
   }
   dataIn[array_index] = in_byte; //store number into array
   array_index = array_index +1;
 }

 

The X, Y reading is mapped to degree in order to move the pan and tilt servos while the button reading controls laser or firing pellet.

 

2. Controlling motor so that the unit only shoots one pellet at a time:

 

The limit switch is normally in an “open” state. Moving backward of the rack inside the gearbox will eventually hits the limit switch and causes it to “close”. When the switch closes, the motor is stopped, the gearbox is reset and one pellet is fired.

Initial State: The limit switch is in the "open" state, and the motor is not running. The gearbox is in a neutral position.

int motorState = LOW; // State of the motor (LOW = off, HIGH = on)
int switchState = 1; // State of the limit switch (1 = open, 0 = closed)

 

When the firing command is received, the motor starts rotating, causing the gearbox to move. As the gearbox moves backward, it eventually reaches a point where it hits the limit switch. The physical contact with the limit switch causes it to change its state from "open" to "closed." When the limit switch closes, it signals the system to stop the motor. The gearbox is now in the desired position for firing one pellet. After firing, the system is reset, returning the gearbox to its neutral position. This could involve releasing the limit switch, preparing the system for the next firing sequence.

 

 if (dataIn[1]==2){ //if fire button is pressed
   Serial.print ("FIRE  ");
   motorState = !motorState;
   while ( switchState == 1){ //while limit switch is open
     digitalWrite(MOTOR_PIN, motorState);
     switchState = digitalRead(SWITCH_PIN);
     Serial.println(switchState);
     if (switchState==0){ // when limit switch is close, stop motor
       motorState = !motorState;
       digitalWrite(MOTOR_PIN, motorState);
       }
     }
   switchState=1; //rest limit switch to open
  }

Phone App

HengLongApp.png

The app is created using MIT. Two of them are made with difference appearances, one with cross and the other with joystick. The overall design as shown above, has two buttons on top to connect or disconnect Bluetooth, a textbox to display the joystick position, a cross or a blue joystick to move servos in x and y positions and two buttons at the bottom to activate laser and to fire pellet. It sends an integer array at a time. You can download them (*.aia) at my GitHub Repository.

Conclusions

app control of Heng Long BB unit

The video above demonstrates the BB gun in action. My next step is to interface it with a Raspberry Pi microprocessor for control.