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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Comments

jrchrist (author)2017-10-20

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

BoianM (author)jrchrist2017-10-21

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

ehsan55 (author)2017-10-17

Thanks to know me that visuino program. great work

BoianM (author)ehsan552017-10-17

You are Welcome! Enjoy :-)

hujjatr made it! (author)2017-10-07

hi..
i have made this project following every instruction of yours..thanks a lot..
and I also appreciate all your work..Could you please help me in making this project be converted into wireless..like being controlled through an android app..
really sorry for the bad quality of the image..
I will be waiting for your reply..
thank you again

BoianM (author)hujjatr2017-10-07

You are Welcome!
I actually posted one tutorial on Android controlled robot, and plan more advanced and interesting version soon ;-)
Here is the current video tutorial ;-)
https://youtu.be/QftNBvhsLi4

hujjatr (author)BoianM2017-10-08

i have seen your video tutorial but it has no insight for the construction of the robotic car..
could you guide me through this , the same way you did in this instructable..

BoianM (author)hujjatr2017-10-08

Here is tutorial I did for Elegoo V1:

https://www.instructables.com/id/Assemble-Elegoo-S...

And here is for Elegoo V2:

http://labpacks.blogspot.com/2017/08/assemble-eleg...

I am still posting the videos on V3:

http://labpacks.blogspot.com/2017/10/assemble-eleg...

Hopefully will finish them in few days :-)

TaysirF made it! (author)2017-09-08

that's good also you could move it bu your phone with Bluetooth it will be better

BoianM (author)TaysirF2017-10-07

Congratulations!

I already have done couple of Bluetooth versions, and plan more ;-)
Here is one:

https://youtu.be/QftNBvhsLi4

AnkitK99 (author)2017-04-21

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

BoianM (author)AnkitK992017-04-21

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 ;-)

AnkitK99 (author)BoianM2017-04-21

Yes Boian. :-)

RaadA2 (author)2017-02-23

nice work .

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

YaraP (author)2017-02-22

were is the codeing ?

BoianM (author)YaraP2017-02-22

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

joeyzh (author)2016-06-02

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/)

BoianM (author)joeyzh2016-06-02

Thank you!

I also posted one doing remote control over WiFi with Wii controller and 2 ESP8266 ;-)
https://www.instructables.com/id/ESP8266-and-Visuin...
Probably will also post one with Bluetooth LE and Arduino 101 soon ;-) Will see...

paulsantony6 (author)2016-05-02

Good

BoianM (author)paulsantony62016-05-02

Thank you! :-)

Neiljams made it! (author)2016-04-05

Fun and easy just how i like it. Thanks for sharing!?

BoianM (author)Neiljams2016-04-06

Thank you! Congratulations on making it :-) Looks great!

CristiG4 (author)2016-03-05

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

BoianM (author)CristiG42016-03-05

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.

CristiG4 (author)BoianM2016-03-18

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?

BoianM (author)CristiG42016-03-18

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.

ponchocreedo (author)2016-03-04

Is there any way to get this code as a regular ide file? Even plain text would work. Visuino is complicated to install in my classroom and this is exactly what we are building for our local robot games.

BoianM (author)ponchocreedo2016-03-04

Yes, I can send you the currently generated Arduino IDE code. It will work with the current version of the Visuino libraries that you can download from here:

https://bitbucket.org/mitov/visuino-libraries

However the libraries change as Visuino is and the code generation is developed, and the code that I will send you will not work with future versions of the libraries. It is always best to generate the code with Visuino so it will be compatible with the libraries.

You can contact me at mitov@mitov.com to get the generated code with the current Visuino version.

darth-vader1 (author)2016-02-25

id follow all the steps but unfortunately I do not have the control 1 (purple) wire and also instead of using a Arduino joystick I'm using a pi

BoianM (author)darth-vader12016-02-26

:-D I think you can use other color. Unfortunately RPi is not yet supported by Visuino :-( , but I hope this will change soon...

farraha (author)2016-02-16

That's wonderful!

BoianM (author)farraha2016-02-16

Thank you! Enjoy :-)

TimothyJ999 (author)2016-02-09

I bought that cheap 37-sensor kit when I first got started with Arduino, and I'd completely forgotten about the joystick that came with it! Thanks for reminding me and for supplying a code example. Lots of possibilities!

BoianM (author)TimothyJ9992016-02-09

I am glad :-) Enjoy! I actually had a lot of fun already with this sensor set ;-)

camflht (author)2016-02-08

Excellent Instructable, with very precise written directions and clear photos. This is one of the best I've seen.

BoianM (author)camflht2016-02-08

Thank you! :-)

About This Instructable

17,754views

89favorites

License:

More by BoianM:Program Arduino UNO With Visuino to Draw on ILI9341 TFT Touchscreen Display Shield With PenAssemble Kuman Wi-Fi Robot With Camera and ManipulatorArduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields
Add instructable to: