Introduction: Arduino Uno and Visuino: Control Smart Car Robot With Joystick and L298N Motor Driver

Smart Car sets when combined with L298N Motor Driver Modules, offer one of the easiest ways to make robot cars. The L298N Motor Driver Module is easy to control with Arduino, and with the help of Visuino you can program your car in seconds.

In this Instructable I will show you how easy it is to control a Smart Car with an analog Joystick. In the following Instructables I will show you more interesting and complex robot designs, so stay tuned ;-)

Please note that the annotation on some of the pictures in this Instructable will work correctly on some browsers only after you click on the image to expand it.

Please make sure you click on the image to see the annotation showing the correct spot on the image!

Step 1: Components

  1. One Smart Car chassis with 2 DC motors, gears and wheels
  2. One Arduino board (I used Arduino UNO, but any other will be just fine)
  3. One L298N Dual Motor Driver Module
  4. One Joystick that I got from this cheap 37 sensors set
  5. One USB Power supply with USB Cable (I used a USB Power Bank but any other option will work)
  6. 2 Male-Male jumper wires
  7. 8 Female-Male jumper wires

Step 2: Connect the Joystick to Arduino

  1. Connect Female-Female wires to the Ground(Black wire), Power(Red wire), VRx(Brown wire), and VRy(Orange wire) of the Joystick as shown in Picture 1
  2. Connect the VRx wire(Brown wire) the the Analog 1 pin of the Arduino board (Picture 2)
  3. Connect the VRy wire(Orange wire) the the Analog 0 pin of the Arduino board (Picture 2)
  4. Connect the Ground wire(Black wire) to the Ground pin of the Arduino board (Picture 2)
  5. Connect the Power wire(Red wire) to the 5V(Called IOREF on most boards) Power pin of the Arduino board (Picture 2)
  6. Picture 3 shows the Arduino Uno pins that were connected in this step

Step 3: Connect the Motors to the L298N Motor Driver Board

  1. Connect the wires from one of the motors to the OUT1 and OUT2 Motor Control pins of the L298N Motor Driver Module (Picture 1)
  2. Connect the wires from one of the motors to the OUT3 and OUT4 Motor Control pins of the L298N Motor Driver Module (Picture 2)
  3. Pictures 3 shows the connected wires to the L298N Motor Driver Module
  4. Picture 4 shows the other end of the wires connected to the Motors and the 0.1uF anti-sparkingcapacitors soldered to the Motors as shown in this Instructable

Step 4: Connect Power to the L298N Motor Driver Board

  1. Connect Male-Male Power wire(Red wire) to the +12V Power Pin of the L298N Motor Driver Module (Picture 1 and 2)
  2. Connect Male-Male Ground wire(Black wire) to the Ground Pin of theL298N Motor Driver Module (Picture 1 and 2)
  3. Connect the other end of the Ground wire(Black wire) to the Ground Pin of the Arduino board (Picture 3)
  4. Connect the other end of the Power wire(Red wire) to the 5V Power Pin of the Arduino board (Picture 3)
  5. Picture 4 shows in Red the Arduino Uno pins that were connected in this step. In Blue are shown the connections done in the previous steps

Step 5: Connect the L298N Motor Driver Board Control Pins to Arduino

  1. Leave the ENA and ENB jumpers on the L298N Motor Driver Module (Picture 1)
  2. Connect the Female end of a Female-Male wire(Control 1)(Purple wire) to the IN1 pin of the L298N Motor Driver Module (Picture 1)
  3. Connect the Female end of a Female-Male wire(Control 2)(Blue wire) to the IN2 pin of theL298N Motor Driver Module (Picture 1)
  4. Connect the Female end of a Female-Male wire(Control 3)(Green wire) to the IN3 pin of theL298N Motor Driver Module (Picture 1)
  5. Connect the Female end of a Female-Male wire(Control 4)(Yellow wire) to the IN4 pin of the L298N Motor Driver Module (Picture 1)
  6. Connect the other end of the Control 1 wire(Purple wire) to the Digital 2 Pin of the Arduino board (Picture 2)
  7. Connect the other end of the Control 2 wire(Blue wire) to the Digital 3 Pin of the Arduino board (Picture 2)
  8. Connect the other end of the Control 3 wire(Green wire) to the Digital 4 Pin of the Arduino board (Picture 2)
  9. Connect the other end of the Control 4 wire(Yellow wire) to the Digital 5 Pin of the Arduino board (Picture 2)
  10. Picture 3 shows in Red the Arduino Uno pins that were connected in this step. In Blue are shown the connections done in the previous steps

Step 6: Add Power and Secure the Lose Components to the Car Chassis

  1. Add a USB power source (In my case a rechargeable USB power bank) (Picture 1)
  2. Use straps, rubber bands, screws or any other convenient ways to secure the wires and boards to the chassis (Pictures 1, 2 and 3)

Step 7: Start Visuino, and Add Steering Differential, and Motor Driver Bridge Components

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.5 or 1.6.7, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Type "steer" in the Filter box of the Component Toolbox then select the "Steering Differential" component (Picture 1), and drop it in the design area.
    This component will calculate the speed of the left and right motors based on the Speed and Direction from the Joystick (X and Y control)
  3. Type "motor" in the Filter box of the Component Toolbox then select the "Dual DC Motor Driver 2 Pin Bridge (L9110S, L298N)" component (Picture 2), and drop it in the design area
    Since we left the ENA and ENB jumpers on the L298N Motor Driver module, we will control it with only 2 pins per motor. Visuino also includes a component to control it with the 3 pins, if the jumpers are disconnected, but this is not necessary

Step 8: In Visuino: Connect the Steering Differential Component

  1. Connect the Out" pin of "Digital[ 14 ]/AnalogIn[ 0 ]" channel of the Arduino component to the "Direction" input pin of the Steering1 component (Picture 1)
  2. Connect the "Out" pin of "Digital[ 15 ]/AnalogIn[ 1 ]" channel of the Arduino component to the "Speed" input pin of the Steering1 component (Picture 2)
  3. Connect the "Left" pin of the "Motors" pin list of the Steering1 component to the "In" pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component (Picture 3)
  4. Connect the "Right" pin of the "Motors" pin list of the Steering1 component to the "In" pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component (Picture 4)

Step 9: In Visuino: Connect the Motor Driver Bridge Component

  1. Connect the "Direction(B)" output pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 2 ]" channel of the Arduino component (Picture 1)
  2. Connect the "Speed(A)" output pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component to the "Analog" input pin of "Digital[ 3 ]" channel of the Arduino component (Picture 2)
  3. Connect the "Direction(B)" output pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 4 ]" channel of the Arduino component (Picture 3)
  4. Connect the "Speed(A)" output pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component to the "Analog" input pin of "Digital[ 5 ]" channel of the Arduino component (Picture 4)

Step 10: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 11: And Play...

Congratulations! You have completed the project.

The Video shows the connected and powered up Smart Car.

If you connect the Power to the Arduino board, you can use the Joystick to control the car by moving the Joystick forward and backward the car will move in the Forward or Backward direction, and moving the Joystick left and right will make the car turn left and right.

If the car is not moving as expected, you may need to swap the wires controlling the motors connected in Step 3 to make them rotate in the proper direction.

On the Picture you can see the complete Visuino diagram.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016