Sunday, January 10, 2016

S4A (Scratch for Arduino) Project - A Keyboard Controlled Robot Car

A fun project to create a keyboard controlled robot car... based on the "Robotics: keyboard driven car" project on the S4A site. This to me, is a perfect example of an interdisciplinary project: there is quite a bit of mechanical, electrical and computer engineering involved. This project is being used by the Grade 5 kids in my child's school this year; the kids have been working with the Pro-Bot for quite a bit of time and I felt that letting them create their own robot car that behaves similar to the Pro-Bot is a great finale. So far, it's my favorite Arduino project. Below is a formal lesson plan for the robot car.

Note: This is a simplified version of the car from the S4A site - it just involves creating the keyboard driven car, minus the remote controller. This means the car stays connected to the laptop via the USB cable.


Design your own robot car, whose movements can be controlled via the arrow keys on your keyboard. The car should move forward & backward, and turn left & right, controlled by the corresponding arrow keys.


The students learn to build a basic robot, using motors to drive its wheels and learn to control it via reactive programming.

Computer Science Concepts

  • Reactive programming
  • Conditionals
  • Forever loops

Classroom Standards


  • Software Development Environment: S4A
  • Arduino Uno
  • USB cable connecting the Arduino to the laptop
  • Bread board
  • 2 Servo Motors - continuous rotation (Parallax continuous rotation servos used here)
  • Wheels to attach to the Servos 
  • Batteries to power the servos (3 x 1.5 V AA, per servo)
  • 2 Battery holders
  • Jumper wires (easier if you color code them)
  • Sturdy base to attach the wheels, motors and the control unit 
  • Any extra materials needed for balancing the car structure, like the caster wheel used here
  • Other materials for constructing the car such as tape, etc. (velcro tape works well)


2 hours approx.

Lesson Plan Links from S4A

The lesson plan developed by the S4A team is provided in the link below. It includes the S4A code for programming the car. We shall use Example 2: Robot Controlled with Keyboard:


Start off by introducing the students to the assignment & its requirements. The main job would be to introduce the students to the servo motor and its operation. Discuss what motors are & how they convert electrical energy into kinetic energy. Go through a few examples of where/how motors are seen/used in our daily lives.

The pins used by S4A for the servos on Arduino are Digital 4 & Digital 7. Demonstrate to the students how the servo motor can move clockwise & anticlockwise, using the corresponding instructions on the S4A platform. It is helpful if the programming concepts used in this project - reactive programming & conditionals - are familiar to the students.

The students could spend some time assembling the car. A stable structure that can support the bread board, wheels, battery & the control unit needs to be built. A sturdy base should be used on which the Arduino & the breadboard can be mounted on top. There are several models of car chassis available on Amazon, specifically for mounting the Arduino boards, if you prefer to use those. Here, I have tried to create the car chassis out of pieces of wood... the reason being to let the kids see that they do have the option to assemble the car with simple materials, rather than a purchased kit.

Also, I used velcro tape to attach various components as needed to the base, so that they can be easily disassembled later on (a really important factor while sharing the materials among multiple classrooms). The caster wheel was attached with screws, for more stability. The same for the piece of wood holding the servos firmly to the base.

The servo motors could be mounted on the top or bottom portion of the base, such that the servo wires can be connected to the breadboard. A couple of battery packs would also be required to power the servos. I chose to go with the servos on the bottom of the wooden base. The wheels attached to the servos serve as the driver wheels, while a caster wheel that can turn in all directions makes up the front wheel. The battery packs are placed close to the breadboard to make the wiring easier. Note that we are not using a remote controlled version of the car here, hence the unit will still be connected via the USB cable to the laptop. Hence, you need to keep an eye out on how far your car moves.


Color coding the jumper wires used for the connections would make it really easy for the kids to do the wiring. I have provided step-by-step wiring diagrams as part of the slides.

The Assembled Car...

Top view of the car

Servo motor attached to a wheel

Caster wheel in front to balance the structure
Velcro Tape used to attach the various components easily to the base

Program the Car

The direction in which you get the servo motors to turn - clockwise or anticlockwise - controls the movement of the car. Use reactive programming to control the motor directions for up, down, left and right arrow keys. The complete program for the car is provided in the S4A lesson plan link. In fact, two options for programming the car are provided in the link...

I personally prefer Option 2 for this version of the car (attached to the laptop via the USB cable), as it operates only if a key is pressed.

Option 1
Option 2

To summarize the class, discussing the working of the motors and the reactive programming used. Compare and contrast the two options provided for programming the car.

The Final Product

Coming up next, part 2 of this project -->  the robot car modified to have indicator lights...

1 comment:

  1. Looks good but my servos only go 180 degrees before stopping and hacking the servo motor looks complicated!