Medium 9781449311544

Make a Mind-Controlled Arduino Robot: Use Your Brain as a Remote

Views: 1612
Ratings: (0)

Build a robot that responds to electrical activity in your brain—it’s easy and fun. If you’re familiar with Arduino and have basic mechanical building skills, this book will show you how to construct a robot that plays sounds, blinks lights, and reacts to signals from an affordable electroencephalography (EEG) headband. Concentrate and the robot will move. Focus more and it will go faster. Let your mind wander and the robot will slow down.

You’ll find complete instructions for building a simple robot chassis with servos, wheels, sensors, LEDs, and a speaker. You also get the code to program the Arduino microcontroller to receive wireless signals from the EEG. Your robot will astound anyone who wears the EEG headband.

This book will help you:

  • Connect an inexpensive EEG device to Arduino
  • Build a robot platform on wheels
  • Calculate a percentage value from a potentiometer reading
  • Mix colors with an RGB LED
  • Play tones with a piezo speaker
  • Write a program that makes the robot avoid boundaries
  • Create simple movement routines

List price: $4.99

Your Price: $3.99

You Save: 20%

 

22 Slices

Format Buy Remix

How to Contact Us

ePub

 

Tools and Parts

ePub

 

Servo Motors

ePub

Servo motors (Figure1-4) will be moving the wheels of our robot. The most usual type of servos have limited rotation. They are used when you need to turn the motor to a specific angle. In our robot, we only need to control speed and direction. And, of course, the motor needs to be able to turn freely. Continuous rotation servos are made for this. Almost any servo can be modified to continuous rotation, but its easier to buy a ready-made version.

Figure1-4.Continuous rotation servos

The Parallax (Futaba) continuous rotation servo is perfect for our needs. It has an external potentiometer adjustment screw, which allows identical centering of two servos effortlessly. Youll notice how handy this is later, when we program the movements for the robot.

If you want to learn how to modify any servo to continuous rotation, read the Soccer Robot chapter in our book Make: Arduino Bots and Gadgets (MABG), published by OReilly (2011).

Were going to use regular L-brackets to attach the servos. Attach two brackets to each servo with 3x10 mm screws, as shown in Figure1-5.

 

Chassis

ePub

For the chassis youll need something that is robust enough to hold the robot together and can be shaped easily. Plywood, acrylic, or metal plate (Figure1-6) works well.

Our material of choice is Dibond, which is aluminum composite with polyethylene core. Its light, easy to cut, strong, and good looking. Best of all it happened to be free. Because its lightweight and flat, its used for printing advertising signs. Lucky for us, printing doesnt always go like it should, and tons of Dibond ends up in the trash.

Even if you dont have a sign-making store as your neighbor, you could find other useful material thrown away. For example, you shouldnt have any trouble finding a metal plate from computer parts or plywood from furniture. Choose a material that is easily available for you and that is comfortable to process with your tools and skills.

You dont need to limit yourself to traditional methods when making the chassis. If you have the access and necessary skill for 3D printer or laser cutter, go for it. Go to http://www.thingiverse.com for some inspiration on printed 3D objects.

 

Painting the Chassis

ePub

 

Attaching Servos to the Chassis

ePub

 

Attaching the Line-Detecting Sensor

ePub

Cut a 3 cm piece from the aluminum pipe. To make sure that the pipe does not short-circuit the sensor, well put a round piece of felt pad on the other end. Make a hole in the felt pad so that you can push the screw easily through it (Figure1-12).

Figure1-12.3 cm piece of aluminum pipe for the line-detecting sensor and a felt pad to prevent short circuits

Put a 3x42 mm screw through the pipe and secure the line detector in the front of the robot (Figure1-13). The emitter/receiver part of the sensor has to be facing down.

Figure1-13.Line-detecting sensor attached

How does the line-detecting sensor work? It has a infrared emitter and a infrared detector. Reflective surfaces bounce the infrared light back to the infrared detector. So we know there is no line. This does not happen with nonreflective surface, such as a black line. Generally reflective surfaces are white and nonreflective ones are black. Just keep in mind that this is not always the case. We have had black paper that was more reflective than our white tape. With three or more line-detecting sensors, you can make a line-following robot. Instead of just turning around like our robot, line followers try to keep the black line in the center sensor. If the side sensors detect the line, the robot will turn until the center sensor sees the line again.

 

Wheels

ePub

 

Attaching the RGB LED to Chassis

ePub

 

Attaching the Power Switch to the Chassis

ePub

 

Attaching Arduino

ePub

 

Battery Holder

ePub

 

Attaching Solderless Breadboard

ePub

 

