Skip to content
Tiogaplanet edited this page Oct 23, 2019 · 13 revisions

Welcome to the Arduino_Smart_Car wiki!

Here you will find the documentation for using the library to make programming your Smart Car quick and easy. But first we'll need to make some minor hardware changes to the car to get this library working. So follow the guide below and then check out the API.

Table of contents

  1. Requirements
  2. Hardware Changes
    1. Connections
    2. Errata
  3. Functions
  4. Examples

Requirements

Hardware

In addition to the VKmaker Smart Car kit you will also need an LM393 speed sensor.

Software

The Arduino IDE.

Hardware Changes

In addition to the assembly video included on the DVD, there are many good guides available on the Internet. I used Stephen Edwards' instructions as a general guide, taking note of key differences in the VKmaker kit such as a 6-battery box which forces a little reorganization of components, and orientation of the power switch in the acrylic chassis. I won't repeat a full-blown instructions document for assembling the robot here. Rather, I will point out some key changes that must be made to work with the library presented here. I will also present a fix for a couple glaring errors I noticed in assemblying the robot.

If you follow the instructions provided with the kit will get you a robot that spins both motors at full speed. For robots operating on smooth tile or hardwood this will result in the robot failing to gain traction on one or both wheels. If your floors are smooth enough the caster will be a problem too as it won't experience enough rolling friction to track correctly behind the robot. If the caster doesn't track well behind the robot no amount of tinkering with the drive wheels will keep the robot from veering left or right. However, we can tackle the problem of the motors spinning at full speed using PWM and we can tackle the motors operating at slightly different speeds using the speed sensors.

Connections

Pulse Width Modulation

The sketch included with the robot is documented and with some trial and error you can modify it to use PWM allowing better control of the speed of the motors. Strangely, the schematics provided in the kit don't show you how to send PWM to the motor controller. If you are familiar with Arduino it shouldn't be too difficult to re-wire the connections between the Arduino and the motor controller to enable PWM.

Let's address the wiring schematics provided with the kit and get PWM working correctly. The instructions recommend connecting the motor controller using the analog connection block of the Sensor Shield v5.0 and they don't provide any instruction on how to connect the PWM-enable lines. Besides neglecting PWM, the instructions lead us to use the analog pins which are better kept available for actual analog sensors later. There are plenty of available digital pins available on the Sensor Shield. Remove the jumpers on ENA and ENB of the motor controller to enable PWM. Now, let's wire things up like this:

Sensor Shield Motor controller
5 ENA
6 IN1
7 IN2
8 IN3
9 IN4
11 ENB

Servo

The instructions use pin 11 for the servo but we've used pin 11 for the motor controller. Let's wire up the servo like this:

Sensor Shield Servo
V Red
G Brown
12 Orange
A view of the servo wiring from behind.

Ultrasonic Sensor

The instructions use pins 8 and 9 for the ultrasonic module but we've used them for the motor controller too. Let's wire the ultrasonic sensor like this:

Sensor Shield Ultrasonic sensor
V VCC
G GND
10 Echo
4 Trigger
The wiring for the ultrasonic sensor.

Speed Sensors

Next, let's address the issue of matching speeds for the two motors. Remove the motor controller from the chassis. It is too close to the cutout for the speed sensor on the right side and the front left brass standoff on the motor controller will interfere with the speed sensor. Once the standoff is removed from the motor controller you can reinstall the motor controller using the two remaining standoffs and the third that is acting as a support.

The speed sensors can be secured in place with hot glue. If you chose to screw them in place you will have to drill your own holes in the chassis. Wire the sensors to pins 2 and 3 as we will need the external interrupts available on those two pins.

Sensor Shield Left Speed Sensor Right Speed Sensor
V 5V 5V
G GND GND
2 OUT
3 OUT
The right side speed sensor installed in the chassis.

When all changes are made to the electrical connections your wiring and Sensor Shield should look like what you see in the two figures below.

All connections made on the Sensor Shield. A backside view of the connections made on the Sensor Shield.

Errata

Servo

The kit I received contained a servo base with servo arm already installed. The arm was installed incorrectly, with the screws installed through the servo arm first, then through the servo base. Those screws can't be simply turned around as they are too long and will interfere with the body of the servo as it turns. My kit included a small bag containing many small screws and nuts. I was able to find a pair of screws and nuts to replace the incorrectly installed screws. Furthermore, there is a file on the DVD called "Instructions.doc" which direct you to install an M3 * 8 screw (included) through the center of the servo arm and into the servo shaft. Do this after you have replaced the two incorrect screws.

Battery box

Another noticeable error in the instructions is that it instructs you to install the battery box with a single screw. Over time the battery box will pivot away from the chassis as the robot executes sharp turns. This is easily fixed with some drilling and adding a second screw. I chose to fix the problem by using Velcro to affix the battery box to the chassis.

Barrel connector and power switch

Following the instructions for connecting the power switch will leave you with wiring that will always power the Arduino regardless of the position of the switch. Install the ends of the barrel connector wires into the motor controller. Cut the red power line between the battery box and the barrel connector and install the switch there.

Functions

Now that all of the hardware is in place, it's time to look at the API.

Group Function
Initialization SmartCar()
begin()
end()
Ultrasonic turnHead()
readHeadAngle()
ping
turnHeadAndPing()
Motion driveForward()
driveBackward()
driveForwardTime()
driveBackwardTime()
turnLeftTime()
turnRightTime()
driveForwardDistance()1
driveBackwardDistance()1
turnLeftDegrees()1
turnRightDegrees()1
stop()

1 Denotes a method that requires speed sensors.

Examples

  • Roam: Let the robot car roam about the room.
  • RoamDistance: Another roaming example, this time using the speed sensors to drive by distance.