Arduino and LEGO Projects
202 pág.

Arduino and LEGO Projects


DisciplinaArduino507 materiais3.080 seguidores
Pré-visualização28 páginas
decals, but if they are unavailable, paper labels from any stationary store can be used; just be sure to get 
the 8\u201d x 10\u201d sheets so that the labels are not cut in the middle. Figure 5-36 shows what the labels should look like, 
and Figure 5-37 shows the completed TARDIS body with labels applied.
Figure 5-35. The top level is covered in tiles
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
141
Figure 5-36. The decals for the Police Box banner and TARDIS doordecal
Figure 5-37. The completed TARDIS body
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
142
Now that the body is done, you need to give your TARDIS a roof.
Building the Roof
Since you are going with a cookie jar type top, it needs an edge to hold it in place when it slides into the body, and to 
give the slopes something to sit on. In Figure 5-38, you start with a ring of bricks. The ring will fit in the opening on top 
of the TARDIS body.
Figure 5-38. The initial ring for the TARDIS lid
The second layer of the lid will have 2 x 3 33 1/3 slopes around the edge, as well as the 2 x 2 33 1/3 slope corners. 
Since this will not make for a very strong foundation, the inner ring of studs will be filled in with a two-stud ring of 
bricks, as seen in Figure 5-39.
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
143
You now need to lay down two more levels of slopes. This first level, as seen in Figure 5-40, sits on top of the 
exposed studs of the layer in Figure 5-39. It is secured by locking in on the level beneath it, but the level above it, which 
is seen in Figure 5-41, has the slopes\u2019 outer studs attach to the slopes beneath it. While not completely secure, they will 
hold in place well enough for you to work with.
Figure 5-39. A ring of slopes is laid down and is supported by an inner ring of bricks
Figure 5-40. The slopes completely cover the studs beneath them
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
144
Figure 5-41. The last layer of slopes have their outer edge on the slopes beneath them
Figure 5-42. An LED is run through the hole in the middle of the 2 ¥ 4 plate and more plates secure the slopes
Now you will flip over the lid and secure the top layer of slopes in place. The center piece securing the slopes in place is 
a 2 x 4 plate with holes in it. You are using a Technic plate so you can feed an LED through the hole and have the top of the 
TARDIS light up. The 2 x 4 is surrounded by a ring of plates to lock the plates more firmly and cover the seams (Figure 5-42).
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
145
When you flip the lid back over, you push the LED over one of the studs and push a 2 x 2 corner piece into the 
hole. There will be enough room to slide the LED leads into the hole after the 2 x 2 corner is inserted, so push the LED 
down so that it does not stick out higher than the brick and so that the two leads do not touch (see Figure 5-43).
Figure 5-43. The 2 ¥ 2 corner piece with the white LED in the corner
The studs are still exposed on top, so a ring of 1 x 3 tiles covers the outer exposed studs. A round 2 x 2 clear brick is 
placed on top of the corner brick in the middle, which can be seen in Figure 5-44. A second 2 x 2 clear round is placed 
on top of the first with a 2 x 2 round tile on top; this completes the TARDIS, as shown in Figure 5-45. Even though 
the LED is hidden beneath the round, the clear bricks will refract the light and the light will be seen clearly when the 
music and sounds start to play (see Figure 5-46).
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
146
Figure 5-45. A second 2 ¥ 2 round is placed on top of the first, and a 2 ¥ 2 round tile is placed on top
Figure 5-44. Tiles are placed around the top of the slopes, and a clear 2 ¥ 2 round is placed over the 2 ¥ 2 corner
www.it-ebooks.info
Chapter 5 \u25a0 animating the tarDiS
147
Summary
Doctor Who fandom is at an all-time high, so you used SNOT techniques to build your own TARDIS. You were able to 
capture the look and feel without having any exposed studs. Although it cannot travel through space and time, nor does 
it fade out when it activates, it can simulate the lights and sounds of the TARDIS that occur when the Doctor travels.
What else can you make the TARDIS do? Can you build a sonic screwdriver that will trigger the TARDIS? Can you 
make it play different sounds based on different triggers? Can you use the TARDIS to battle intergalactic machinations 
of alien overlords?
Figure 5-46. The LED is attached to the ground and pin 6, the lid is placed onto the top of the body, and the TARDIS 
is completed
www.it-ebooks.info
149
Chapter 6
Controlling LEGO Trains with Arduino
The LEGO Group has its own mechanical system, the Power Functions system. Power Functions are a system of motors 
and lights that are made by LEGO and are used to power and control such projects as dinosaurs, bulldozers and trucks. 
There is also a thriving train community that uses LEGO trains to create large, ornate multi-train layouts that run 
through LEGO cities and towns crowded with buildings and people as they go about their LEGO lives. Like the other 
Power Functions creations, the trains are controlled remotely to tell each train which direction and how fast to travel.
The LEGO Power Functions are predominantly controlled by remote controls that use infrared technology. IR is 
commonly used in devices like TV remote controls to send signals to devices and react to them. The Arduino can both 
send and receive IR signals with the proper connections. A simple infrared LED and the proper frequencies can be 
used to mimic these signals and control these devices.
For this project, you will take an Arduino and use it to control a LEGO train. The Arduino can control all the same 
functions as the Power Functions remote, but it should be more reliable and send a cleaner signal to the IR receiver 
in the train to allow for finer control of the train. While the Arduino can control up to eight trains, you will be working 
with just one for this project.
A list of the parts in this chapter can be found in the appendix.
Arduino Train Controls
The most basic things you need for this project are an Arduino and an infrared LED, but that wouldn\u2019t give you 
enough control over the train, so you will add a potentiometer, a button, and some LEDs to be able to control the train 
and have some visible reactions. Figure 6-1 shows a diagram of the wiring and Figure 6-2 shows the required hardware 
on a breadboard.
www.it-ebooks.info
Chapter 6 \u25a0 Controlling lego trains with arduino
150
Figure 6-1. Diagram of the wiring for the train controller
Figure 6-2. The Arduino hardware for the train project
www.it-ebooks.info
Chapter 6 \u25a0 Controlling lego trains with arduino
151
The component in the upper right is a type of a variable resistor called a potentiometer. As the shaft turns, the 
resistance increases or decreases. Using one of the Arduino\u2019s analog inputs, it is possible to read this value and do 
something in your code like control the brightness of an LED or, in this case, the speed of the train. There are three 
connections coming from it: far left is ground, middle connects to a pin, and far right connects to the 5V pin. The 
middle connection has to go to an Analog In pin because unlike a button, which has an on state and an off state, the 
potentiometer returns a numeric value from 0 to 1024, similar to the way you used the Analog Out pins to send values 
of 0 to 255 to dim LEDs. You are going to use the potentiometer to control the speed of the train.
The button next to the potentiometer is a Normally Open (NO) push button. Normally Open means that there 
is no connection when the button is not being pressed. Pressing the button creates a connection and the Arduino