Arduino 4WD Car - Assembly and Code - With Optional Infrared or Bluetooth Control and Autonomous Driving Capability (original) (raw)

Introduction: Arduino 4WD Car - Assembly and Code - With Optional Infrared or Bluetooth Control and Autonomous Driving Capability

Assembly instruction for a cheap (30€) chinese 4WD_KIT1 and how to improve and extend it. The control software is available as an Arduino library.

Supplies

  1. 4 WD starter kit for Arduino
  2. TB6612 Dual Motor Driver 1A (replacement for the awful inefficient LM298 driver)
  3. 4 wire 20 cm female-female dupont cable for HC-SR04 connection (missing in my china set)
  4. Toggle switch (missing in the china set)
  5. Two additional M3 screws and nuts to fasten the uno board
  6. 10 wire 12 cm female-female dupont cable for the TB6612 connection (if you do not want to use the 15 cm cable intended for the IR sensors, which we do not use here)

Optional:

  1. AC2208 Piezo buzzer (for audio feedback)
  2. 10 kOhm + 100 kOhm 1% resistor for optional undervoltage protection and supply voltage display in the Bluetooth control GUI.
  3. HC-05 Bluetooth modul for Bluetooth control
  4. TL1838 IR receiver for IR control
  5. Female 20 pin header row to build adapters for the buzzer, the IR receiver and optional the motor power connectors and BT module.

A Phillips screwdriver, a cutter for the servo connector, a soldering iron, a 2 mm and a 5 mm drill and a few cm wires (and a tweezer) are required for assembly. A hot glue gun is helpful for fixing the HC-SR04 ultrasonic sensor at the servo rack.

Step 1: Motor Cabling and Assembly

For a 4 WD car all motors of one side should run at the same speed so both motors are supplied by the same power source.

I mounted the motors with the terminals side by side and therefore plus and minus connections must be swapped between the front and left motor. Plus and minus must also be swapped between the left and right motors.

The optical interruptors are useless without slot-type photo interrupters mounted and an elaborated software support, but they look cool in a special way :-)

Step 2: Chassis Flavors

The chassis can be built in 2 flavors, with one or two decks. The two deck version maybe more sturdy, especially if you put foam bumpers at front and back, while the 1 deck version looks more sportive. It also allows to mount the distance sensor below the deck, which enables it to detect even small obstacles.

For the 2 deck version the motors are mounted at the bottom deck, and all the other parts are mounted at the top deck.

Here you find an assembly video for the 2 deck chassis.

Step 3: Ultrasonic Distance Servo Mounting

Mounting the delivered servo and ultrasonic distance sensor requires manual work, since it is not supported out of the box.

Step 4: Battery Holder and Power Switch

If you use the provided M3 screws to attach the battery holder, the 2 outmost batteries will no longer fit seamlessly. So use 5 mm drill to drill an indentation for the M3 screws and mount the holder using the rectangle holes at the back of thr top deck.

The outmost rectange hole must be widened e.g. by drill or a soldering iron :-) for a big toggle switch to fit through.

If you have the possibility to recharge Li-ion 18650 cells, you should consider to use a battery case for two 18650 Li-ion batteries instead and connect it to the Uno power jack.

Step 5: Motor and Arduino Power Supply

As supply voltage we have 6 volt or even only 4.8 volt, if we use NIMH batteries. In this configuration, it is no fun to use a L298 motor driver, which has a loss of 2 volt. The TB6612 driver breakout board costs around 3 to 5 € and has no loss!

Nevertheless, the L298 driver is supported by the motor control library too.

The Arduino UNO board cannot supplied by the 6 volts of the 4 AA batteries directly, it is only specified up to 5 volt.

You can use the GND and VCC terminals of the Sensor Shield for power connection instead of the UNO power jack. The V pins of the digital output row on the Sensor Shield are always connected with VIN (battery) and not with the UNO VCC (5V). This improves servo performance, but may destroy any 5 volt logic circuit, if they use the V pins for power supply. Therefore using the GND and VCC terminals is not recommended for a 2 LI-ion supply, in this case you must use the UNO power jack! Otherwise it will likely destroy the SG90 servo, which is specified up to 6 volt.

