The Arduino Inventor's Guide (28 page)

BOOK: The Arduino Inventor's Guide
10.53Mb size Format: txt, pdf, ePub

FIGURE 5-31:
Placing the shade on top of the mini breadboard

Let It Glow!

If you have the external battery pack, you can now put four AA batteries in, and plug the barrel jack into the Arduino. The board should still be programmed and running, so just turn off the lights. You should get a nice, softly glowing night-light, like ours in
Figure 5-32
.

FIGURE 5-32:
Lights out! Our final glowing Night-Light project.

GOING FURTHER

This project used a lot of new skills and knowledge, but it still has a load of potential for further hacking. There are plenty of things you can do in terms of both the design and the code as you build your skills with Arduino.

Hack

One great sketch hack would be to have the colors change periodically when the Night-Light is on. For some hints, look back at your Stoplight project code. One method would be to add some simple blink code within the
if()
statement rather than just
digitalWrite()
functions and build a color animation.

You could also try adding different colors for different light readings using the
else if()
command rather than just
if()
or
else
on its own. The base structure of this method might look something like
Listing 5-5
.

LISTING 5-5:
Three-stage Night-Light code example

if
(lightValue < calibrationValue - 200)
{
  
//do if it is completely dark
  
digitalWrite
(11,
HIGH
);
  
digitalWrite
(10,
LOW
);
}
else if
(lightValue < calibrationValue - 50)
{
  
//do if it is a little dim
  
digitalWrite
(11,
LOW
);
  
digitalWrite
(10,
HIGH
);
}
else
{
  
//do if it is bright
  
digitalWrite
(11,
LOW
);
  
digitalWrite
(10,
LOW
);
}

You can see the sketch uses
else
if()
to set categories of light value. You would then need to set the color for each category.

Modify

The design of your Night-Light is totally up to you, so you can create a whole new design if you want. There are a number of tools you can use to design an enclosure and then produce it through automated means, such as laser cutting with balsa wood, 3D printing with materials like ABS or HIPS plastics, or even CNC milling, routing, or machining. Computer-controlled manufacturing will produce superclean and accurate parts that will amount to a more refined product. We encourage you to explore these possibilities to create something more permanent and polished. If you don’t have access to these kinds of tools, try looking into local hacker or maker spaces in your city. Often they’ll have facilities and tools that you can work with.

We have included a few example templates and ideas of projects that you can build and adapt at
https://www.nostarch.com/arduinoinventor/
.
Figure 5-33
shows an example of how you can break up the lampshade design with some fun patterns.

FIGURE 5-33:
A fun design from our design templates.

6
Balance Beam

In this project, you’ll build a desktop balance beam game using a turn knob and a
servo motor
(a small motor capable of making precise movements). The aim of the game is to roll a ball back and forth along the beam without it falling off. You’ll do this by using the turn knob to control the position of the servo. As the servo moves, so will the beam! Ready to get started?

Figure 6-1
shows the finished project. This is a simple mechanism that is made entirely of cardboard and a few household materials.

FIGURE 6-1:
The finished Balance Beam project

MATERIALS TO GATHER

The circuit for this project uses relatively few parts, though we will introduce two new pieces of hardware: the servo motor and the potentiometer. Take a look at the electronic parts and other materials you’ll need, shown in
Figures 6-2
through
6-4
.

Electronic Parts

• One SparkFun RedBoard (DEV-13975), Arduino Uno (DEV-11021), or any other Arduino-compatible board

• One USB Mini-B cable (CAB-11301 or your board’s USB cable; not shown)

• One solderless breadboard (PRT-12002)

• One 10 kΩ potentiometer (COM-09806)

• One submicro size servo motor (ROB-09065)

• Male-to-male jumper wires (PRT-11026)

NOTE

All of the parts used in this project are standard in the SparkFun Inventor’s Kit.

FIGURE 6-2:
Components for the Balance Beam

Other Materials and Tools

• Pencil or marker

• Craft knife

• Metal ruler

• Needle-nose pliers

• Wire cutters

• Glue (hot glue gun or craft glue)

• Mini screwdriver

• Scissors (not shown)

• (Optional) Drill and 1/4-inch, 1/8-inch, and 1/16-inch bits

• Two sheets of cardboard (roughly 8.5 × 11 inches in size)

• Balance Beam template (see
Figure 6-16
on page
167
)

• One bamboo skewer

• One small drinking straw (the bamboo skewer should fit into the straw loosely)

• One ping-pong ball

• One medium-size paper clip

FIGURE 6-3:
Recommended building materials

FIGURE 6-4:
Recommended tools

NEW COMPONENTS

In the previous projects, you’ve mostly used your Arduino to control LEDs, but now it’s time to branch out and explore other components. This project introduces a new sensor, called a
potentiometer
, and motors, specifically the
servo motor
.

The Potentiometer

In this project, you’ll use a potentiometer to control the movement of the Balance Beam. A potentiometer is a kind of sensor known as a
variable resistor
, which just means it’s a resistor whose value can vary.

A potentiometer generally has three legs or connection points and is represented by the symbol shown in
Figure 6-5
.

FIGURE 6-5:
Schematic diagram for a potentiometer

Potentiometers come in many shapes and sizes, a few of which are shown in
Figure 6-6
. Some look like turn knobs, some are sliders, and others require a small screwdriver to manipulate. Regardless of their appearance, they all work in the same way. And they are all around you—at home, you might find them in the dimmer switch of your dining room light, in the volume knob on your stereo, or inside devices like DVD players.

FIGURE 6-6:
Various shapes and sizes of potentiometers. We’ll be using the one on the left.

A potentiometer has a fixed resistance between the two opposite legs marked A and B in
Figure 6-7
. Potentiometers can come in all sorts of resistance values, but for this project you’ll use a 10 kΩ potentiometer. As you turn the knob or move the slider, the third leg of the potentiometer (marked C), called the
wiper
, moves up or down the resistor, and the resistance between B and C changes. It’s this resistance value that’s applied to the circuit.

If you turn the knob clockwise, the wiper moves toward A and the resistance between C and B increases; if you turn the knob counterclockwise, the wiper moves toward B and the resistance decreases.
Figure 6-7
shows how moving the wiper affects the resistance.

FIGURE 6-7:
Various positions on a potentiometer

If you connect A to 5 V, B to GND, and C to an analog input pin on your Arduino, this circuit starts to resemble the voltage divider you used in
Project 5
. As you turn the knob, you can vary the voltage on C between 0 V and 5 V. This setup is also sometimes called an
adjustable voltage divider.

The Servo Motor

A servo motor (or just
servo
for short) is a special type of motor designed to rotate an arm (or
horn
) to a particular angle, which you will determine in your sketch. Most servo motors have a given range of 180 degrees, though some can rotate a full 360 degrees; these are called
continuous rotation servos
. In this project, you’ll be using a standard 180-degree hobby servo, shown in
Figure 6-8
.

FIGURE 6-8:
A standard hobby servo

Servo motors are used in thousands of different products, from model cars and airplanes to the speedometer in your car and the robotic arms that built it.

What’s inside that black box? We opened one up so you don’t have to—see
Figure 6-9
.

FIGURE 6-9:
The inside of a servo motor

Other books

Underdog by Marilyn Sachs
Private Deceptions by Glenn, Roy
Two in Winter by Vanessa North
Damnation Alley by Roger Zelazny
Trouble's Brewing by Linda Evans Shepherd, Eva Marie Everson
The Unidentified by Rae Mariz
Good Intentions by Joy Fielding
SURRENDER IN ROME by Bella Ross