Introduction: Arduino Line Follower Wallrides Classroom Whiteboard
Following the line on the ground is too boring!
We've tried to look at a different angle at line followers and bring them to another plane - to the school whiteboard.
Look what came of it!
Step 1: What Do You Need?
For one racing robot:
- 1 x 2WD miniQ Robot chassis; It is a multi-functional platform for creating simple two-wheeled robots.
- 2 x 6V Micro geared motor with the 1:150 reduction ratio; Geared motors included with the miniQ robot platform have a gear ratio of 1:50 and are too fast. They should be replaced by stronger motors for example with the 1:150 or higher gear ratio. The higher the gear ratio the slower the robot rides on the whiteboard but the less the chance that the wheels slip.
- 4 x Neodymium magnet; You need small 3mm thickness magnets with the 12mm diameter (for those with a round shape) or with the 12mm side (for those with a square shape). Also, magnets should have a hole for the machine screw with a countersunk head usually for the M3 one. Sometimes manufacturers specify the strength of the magnet coupling. It should be in the range of 2kg to 2.4kg.
- 1 x Arduino UNO; The on-Board computer. The most popular prototyping platform.
- 1 x Octoliner module; Eyes and headlights of your racing bot. Octoliner is a cool line sensor consisting of 8 separate infrared sensors controlled via an I2C interface.
- 1 x 2-cell 7.4V LiPo battery; It can give a large current that motors need to overcome the attraction of the magnets. The 2-cell battery has a voltage in the range of 7.4V to 8.4V. It is enough for 6V motors and the built-in voltage regulator on the Arduino Board. Any capacity can be selected. The capacious the battery, the longer the robot drives but note that too capacious battery can be heavy. The capacity in the range of 800mAh to 1300mAh is optimal.
- 4 x Male-Female wire;
- 4 x M3 spacer or Male-Female standoff with the 10mm length;
- 3 x M3 spacer or Male-Female standoff with the 25mm length or more;
- 4 x M3x8 countersunk flat head screw;
- 1 x M3 Nylon screw;
- 1 x M3 Nylon hex nut;
- Any M3 screws and hex nuts.
For a classroom:
- Magnetic whiteboard hanging on the wall;
- Thick black magnetic Board markers;
- Special LiPo battery charger or multiple chargers if you want to make many robots and charge them separately.
Step 2: How to Assemble? Assemble Chassis.
At first, you need to assemble miniQ chassis platform pre-replacing motors from the kit with more powerful ones with the 1:150 gear ratio. Do not forget to solder the wires to the motors contacts!
Step 3: How to Assemble? Install Magnets.
Install the magnets on the miniQ platform. Use M3x10 standoffs, M3x8 or M3x6 flat countersunk screws and M3 nuts. Required installation holes are shown in the picture.
The length of the standoffs should be exactly 10 mm. After installing the magnets, test the platform on the whiteboard. All four magnets should be adjacent to the magnetic board and the rubber tires on the wheels of the miniQ platform should be preloaded and provide some friction with the board surface.
Manually move robot across the board. During the ride, the magnets should not come off the board. If any magnet comes off it means that the rubber tires on the wheels load maximally. In this case, increase the 10mm distance of all standoffs by 1 or 2 mm by adding a pair of M3 washers and try again.
Step 4: How to Assemble? Add Electronics.
Mount the Arduino UNO Board on the platform using M3x25 standoffs, M3 screws and M3 nuts. Do not use short standoffs, leave some space under the Arduino board for wires and battery.
Install the Motor shield on the Arduino UNO Board.
Install the Octoliner module. Press it against the platform using a nylon M3 screw and nut.
Do not use metal fasteners to mount the Octoliner. Some mounting holes on the breakout board are soldered and used as IO pins. To prevent short circuits, use plastic fastener, for example, nylon.
Step 5: How to Assemble? Wiring.
Link all electronic components as shown in the diagram. The Octoliner module is connected via 4 wires (GND, 5V, SDA, SCL) to the Arduino UNO. Connect motors to the Motor shield. The LiPo battery is linked to the contact pads of the external power supply on the Motor shield as well as to the VIN pin on the Arduino board. Instead of using the VIN pin, you can use the 5.5 mm x 2.1 mm power plug on the board.
When using the Motor shield no wires are needed. Two motor channels are controlled by 4 pins. 2 PWM pins are responsible for the speed of rotation while 2 DIR pins for the direction of rotation. Usually, they are already linked with specific Arduino Board pins and their index numbers may differ depending on the manufacturer of the shield. For example, for my Motor shield, numbers are D4 D5 (DIR and PWM for the first channel) and D7 D6 (DIR and PWM for the second channel). For the original Arduino Motor shield, pins numbers correspond to D12 D3 (DIR and PWM for the first channel) and D13 D11 (DIR and PWM for the second channel).
Hobby LiPo batteries do not have a reverse polarity protection Board! Accidental shorting of the positive and negative contacts will result in permanent battery failure or fire.
Step 6: How to Program? XOD.
To make a program for such a racing robot is even easier than to assemble it.
In all my projects I use the XOD visual programming environment which allows me to create Arduino programs graphically without writing code. This environment is ideal for fast device prototyping or learning programming algorithms. Follow the XOD documentation web page to read more.
To program this robot, you need to add just one library amperka/octoliner into your XOD workspace. It is necessary for work with an eight-channel line sensor.
Step 7: How to Program? Patch.
The program is based on the principle of a PID-controller operation. If you want to know what the PID-controller is and how it works you can read another article on this topic.
Take a look at the patch with the robot program. Let's see what nodes are present on it and how it all works.
It is a quick-start node from the amperka/octoliner XOD library which represents the Octoliner module tracking the line. It outputs the "line tracking value" which lays in the range of -1 to 1. The 0 value shows that the line is at the center position relative to the infrared sensors on the Octoliner board (between CH3 and CH4). The -1 value corresponds to the extreme left position (CH0) while the 1 to the extreme right (CH1). On boot node initializes the optocoupler sensors and sets up their default brightness and sensitivity parameters. The inputs for this node are the I2C address of the device (ADDR for the Octoliner board it is 0x1A) and the line tracking value update rate (UPD), I set it continuous.
The line tracking values are fed directly to the pid-controller node.
This node implementing the work of the PID-controller in XOD. The target (TARG) value for it is 0. It is the state when the line is exactly at the center under the robot. If the line tracking value is 0, the PID-controller resets via RST pin. If the line tracking value is different from 0, the PID-controller converts It using Kp, Ki, Kd coefficients into the motor speed values. The coefficients values were selected experimentally and equal to 1, 0.2 and 0.5, respectively. The update rate (UPD) of the PID-controller is set to continuous.
The processed value of the PID-controller is subtracted from the 1 and added to the 1. It is done to desynchronize motors, to make them rotate in opposite directions when the line is lost. The 1 value in these nodes represents the maximum speed of the motors. You can reduce the speed by entering the lower value.
A couple of these nodes are responsible for controlling left and right robot motors. Here set the PWM and DIR pin values through which your Motor shield operates.
Flash the patch and try your racing bot. If you exactly follow assembly instructions, you do not need to change the patch or adjust the PID-controller. The specified settings are quite optimal.
The finished program can be found in the library gabbapeople/whiteboard-races
Step 8: Showcase and Tips.
- Use new or fresh black markers to draw a race track on the whiteboard. Try to make a thicker and contrasting line.
- It is possible to use miniQ platform of different producers, for example, this one. Most analogs are interchangeable.
- Make more than one robot! When there are a lot of them it's a little more fun!
Participated in the