Shopping Cart

How to Build Your Own Car Robot - Part 3: Control and programming

Posted by on

Introduction

In this blog, as promised in part 1 and part 2, we will show how you can program the car robot that you have built. 

What you need extra:

  • Motor driver
  • 2x long zip paired wires
  • 4xAA battery case
  • Keyboard
Step 1) Motor driver

You need to connect the positive and negative terminals of the battery to the power input socket of the motor driver. Use a screw driver to open up the gap so the wire can slide through and then tighten the screws to secure the connection. 

Then connect the two long paired wires to the Motor A and Motor B inputs on the motor driver as you did with the battery wires. The other end will connect to the motors. The motor driver essentially flips the polarity of the input power to the motor to allow the motor turn clockwise or counter-clockwise as needed.

 

Step 2) Connecting raspberry pi to motors

Push the other ends of the paired wires through the chassis holes and then connect it to the motor wires by twisting the leads. To avoid the power and ground touching, use tape to cover any exposed leads. 

 

Step 3) Download code and run

Download the code from here to your pi using the browser on the desktop task bar.

Then launch Minecraft pi from the desktop Menu> Games> Minecraft Pi. Start a new world and then minimize the Minecraft window and launch the terminal from the  desktop task bar. 

To navigate to the place where you've downloaded the code type

> cd Downloads/

Then unzip and go inside the folder to run the code by

> unzip RobotMove/

> cd RobotMove/

>sudo python robot.py

Now minimize the terminal window and go back to Minecraft.

Step 4) Program

The following coding platform should load up. The are two red tapes that record instructions for the left and right motors. Right clicking on the the tape changes the color of the block. The green block tells the motor to go forward and blue tells it to go backward. 

 

Step 5) Compile

Once you are done with coding your robot, approach the crafting table and hit it with your sword/wrench to run instructions on the car. 

 

 

 

Activity

Set a obstacle challenge and see if you can program your robot to move around the obstacle to reach your destination ☺

 


Older Post Newer Post