Program Infrared Remote Controlled Arduino Smart Car Robot With Visuino

by BoianM in Circuits > Arduino

12915 Views, 33 Favorites, 0 Comments

Program Infrared Remote Controlled Arduino Smart Car Robot With Visuino

Visuino Video Tutorial: Program Infrared Remote Controlled Arduino Smart Car Robot with Visuino

Recently I received a Smart Car Robot Kit donated by Elegoo for the Visuino development, and I already posted a Tutorial on how to assemble the Kit.

Here I will show you how easy it is to program the Robot with Visuino so you can control it with Infrared Remote.

Components

DSC06150.JPG
DSC04984.JPG
582fc1d7e02ad6fcd9000186.jpeg

One assembled Elegoo Smart Car Robot car and the Infrared Remote included in the kit (Picture 1)

Pictures 2, and 3 show the unassembled kit.

Here is a Tutorial on how to assemble the robot.

Start Visuino, and Add Motor Driver Bridge Component

ComponentMotors.png

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

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

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

  1. Start Visuino as shown in the Picture
  2. Type "motor" in the Filter box of the Component Toolbox then select the "Dual DC Motor Driver 3 Pin Bridge(L298N)" component (Picture), and drop it in the design area

In Visuino: Connect the Motor Driver Bridge Component

ComponentMotorsConnect1.png
ComponentMotorsConnect2.png
ComponentMotorsConnect3.png
ComponentMotorsConnect4.png
ComponentMotorsConnect5.png
ComponentMotorsConnect6.png
  1. Connect the "Forward" output pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 7 ]" channel of the Arduino component (Picture 1)
  2. Connect the "Reverse" output pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 6 ]" channel of the Arduino component (Picture 2)
  3. Connect the "Speed" output pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component to the "Analog" input pin of "Digital[ 5 ]" channel of the Arduino component (Picture 5)
  4. Connect the "Forward" output pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 8 ]" channel of the Arduino component (Picture 1)
  5. Connect the "Reverse" output pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component to the "Digital" input pin of "Digital[ 9 ]" channel of the Arduino component (Picture 2)
  6. Connect the "Speed" output pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component to the "Analog" input pin of "Digital[ 10 ]" channel of the Arduino component (Picture 5)

In Visuino: Add, Configure, and Connect 2 "Ramp to Value" Components

ComponentRamp.png
ComponentRampProperty1.png
ComponentRampProperty2.png
ComponentRampConnect1.png
ComponentRampConnect2.png

You can control the motor speeds directly, however if you suddenly change the motor from stopped to full speed, or from full speed to stop, this will make the robot movements "jumpy", and may lead to wheels easily detaching from the robot. It is better to speed up and slow down the motors gradually using a ramp. Visuino includes "Ramp To Value" component designed for such purpose.

  1. Type "ramp" in the Filter box of the Component Toolbox then select the "Ramp To Value" component (Picture 1), and drop 2 of them in the design area
  2. Select the 2 "Ramp To Value" components (Picture 2)
  3. In the Object Inspector, set the value of the "Initial Value" property to "0.5" (Picture 2) - this specifies that the motors will initially be off
  4. In the Object Inspector, set the value of the "Slope" property to "2" (Picture 3) - this will specify how fast the motors will ramp up and down
  5. Connect the "Out" output pin of the RampToValue1 component to the "In" input pin of the "Motors[ 0 ]" channel of the DualMotorDriver1 component (Picture 4)
  6. Connect the "Out" output pin of the RampToValue2 component to the "In" input pin of the "Motors[ 1 ]" channel of the DualMotorDriver1 component (Picture 5)

In Visuino: Add "Analog Value" Component, and Add 4 "Set Value State" Elements

ComponentValue1.png
ComponentValue1Property.png
ComponentValue1AddElements.png
AddSetValueState.png
ComponentValue1Element1Property.png
ComponentValue1Element2Property.png

To control the motor speeds for the 4 commands from the remote (Forward, Backward, Left, and Right), and the Stop, we can use "Analog Value" component for each motor with value 0.5 - Stop, and 4 "Set Value State" elements specifying the motor speeds for the 4 commands.

  1. Type "analog value" in the Filter box of the Component Toolbox then select the "Analog Value" component (Picture 1), and drop it in the design area
  2. In the Object Inspector set the value of the "Value" property of the AnalogValue1 component to "0.5" (Picture 2) - this will make sure the motor is off by default
  3. Click on the "Tools" button of the AnalogValue1 component to open the "Elements" dialog (Picture 3)
  4. In the "Elements" editor select the "Set Value State" in the right window, and clicking on the "+" button 4 times (Picture 4) to add 4 of them
  5. In the Elements Editor select the "Set Value State1" (Picture 5)
  6. In the Object Inspector set the value of the "Value" property of the element to "1" (Picture 2) - this will specify the motor to rotate forward
  7. In the Elements Editor select the "Set Value State2" (Picture 6)
  8. In the Object Inspector set the value of the "Value" property of the element to "1" (Picture 3)
  9. Leave the other 2 Elements unchanged. The value of the "Value" property for them will be "0" - this will specify the motor to rotate backward
  10. Close the "Elements" editor

In Visuino: Add Another "Analog Value" Component, and Add 4 "Set Value State" Elements