The Arduino is now supplied with VIN - 0.9 volt, and runs down to aproximately 3.5 volt.

If you are using 4 NIMH rechargeable AA batteries, you should keep the SEL bridge, which connects the VIN with the Arduino 5 volt. This avoids the 0.9 volt loss of the 5 volt regulator and some resets if the batteries are weak and the motors start.

Step 6: Control Connections

The actual connection between the Sensor Shield and the servo, the ultrasonic sensor and the motor driver is of course software dependent. Here are the definitions used by the PWMMotorControl Arduino library. The line marked with AVR (UNO) (line 37) shows the relevant connections for us.

To connect the motor driver you can use the 15 cm cables inteded for the IR obstacle detection curcit or use extra12 cm female-female dupont wires.

Do not forget to connect the Arduino VCC and GND with the VCC and GND terminals of the TB6612 board.

Step 7: Motor Test

If you see errors like this

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x006c
0xc4 != 0xd4
avrdude: verification error; content mismatch

during upload try to use another USB connection cable or to temporarily disconnect the Sensor Shield from the UNO board or switch the battery power on while uploading.

If the motors rotate in the wrong direction, you have to swap the motor connections (A,B)O1 and (A,B)O2, or the (A,B)IN1 and (A,B)IN2 connectors on the TB6612 board.

Step 8: Distance Sensor and Servo Test

To test your distance sensor, upload the SmartCarFollowerSimple example to the UNO board.

After booting, the servo should move to 135 and 45 degree and then back to 90 degree.

For distances above 30 cm you should hear a tone of 1500 Hz, for distances below 20 cm 666 Hz, and for distances between 1000 Hz.

The car moves forward and backwards in order to keep a distance between 30 and 30 cm to the obstacle.

Take care, that the line with the right configuration e.g. #define TBB6612_4WD_4AA_BASIC_CONFIGURATION or #define TBB6612_4WD_4NIMH_BASIC_CONFIGURATION is activated before compile!

Step 9: Basic IR Control

Attach the TL1838 IR receiver module to the SD+ connector of the Sensor Shield. Do not use the row, where the buzzer and the motor driver is attached, since the middle V pin there is connected with VIN, which may have 6 volt and therefore will destroy the TL1838.

Basic IR-remote car control like move and turn is implemented in the BasicIRControl example.

Mapping between keys of any arbitrary IR remote sending NEC protocol (all the cheap china ones) and car commands can easily be achieved in IRCommandMapping.h.

To support your mapping, the received IR code is printed at the serial output if `INFO` is defined (default).

Step 10: Modify SensorShield for Bluetooth Module HC05

For Bluetooth control, I use a HC05 bluetooth modul and connected it to the UART pins of the Sensor Shield.

To avoid another set of cables, I changed the original male UART pin header row to a female row. Desoldering (and soldering) can be done by heating all 4 pins simultaneously, with the help of a lot of solder.

Step 11: Smartphone Control

If you have added a bluetooth module, you can control your car by your smartphoneusing the RobotCarBlueDisplay example of the BlueDisplay Arduino library. On your Android smartphone you need to install the Android BlueDisplay app.

The Bluetooth module can be modified by means of the BTModuleProgrammer example from the BlueDisplay library to have a unique name and to support 115200 baud.

Do not forget to remove the Bluetooth module during programming of the UNO, otherwise you will get errors like:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xa5

Take care, that the line with the right configuration e.g. #define TBB6612_4WD_4AA_FULL_CONFIGURATION is activated before compile!

Step 12: Deterministic Turns and Distances With MPU6050 IMU

The Arduino library supports usage of a MPU6050 IMU module to go fixed distances and do determinist turns. But it is still not fully tested for this type of robot car.

Step 13: Remarks

I hope you have fun with the car, I especially enjoy the sensor drive function with bluetooth.

This cars and the library are for my Arduino AG class at the Montessory Gymnasium.

This Instructable and the library are still work in progress (9/2022).

If you have improvement requests, do not hesitate to use the github discussions function of the library.

It would be a pleasure to hear from you, if you use this instructions or the library for your own projects.

Armin