Sigueluz-beetle

Are you ready to program your PrintBot? I will give you a step-by-step explanation of how to do it with bitbloq. What do beetles do? They hide in the darkest corners! That´s why we´re going to make a program for our light dodger robot. Here you can see how our robot will work:

1__Sigueluz-200

Did you understand the picture? The robot dodges the light, so let´s get started! First we need to connect our board correctly. Here´s the connection diagram:

2__conexiones

Our beetle has a light sensor on each side. The sensors tell us the quantity of light that they detect. We need to read the values of the sensors to determine whether there´s more light on the right or the left. We will call the readings luz_derecha (right_light) and luz_izquierda (left_light):

4__sensoresLuz

Notice that the left sensor is connected to pin A2 and the right sensor to pin A3.

Our light sensor is a digital component that gives us a value of 500 in broad daylight and 0 in total darkness. So what do we do now? We need to move the motors to make the robot dodge the light. It´s super easy!

    1. GO FORWARD: When there is plenty of light, it moves forward quickly to escape it. How do we know there´s a lot of light? Because the sensors give us a very high reading, for example, above 300.

5__huyeLuz

Notice that the left sensor is connected to pin 6 and the right sensor to pin  9.

    1. TURN LEFT: When the right sensor receives more light than the left, the robot turns left because it´s darker there. To turn to the left, what I do is move only the right wheel (try this at home, you will see that I am right!).

6__giraIZQ

    1. TURN RIGHT: On the other hand, when the left sensor receives more light than the right one, it turns right because it´s darker there. To turn to the right, I only move the left wheel (do you believe me now?).

7__giraDRCH

    1. STOP: Finally, if in darkness, it will stop. Because it´s never a good idea to go forward without knowing where we´re going…

8__parar

Beetle-guia-de-montje-11-100