ComponentValue2.png
ComponentValue2Property.png
ComponentValue2Tools.png
AddSetValueState.png
ComponentValue2Element1Property.png
ComponentValue2Element4Property.png
  1. Type "analog value" in the Filter box of the Component Toolbox then select the "Analog Value" component (Picture 1), and drop it in the design area
  2. In the Object Inspector set the value of the "Value" property of the AnalogValue1 component to "0.5" (Picture 2)
  3. Click on the "Tools" button of the AnalogValue1 component to open the "Elements" dialog (Picture 3)
  4. In the "Elements" editor select the "Set Value State" in the right window, and clicking on the "+" button 4 times (Picture 4) to add 4 of them
  5. In the Elements Editor select the "Set Value State1" (Picture 5)
  6. In the Object Inspector set the value of the "Value" property of the element to "1" (Picture 2)
  7. In the Elements Editor select the "Set Value State4" (Picture 6)
  8. In the Object Inspector set the value of the "Value" property of the element to "1" (Picture 3)
  9. Leave the other 2 Elements unchanged
  10. Close the "Elements" editor

In Visuino: Connect the 2 "Analog Value" Components

ComponentValue1Connect.png
ComponentValue2Connect.png
  1. Connect the "Out" output pin of the AnalogValue1 component to the "In" input pin of the RampToValue1 component (Picture 1)
  2. Connect the "Out" output pin of the AnalogValue2 component to the "In" input pin of the RampToValue2 component (Picture 2)

In Visuino: Add Infrared Receiver Component, and Add 4 Decode NEC Command Elements to It

ComponentInfrared.png
ComponentInfraredTools.png
ComponentInfraredAddElements.png

To decode the infrared commands, we will add Infrared Receiver component. The simplest way to decode a specific command is to add Decode element to the Infrared Receiver Elements: We will add 4 such elements for the 4 commands - Forward, Back, Left and Right.

  1. Type "infra" in the Filter box of the Component Toolbox then select the "Infrared Receiver" component (Picture 1), and drop it in the design area
  2. Click on the "Tools" button of the InfraredReceiver1 component to open the "Elements" dialog (Picture 2)
  3. In the "Elements" editor select the "Decode NEC Command" in the right window, and clicking on the "+" button 4 times (Picture 3) to add 4 of them

In Visuino: Configure the 4 Decode NEC Command Elements

ComponentInfraredElementsRepear.png
ComponentInfraredElement1Property.png
ComponentInfraredElement2Property.png
ComponentInfraredElement3Property.png
ComponentInfraredElement4Property.png
  1. In the Elements Editor select the 4 Decode NEC Command elements (Picture 1)
  2. In the Object Inspector set the value of the "Repeat Interval" property of the element to "200" (Picture 1)
  3. In the Elements Editor select the "Decode NEC Command1" (Picture 2)
  4. In the Object Inspector set the value of the "Value" property of the element to "16736925" (Picture 2) - This will specify the Infrared button code. You can follow this tutorial to discover the codes for each button of your remote
  5. In the Elements Editor select the "Decode NEC Command2" (Picture 3)
  6. In the Object Inspector set the value of the "Value" property of the element to "16761405" (Picture 3)
  7. In the Elements Editor select the "Decode NEC Command3" (Picture 4)
  8. In the Object Inspector set the value of the "Value" property of the element to "16754775" (Picture 4)
  9. In the Elements Editor select the "Decode NEC Command4" (Picture 5)
  10. In the Object Inspector set the value of the "Value" property of the element to "16720605" (Picture 5)
  11. Close the "Elements" editor

In Visuino: Connect the First 2 Decode NEC Command Elements

ComponentInfraredConnect1.png
ComponentInfraredConnect2.png
ComponentInfraredConnect4.png
ComponentInfraredConnect3.png
  1. Connect the "Out" output pin of the "Elements.Decode NEC Command1" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State1" of the AnalogValue1 component (Picture 1)
  2. Connect the "Out" output pin of the "Elements.Decode NEC Command1" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State1" of the AnalogValue2 component (Picture 2)
  3. Connect the "Out" output pin of the "Elements.Decode NEC Command2" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State2" of the AnalogValue1 component (Picture 3)
  4. Connect the "Out" output pin of the "Elements.Decode NEC Command2" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State2" of the AnalogValue2 component (Picture 4)

In Visuino: Connect the Rest of the Decode NEC Command Elements, and the Infrared Receiver Component

ComponentInfraredConnect5.png
ComponentInfraredConnect6.png
ComponentInfraredConnect7.png
ComponentInfraredConnect8.png
ComponentInfraredConnect9.png
ComponentInfraredConnect10.png
  1. Connect the "Out" output pin of the "Elements.Decode NEC Command3" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State3" of the AnalogValue1 component (Picture 1)
  2. Connect the "Out" output pin of the "Elements.Decode NEC Command3" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State3" of the AnalogValue2 component (Picture 2)
  3. Connect the "Out" output pin of the "Elements.Decode NEC Command4" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State4" of the AnalogValue1 component (Picture 3)
  4. Connect the "Out" output pin of the "Elements.Decode NEC Command4" element of the InfraredReceiver1 component to the "In" input pin of the "Elements.Set Value State4" of the AnalogValue2 component (Picture 4)

Generate, Compile, and Upload the Arduino Code

Generate.png
ArduinoIDE.png
  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)

If you get compiler error in the Arduino IDE, this means that you are missing the following library:

https://github.com/z3t0/Arduino-IRremote

Look at this Tutorial to see how to install it!

And Play...

VisuinoDiagramCrop.png
Program Infrared Remote Controlled Smart Car Robot with Visuino

Congratulations! You have a full Infrared Remote control over your Smart Car Robot.

If you power up the Smart Car Robot, you can control it by pressing on the Arrow buttons of the Infrared Remote as shown on the Video.

On the Picture you can see the complete Visuino diagram.

Also attached are the Visuino projects, that I created for this Tutorial. You can download and open them in Visuino: https://www.visuino.com