ScrewShield Holds Wires in Place

ePub

 

Moving

ePub

The code that controls your robot is simple. Well, its simpler than one would expect for a sci-fi trick like mind control.

A simplified, pseudocode version of your robot would be as follows:

The reflectivity sensor tells if the robot is on top of a black line, which forms the border of the arena. When the robot is on the border, it turns until the sensor sees white again.

Then the robot goes forward. The speed is read from the EEG headband.

Rinse and repeat.

In this coding part of the book, youll write each part of the code that makes your robot tick.

Continuous rotation servos are motors you can easily control. With continuous rotation servos, you can only control the speed (forward, stop, back), but unlike standard servos, you cant set the servo to point at a specific angle.

There are three wires going to a servo: red (positive), black (ground), and white (data). To control a servo, you need to keep sending pulses to it. The length of the pulse tells how fast the full rotation servo should turn. The pulse length is very short, typically from 500 s (microseconds) to 2000 s. This means it can be as little as half a millisecond: 500 s = 0.5 s = 0.0005 seconds.

 

Line Avoidance

ePub

To make your bot stay in the arena, you must teach it to avoid a black line. Then you can build an arena with big white paper as the floor and black tape as the border.

Lets connect the reflection sensor to Arduino. Prepare the cable by cutting the end that doesnt fit to the sensor. In our case, the small white connector fit to the sensor and we left it in place. The big black connector didnt fit anywhere, so we cut it away. Strip the free wires for connecting to Arduino (Figure2-6).

Figure2-6.Stripped sensor wire

Connect free sensor wires to Arduino as shown in the circuit diagram for helloreflection.pde (Figure2-7). Connect the red plus wire to +5V, and the black ground wire to GND. Connect the green data wire to D4. (Figure2-8). Use the ScrewShield to keep the wires in place (Figure2-9).

Figure2-7.Circuit diagram for helloreflection.pde

Figure2-8.Reflection sensor connected

Figure2-9.Free wires connected to Arduino with ScrewShield

For line avoidance, we use a typical reflectivity sensor. We read it with Arduinos digitalRead() function.

 

Battery, No Strings Attached

ePub

Your line-avoiding robot is otherwise great, but it can be a bit of an annoyance to run after it while youre holding the USB cable. Its time for your robot to get its very own power source.

We cant use a regular 9-volt battery for the bot, as it doesnt have enough juice to power motors, the LED, and the NeuroSky dongle. Its also much nicer to use a high-capacity rechargeable battery, because it can keep your robot running 10 times longer without the need for a battery change.

We used DualSky 1300 mAh 30C 2s1p 7.4 V battery (Figure2-11). What do all these values mean? 1300 mAh (milliamp hours) or 1.3 Ah is the battery capacity. Higher value means longer running time. 30C is the discharge capacity for one hour. In this case 1300 mAh * 30 = 39000 mAh = 39 Ah. 2s1p means that battery has two 3.7 V cells in parallel. So together they give you 7.4 V, the output current. The recommended input voltage for Arduino Uno is 712 V.

Figure2-11.Rechargeable lithium-polymer battery pack

Always use strong batteries carefully. Acquire and follow battery-specific instructions. A short circuit can lead to heating, fire, or even explosion.

 

Bells and Whistles

ePub

LEDs and piezo speakers create user interface for many embedded devices. Even though they are low-key compared to computer displays and big speakers, they serve an important function. Users expect to get feedback on what they are doing.

Using LEDs and speakers to describe program state also helps coding. It would be difficult to keep a moving robot continuously on a USB leash. Sounds and lights on the robot will tell you whats happening, so you dont have to divide your attention between the serial monitor and the device. And of course, you dont have to fight with a lost serial connection.

An RGB LED has three LEDs in one package (Figure2-18). The colors of those LEDs are the primary colors: red, green, and blue (Figure2-19). When you mix colors by turning on multiple LEDs, you get secondary colors such as cyan, magenta, and yellow.

Figure2-18.An RGB LED has three LEDs in one package

Figure2-19.RGB LED primary colors

The RGB LED you use in this project has one positive leg and three negative legs. This configuration is called common anode. The positive wire is always connected to Arduinos +5V.

 

Load more


Details

Print Book
E-Books
Slices

Format name
ePub
Encrypted
No
Sku
9781449326005
Isbn
9781449326005
File size
0 Bytes
Printing
Not Allowed
Copying
Not Allowed
Read aloud
No
Format name
ePub
Encrypted
No
Printing
Allowed
Copying
Allowed
Read aloud
Allowed
Sku
In metadata
Isbn
In metadata
File size
In metadata