O'Reilly logo

Make a Mind-Controlled Arduino Robot by Kimmo Karvinen, Tero Karvinen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Coding

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

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

void loop()
{
        while (lineDetected()) turn();  // 1
        forward(getAttention());        // 2
}
1

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.

2

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

Rinse and repeat.

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

Moving

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 can’t 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required