Arduino and LEGO Projects
202 pág.

Arduino and LEGO Projects

DisciplinaArduino498 materiais3.075 seguidores
Pré-visualização28 páginas
switch and servo motor. The switch and motor need to be lined up 
when the machine is turned on. The motor is lined up with LEGO bricks to keep it in place while you build the rest of 
the box. It will be made more secure as the walls are built higher, which can be seen in Figure 1-20.
Figure 1-20. The servo motor and toggle switch are laid out on top of stacked LEGO plates and lined up using 
LEGO bricks
Adding LEGO Arms and a Switch
With the motor and switch in place, the LEGO arms for the motor and switch need to be set up, since that is what will 
be seen from outside the box. In Figures 1-21 through 1-25, a LEGO Technic beam is secured with a wire to a disc that 
came with the servo motor, then LEGO Technic beams are added to the top of it, plus a Technic pin with two Technic 
angle connectors on the ends to give it a wider reach when it comes up to hit the switch. Once that is done, Technic 
axle joiners are connected by 2M pins to create a pole that the Technic beams can hit with the machine is on, which 
will just slide over the top of the toggle switch.
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Figure 1-21. A curved Technic beam is wired to the servo motor\u2019s disc
Figure 1-22. Angled Technic beams are added to the end of the secured Technic beam, and a 5M pin and two angle 
connectors hold it in place
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Figure 1-23. Four axle joiners and three 2M pins extend the switch
Figure 1-24. The finished attachment for the switch
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Raising the Walls
With the motor arm and switch extension in place, the walls of the box need to be built higher. The walls should be 
high enough to cover the switch and motor arm. LEGO bricks extend from the walls to cover the bricks holding the 
motor in place, and another is extended over the motor itself to keep the motor from rising when the arm activates. If 
there is too much space between the brick above the motor and the servo, fill the space with LEGO plates for a tighter 
fit. Also note that there are two 2x2 bricks in the top row. These will hold the lid when it is closed to keep it from falling 
into the box. See Figure 1-26.
Figure 1-25. The motor arm and switch extension are added
Figure 1-26. The box extends over the motor and switch
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Building the Lid
Now that the box is prepared, you need to make the lid. Use Technic beams because the rounded ends will make it 
easier for the box to open and close. Using two pins between each Technic beam will hold them securely and they will 
not be able to move. Figures 1-27 and 1-28 show the parts and assembly of the lid.
Figure 1-27. 11M Technic beams and black friction Technic beams to hold them together. Two pins should connect 
between each beam to hold them securely
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Two Technic bricks with holes in the middle will go on the ends with gray pins to hinge the joint. Use the gray 
pins there because they are frictionless and allow more movement than the black friction pins. Once the lid is added 
to the box, a layer of bricks is added around the lid. See Figures 1-29 through 1-32.
Figure 1-28. The Technic beams connected. There are 2 pins between each beam
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Figure 1-29. Frictionless pins will go into the 1 x 2 Technic bricks, which will in turn be put into the holes in the end of 
the beams in the lid
Figure 1-30. The Technic bricks are added to the beams via the frictionless pins
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
Figure 1-31. The Technic bricks are put on top of the walls of the box
Figure 1-32. A layer of bricks is added to border the lid
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
With the opening lid completed, all that is left is the cover for the switch. Again, you are going to use stacked 
plates to cover this part of the box, but you can leave open a slit for the switch. The switch needs to be able to move 
freely back and forth to turn it off and on. The stick\u2019s extension moves easily within a one-stud width and a four-stud 
length, as seen in Figure 1-33, with the switch shown. It\u2019s important to secure the hinge of the box down, as shown in 
Figure 1-34, so usage of the Ultimate Machine does not lift the lid off the box.
Figure 1-34. The activated Ultimate Machine
Figure 1-33. The completed box, ready to turn itself off and on
Chapter 1 \u25a0 LeGO, arduinO, and the uLtimate maChine
With the switch covered, you have completed your first project. By flipping the switch towards the lid, the 
machine will be activated and the motor arm will come to life, only to push the switch away from itself and return to 
its dormant state until it is activated again.
You just completed an introduction to LEGO building and the Arduino. You learned the basic techniques for using an 
Arduino, starting from the most basic of programs, making an LED blink, to a more complex one using Arduino shields. 
You also learned the most basic LEGO building principle of build strong by using a strong base and alternating the 
bricks to create walls that can support your building. Combining the two gives you the ability to make more interesting 
projects and give them different levels of activity and interactivity, as you will explore in the following chapters.
Chapter 2
Using Sensors with the Android
In the last chapter, you made a machine that interacts with itself. A simple response to flipping a switch to turn itself 
off is a good start, but for more interactive projects, you need to start working with analog sensors that do more than 
just turn on and off. Sensors allow a machine to monitor the world around it and react accordingly. In this chapter, 
you will create a project that will be able to react to its surroundings.
When Google introduced their mobile operating system known as Android, they created a mascot to represent 
it. The little green robot became synonymous with the cell phones and tablets on which the operating system was 
installed. You are going to create this Android mascot and make him react to his environment. He will be able to \u201csee\u201d 
what is going on around him and turn to look when things get close within a 180 degree field of view.
A list of the parts in this chapter can be found in the appendix.
The Ultrasound Sensor
There are many different sensors that can be used to send data from the outside world to the Arduino; one such sensor is 
the ultrasound sensor. An ultrasound sensor sends out a high frequency sound that will bounce off objects and return to the 
sensor. The time it takes for the sound to go out and bounce back is then calculated to tell the distance of the object. With 
a simple calculation, it can be converted into a more human relatable value of centimeters or inches. For this Android, you 
are going to use the PING))) Ultrasonic Distance Sensor by Parallax, Inc., an Arduino-compatible ultrasound sensor.
As seen in Figure 2-1, the PING))) Ultrasonic Distance Sensor has three pins: 5V, GND, and SIG. The 5V and 
GND pin on the sensor connect to pins on the Arduino, which will allow the circuit to complete and for power to 
run through the ultrasonic sensor. The SIG or Signal pin can be connected to any of the digital Arduino pins; it\u2019s how 
the data is moved from the sensor to the Arduino itself.
Figure 2-1. The PING))) Ultrasonic Distance Sensor by Parallax, Inc
Chapter 2