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

20,549

89

30

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

3 People Made This Project!

Recommendations

  • First Time Author

    First Time Author
  • Big and Small Contest

    Big and Small Contest
  • PCB Contest

    PCB Contest

30 Discussions

0
None
BoianMSuryaprakashG

Answer 10 months ago

You control it directly with the Joystick in this project :-)

0
None
jrchrist

1 year ago

Thank you for the instructable. I wired and uploaded the code, but am not getting any motor movement. I am using an ELEGOO UNO R3, so I'm not sure if that is affecting it instead of using the Arduino UNO. Please let me know if you can help.

Thanks

1 reply
0
None
BoianMjrchrist

Reply 1 year ago

This should work almost exactly the same with ELGOO :-) . I will try to post a tutorial one of this days, if the time permits...

0
None
ehsan55

1 year ago

Thanks to know me that visuino program. great work

1 reply
0
None
BoianMehsan55

Reply 1 year ago

You are Welcome! Enjoy :-)

0
None
AnkitK99

1 year ago

hello,

I really appreciate your work, nicely done. i have few queries as well, can we add obstacle avoiding feature by adding ultrasonic sensor in this Smart Car Robot using Visuino, how to make connection in this case and how to specify distance in Visuino. thanks in advance

2 replies
0
None
BoianMAnkitK99

Reply 1 year ago

Thank you! I am already preparing such tutorial as well as number of other tutorials, so stay tuned ;-) . If I am not mistaken, I already sent you project over e-mail earlier today ;-)

0
None
RaadA2

1 year ago

nice work .

what about if i want use 4 motor what should i do in Visuino???

0
None
BoianMYaraP

Reply 1 year ago

The coding is done by creating Visuino design. Visuino generates the code automatically.

0
None
joeyzh

2 years ago

Thank you so much for such brilliant idea. I saw another motor car control using Arduino compatible platform and control through cellphone using wifi. (http://www.amebaiot.com/en/ameba-arduino-amebamotors-mobile/)

1 reply
0
None
CristiG4

2 years ago

It can work with a motor shiel Monster or only works with the L298N?

3 replies
0
None
BoianMCristiG4

Reply 2 years ago

I don't have it and can't test, but the Sparkfun site lists it as Full Bridge, and according to this, and from the schematics, it should work :-) . Let me know if you have problems with it, and I can take a further look.

0
None
CristiG4BoianM

Reply 2 years ago

I tried the code with the monster bridge but It didn't work, I mean the monster bridge uses two direction signals and one pwm. How can I modify the visuino code to do that?

0
None
BoianMCristiG4

Reply 2 years ago

The L298N also has the option to be controlled with 3 signals (2 directions and PWM).

There are 2 options:

1. Set the PWM pin to +5V as I did in this Instructable with the jumpers, and connect the PWM to one of the direction pins

OR:

2. Use the "Dual DC Motor Driver 3 Pin Bridge(L298N)" component instead. It is designed to use the 3 pins.