The Arduino Inventor's Guide (33 page)

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

FIGURE 6-40:
The single-pole, double-throw switch

This switch, when wired correctly, will act as an on-off switch, allowing you to read whether it is set on 5 V or ground. Place the switch in the breadboard, making sure each leg gets its own row of holes. We placed ours at the top of the breadboard in
Figure 6-41
. As with the potentiometer, connect the two outer pins of the switch to the 5 V and ground power rails of the breadboard using two shorter jumper wires. Use a third jumper wire to connect the center pin of the switch to pin 12 of the Arduino. A complete diagram of this circuit is shown in
Figure 6-41
.

FIGURE 6-41:
The final circuit with the mode selection switch

The center pin is the signal pin and will read either
HIGH
or
LOW
depending on the position of the switch. You’ll use this paired with some basic logic to switch between manual control, which uses the potentiometer, and autopilot, which sets the servo to move back and forth on its own.

From the book’s resources at
https://www.nostarch.com/arduinoinventor/
, upload the
P6_AutoBalanceBeam.ino
sketch to your Arduino. Take a look at the comments in the sketch to see how it works.

Remember that if the beam’s not centered when you switch autopilot on, the ball will likely fall off. It may take a few tries, but when you get it, it looks like magic! Take a look at a video of ours running here:
https://www.nostarch.com/arduinoinventor/
.

7
Tiny Desktop Greenhouse

Greenhouses come in all shapes and sizes, from tiny indoor greenhouses made from plastic sheeting to large industrial greenhouses that span thousands of square feet. Not everyone wants a full-size greenhouse, though, so in this project you’ll build a smaller-scale model that can sit on your desk (
Figure 7-1
).

FIGURE 7-1:
The Tiny Desktop Greenhouse

In a traditional greenhouse, the panes of transparent glass or plastic allow light energy in to heat up the interior of the greenhouse, and the greenhouse is sealed to trap that warm air inside, resulting in an overall increase in temperature. The danger, of course, is that a greenhouse might become
too
hot. To regulate temperature, many greenhouses have fans and
autovents
that open windows at the top of the greenhouse to ventilate when it gets too hot.

Your greenhouse will also have an autovent. You’ll build a greenhouse controller that will monitor the temperature, and if it gets too warm, a window will open and a fan will turn on.

THE GREENHOUSE EFFECT

Greenhouses are warm enough to grow veggies year round because they’re able to trap and store energy. Earth’s atmosphere works similar to a greenhouse. Heat from the sun is radiated by the earth and then reflected and captured by the atmosphere. This unique property is known as the
greenhouse effect
, and it’s responsible for keeping the temperature of our planet temperate and livable. Without it, the temperature of our planet would average near 0 degrees Fahrenheit (–18 degrees Celsius)!

Another common example of the greenhouse effect is a car in the middle of the summer. With the windows closed, the temperature inside the car can rise 20 to 30 degrees higher than the outside temperature. This is why you should never leave your pets in the car—especially in the summer!

MATERIALS TO GATHER

To lift the autovent, this project uses a servo motor similar to the one you used for the Balance Beam in
Project 6
. We’ll also introduce three new parts in this project: a small DC hobby motor for the fan, a
transistor
to control the motor, and a
temperature sensor
to detect the temperature inside the greenhouse.

As you gather your parts, you’ll find that the transistor and the temperature sensor look very similar—they’re both small, threelegged devices that have a round, black plastic end with a flat edge (see
Figure 7-2
). To differentiate between them, tilt the flat edge against a light source, and you should see some printing; the temperature sensor should have the letters
TMP
marked on it. Gather your parts, shown in
Figures 7-3
and
7-4
, and let’s get started!

FIGURE 7-2:
TMP36 temperature sensor (left) and 2N2222 transistor (right)

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)

• One solderless breadboard (PRT-12002)

• One 330 Ω resistor (COM-08377, or COM-11507 for a pack of 20)

• One diode (COM-08588)

• One NPN transistor—2N2222 or BC337 (COM-13689)

• One TMP36 temperature sensor (SEN-10988)

• One hobby motor (ROB-11696)

NOTE

The parts marked with an asterisk (*) do not come with the standard SparkFun Inventor’s Kit but are available in the separate add-on kit.

• One submicro size servo motor (ROB-09065)

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

• Male-to-female jumper wires (PRT-09140*)

FIGURE 7-3:
Components for the Tiny Desktop Greenhouse

Other Materials and Tools

• Pencil (not shown)

• Craft knife

• Metal ruler

• Ruler

• Needle-nose pliers

• Wire cutters

• Glue (hot glue gun or craft glue)

• Masking tape (not shown)

• Cardboard (approximately one 11 × 17-inch piece or three 8.5 × 11-inch pieces)

• Enclosure template (see
Figure 7-18
on page
208
)

• 1 sheet (8.5 × 11 inches) transparency film (not shown)

• 1 medium-size paper clip (not shown)

FIGURE 7-4:
Recommended tools and materials

NEW COMPONENTS

First, let’s take a look at the new components, starting with the temperature sensor.

TMP36 Temperature Sensor

You already know how to measure light levels. With this nifty sensor, you’ll be able to measure temperature as well. The TMP36 is one of the easiest temperature sensors to use. The sensor itself is encased in a small plastic shell shaped like a cylinder with a flat edge, and it has just three pins. (Remember to tilt the flat edge against the light to identify the letters
TMP
so you don’t mix it up with the transistor. If it says 2N2222 or anything else, it’s the wrong part.)

When properly connected to power, the TMP36 sensor will produce a voltage that is directly proportional to the temperature it senses. Similar to how you measured the light level in
Project 5
or the position of the potentiometer in
Project 6
, you can use
analogRead()
to measure the voltage on this sensor. We’ll show you how to convert this voltage to a temperature reading in this project.

Standard Hobby Motor

To move air through the greenhouse, you’ll build a fan using a small hobby motor, as shown in
Figure 7-5
. This is the simplest type of motor available. When you connect its two wires to a power source, the motor spins, and when you reverse the connections, the motor spins in the opposite direction. Unlike the servo motor that you used
in
Project 6
, the hobby motor spins continuously. The hobby motor works with a voltage between 3V and 6V, so it’s perfect for Arduino projects.

FIGURE 7-5:
Standard DC hobby motor

NPN Transistor

The invention of the transistor made it possible to create all kinds of digital devices. For example, the microcontroller on the Arduino is actually made up of millions of transistors. Transistors are part of a family of components called
semiconductors
. A semiconductor is a device that sometimes behaves like a conductor, allowing current to flow, and other times acts like an insulator, preventing current from flowing.

This project uses the transistor like a switch by boosting the Arduino’s amp output. The hobby motor uses about 200–300 mA of current, but the Arduino
OUTPUT
pins are only capable of sourcing about 40 mA of current. Using a simple transistor circuit, we’ll show you how to use the low-current Arduino pin to trigger the transistor to open or close, just like a switch.

TAKING A SYSTEMS APPROACH

For the sake of organization, you’ll build this project as three separate parts, or subsystems. This technique, known as a
systems approach
, is used by engineers to separate a complex project into manageable sections that can each be built and tested individually. The main components of the three different parts are the temperature sensor, the servo motor (for the autovent), and the DC motor (for the fan). A schematic of the three parts is shown in
Figure 7-6
, and a wiring diagram of the compiled project is shown in
Figure 7-7
.

FIGURE 7-6:
Schematic diagram of the circuit

FIGURE 7-7:
Wiring diagram of the circuit

Other books

Chrysocolla by B. Kristin McMichael
Lesbian Cowboys by Sacchi Green
Love Blooms in Winter by Lori Copeland
Wonderland by Rob Browatzke
The Ghost in Me by Wenger, Shaunda Kennedy
A Memory Worth Dying For by Bruce, Joanie
Edith Wharton - SSC 09 by Human Nature (v2.1)