Making Things Move: DIY Mechanisms for Inventors, Hobbyists, and Artists - Dustyn Roberts (2010)

Chapter 10. Projects

The projects below draw on the skills you’ve learned in several of the chapters in this book.

Project 10-1: Not Lazy Susan

In this project, we’ll use a lazy Susan (also called a turntable or thrust bearing) to create a rotating platform. To make things interesting, we’ll use an infrared (IR) LED and phototransistor to make the table rotate with just a wave of your hand.1,2 You can use this as a table to magically serve food to dinner guests, or to make a fun interactive centerpiece for the next wedding you plan.

If you did Project 6-7 with a transistor and Project 6-8 with a photocell, this will be easy. If not, don’t worry—we’ll still go step by step. We’ll build the box first, then the circuit, and finally integrate the two. As always, it’s a good idea to skim through the steps and take a look at the pictures before getting started.

Shopping List:

• Hardware

• Safety glasses

• GM series plastic wheel from Solarbotics (fits on GM9 motor)

• Shaft adaptor (see the resources section on www.makingthingsmove.com to download a 3D printable file or buy this part; use Alibre Design to modify if necessary for your particular motor, wheel, and material thicknesses)

• Two pieces of 1/2 in thick MDF (or other wood) cut to 8.5 × 8.5 in square (for the top and bottom of the box)

• Four 7 3/4 in sections cut from a longer standard 1 × 3 board (actual cross section 3/4 in × 2 1/2 in)

• One piece of 3/16 in thick 8 1/2 in square Masonite for the rotating top (the one here is a laser-cut circle, but yours can be any shape or thickness)

• Wood glue (Titebond or Elmer’s Wood Glue, for example)

• Clamps

• Files, sandpaper, or (preferably) a Dremel tool

• Lazy Susan (McMaster 6031K17)

• Six #4 flat head wood screws 1 1/4 in long (McMaster 90031A117)

• Eight #4 flat head wood screws 1/2 in long (McMaster 90031A110)

• Phillips head screwdriver

• Drill (portable or drill press) and drill bits: 1/2 in, 1/4 in, 1/8 in, and 1/16 in

• Epoxy putty

• Electronics

• DC gearhead motor with about 12 in hook-up wire leads soldered to terminals (an old Solarbotics GM9 used here)

• Corresponding battery (9V used here) and snap or holder with wire leads (like RadioShack 270-324)

• Four AA batteries and holder (like SparkFun PRT-00552)

• Breadboard (like All Electronics PB-400)

• Jumper wires (like SparkFun PRT-00124) or hook-up wire to make your own

• Black electrical tape (McMaster or any hardware store)

• TIP120 Darlington transistor (Digi-Key TIP120-ND or Jameco 32993)

• Phototransistor (All Electronics PTR-1)

• IR LED (All Electronics ILED-8)

• On-off toggle switch (like SparkFun COM-09276) or other SPST switch with about 4 in hook-up wires soldered to the legs

• Diode (SparkFun COM-08589)

• 22KΩ resistor (RadioShack 271-1339)

• 100KΩ resistor (RadioShack 271-1311)

Box Recipe:

1. Use a hacksaw, band saw, or table saw, or ask your local lumber or hardware store to cut the wooden squares and side pieces. Sand, file, or Dremel any rough or splintered edges.

FIGURE 10-1 Clamp the box sides while the glue dries.

image

2. Arrange the four wooden sides of the box as shown in Figure 10-1. Apply wood glue to the mating surfaces, and clamp two at a time together until dry. You should have two L-shaped pieces now.

3. Apply wood glue to open ends and clamp together these two L-shaped pieces to complete a box. If your boards aren’t perfectly square, you might benefit from additional clamps, as shown in Figure 10-2. Let the glue dry while the pieces are clamped.

4. When the glue is dry, coat the bottom of this box with wood glue, and then stick it to one of the wooden squares as the base. Let it dry.

FIGURE 10-2 Using additional clamps to square up the box sides while the glue dries

image

5. Put on your safety glasses. In the other wooden square, drill 1/8 in clearance holes in each corner for the #4 wood screws you’ll eventually use to close the box. You can just lay the square on top of your box and eyeball locations with a pencil. Refer to Figure 10-3 to see these holes. Use a scrap piece of wood behind the square so you don’t drill into your table, or use a drill press. Either way, clamping down the material before you drill is a good idea.

6. Find and mark the center of the board. Drill a hole with the 1/8 in drill bit. Chase this with the 1/2 in drill bit (the pilot hole makes it easier to drill a hole with the larger bit).

FIGURE 10-3 Mounting the lazy Susan bearing

image

7. Center the lazy Susan bearing on the top wooden square. Mount the bearing with the shiny ring side down with four 1/2 in long #4 wood screws. If you have trouble driving them in by hand with the screwdriver, mark and drill 1/16 in pilot holes, and then try again. The mounted bearing with two screws is shown in Figure 10-3.

8. In order to eventually mount the rotating tabletop, you’ll need to get access to the four mounting holes in the corners of the turntable that you haven’t used yet. To drill access holes, rotate the bearing 45° or so, until you can look through the holes and see only wood underneath. Mark these locations, and then use the 1/4 in drill bit to drill these holes. The access holes are the four unused holes in Figure 10-3 around the edge of the lazy Susan.

9. Prepare the rotating tabletop by cutting it or ordering it online. See links in the resources section of www.makingthingsmove.com if you want to download the digital file to make a template, cut it yourself, or buy it.

10. Mount the motor. First, slide the shaft adaptor on your motor and stick it through the centered hole you drilled earlier. It should look like Figure 10-4.

11. Place the plastic wheel on the shaft adaptor. The wheel should be centered on the bearing and will be resting on top of it (and the shaft adaptor) at this point (see Figure 10-5). Adjust the position until the wheel is centered and the shaft adaptor is not rubbing against the inside of the 1/2 in hole you drilled earlier.

FIGURE 10-4 Shaft adaptor centered in the box top

image

FIGURE 10-5 Wheel/bearing/shaft adaptor/motor sandwich, centered

image

12. Turn the box top over and mount the motor using two of the 1 1/4 in long #4 wood screws. You may want to drill 1/16 in pilot holes in the wood after you’ve marked the locations to drill. Your motor should sit flat on the board, as shown in Figure 10-6. In order to make that happen, we removed the strap that held on the motor and used a diagonal cutter to remove the hook that the strap attached to. Also notice how the wires are insulated with hot glue and strain-relieved. This is important, especially for this project.

13. Check to make sure your motor, shaft adaptor, and wheel are still centered on the bearing. Place the rotating tabletop down on your work surface. Rotate the bearing and wheel on the box top so you can see the exposed holes in the lazy Susan you’re about to use to mount the rotating tabletop through the 1/4 in access holes you drilled earlier.

FIGURE 10-6 Motor mounted on the underside of the box top

image

14. If you’re using the laser-cut Masonite, you can just drop in the 1/2 in long #4 wood screws in each hole and mount the tabletop. The stackup should look like Figure 10-7. If you cut your own tabletop, you may want to mark and drill 1/16 in pilot holes to make this mounting step easier. Alternate between the four screws as you screw into the tabletop to ensure you’re sandwiching the plastic wheel evenly and not distorting the bearing.

15. Good work! Set aside the tabletop and box assemblies for now and move on to the electronics.

FIGURE 10-7 Rotating tabletop mounted on box top

image

Electronics Recipe:

1. Connect the 5V power and ground on one side of the breadboard. On the other side of the breadboard, connect a 9V battery to power and ground. Make sure the ground is linked between both ground columns on the breadboard. The circuit will look like Figure 10-8 when finished, so keep this configuration in mind as you work through the project. Build the circuit on your desk before putting it into the box in the integration later.

FIGURE 10-8 The completed circuit

image

2. Plug the TIP120 transistor into the breadboard so each leg has its own row.

3. Connect the collector (middle pin) of the TIP120 transistor to ground through the diode. Make sure that the diode is pointing in the right direction, with the stripe mark closest to the middle of the board.

4. Connect the emitter pin of the TIP120 transistor to ground.

5. Plug the phototransistor into the breadboard and bend the legs so it faces off to the side. It’s a good idea to solder hook-up wire to the phototransistor legs so you can adjust the position later. The wires coming from the phototransistor legs can be seen in Figure 10-8 (the pair of twisted wires closest to the TIP120 transistor).

6. Connect the base pin of the TIP120 transistor to the long leg of the phototransistor. This is the phototransistor’s emitter, and the short leg is the collector.


NOTE A phototransistor works just like a TIP120 transistor, but instead of having a third leg as the base, IR light acts as the base. IR light is just light that’s out of the range of colors we can see. We’ll generate this light with an IR LED in a minute. When you shine IR light on a phototransistor, it allows power to flow through it from collector to emitter. So why do we need both kinds of transistors? Even though the phototransistor here behaves like the TIP120, it doesn’t allow enough power to flow through it to run our motor. So we use the phototransistor as a sensor, and when light hits it, it sends a signal to the bigger TIP120 transistor to let motor power flow.


7. Also connect the long leg (emitter) of the phototransistor to ground through the 22KΩ resistor.

8. Connect the short leg (collector) of the phototransistor directly to 5V power.

9. Connect one of the motor wires to the collector (middle leg) of the TIP120 transistor on the breadboard. Connect the other motor wire to the 9V battery power column.

10. Plug the IR LED into the breadboard and bend the legs so it’s facing the same direction as the phototransistor. It’s also a good idea to solder hook-up wires to the IR LED and use those to plug into the breadboard, so you can adjust the position of the LED later. The wires from the IR LED legs are the twisted pair in Figure 10-8 right at the center of the breadboard, on the bottom.

11. Connect the short leg of the IR LED to ground through the switch (in the off position). Connect the long leg of the IR LED to the 5V power column through a 100Ω resistor.

12. Flip the switch to on. Put your hand or a white piece of paper in front of the IR LED and phototransistor. The closer you get, the more light from the LED will bounce off your hand into the phototransistor, and the faster the motor will spin! If you get far enough away, it won’t spin at all. Don’t believe me that the IR LED is actually on? If you have a camera phone, pretend you’re about to take a picture of your setup. Although our eyes can’t see IR light directly, the camera phone can, and you should see a faint glow on your screen. (In the pictures in this section, I cheated and used a white LED for emphasis; your IR LED won’t look that bright.)

Integration Recipe:

1. Pick up your whole circuit and plop it into the box. Make pencil marks where the LED and phototransistor touch the front of the box. Do the same thing with the switch. Remove the circuit from the box.

2. Use the 1/4 in drill bit to drill holes for the LED and phototransistor to look through opposite the marks you made in step 1 (see Figure 10-9). This is easiest to do with a portable hand drill while supporting the box on the corner of a table. Clean up any splinters with sandpaper or a Dremel tool.

FIGURE 10-9 IR LED (left) and phototransistor (right) peeking through drilled holes

image

3. Drill a hole for the switch opposite the mark you made in step 1 using the 1/2 in bit. It’s best to start with a 1/8 in pilot hole here first. Use the Dremel tool or a file to remove some material from the inside of the hole—just enough so the switch can be flipped from the outside (see Figure 10-10).

4. Once those holes are drilled, you can return the whole circuit to the inside of the box. Make sure your motor wires are still attached and none of your other connections came loose.

5. Stick the IR LED and phototransistor through the holes you drilled, and test to make sure your circuit still works. We found that ours worked best with the phototransistor wrapped in black electrical tape and pushed through the hole so it was flush with the outside of the box. We also sanded the surface of the IR LED a little to diffuse the light, and stuck that out farther past the outside of the box (see Figure 10-7).

FIGURE 10-10 A view of the switch from the outside

image

6. Use the epoxy putty to secure the switch, and put electrical tape under any other components you want to secure.

7. Once everything works, it’s time to put the top on the box! Use four 1 1/4 in long #4 wood screws and mount the rotating tabletop assembly to the corners of the wooden box. Your project should now look like Figure 10-11.

8. Find a vase of flowers or a plate of food to put on the rotating tabletop. Then when someone asks you if it’s a lazy Susan, just wave your hand and show them how not lazy it actually is!

FIGURE 10-11 Not lazy Susan

image

Project 10-2: Wind Lantern

In this project, we’ll build a small, vertical-axis wind turbine, or VAWT for short. These are not as efficient as their horizontal-axis cousins, but they are better suited to urban environments where wind can come from all different directions.

Normally, when you give electricity to a motor, it spins. The same is true in reverse: If you give a motor a spin, it acts as a generator and creates electricity. The wind lantern will use energy from the wind to turn a motor and the resulting energy to light up some LEDs within the base. The wind lantern will use this electricity to create a flickering, glowing indicator of the wind.3,4

You already know that LEDs and diodes allow current to flow through them in only one direction. You also know that bipolar stepper motors have two wire coils. The challenge here is to design a circuit that directs energy generated in each coil through an LED in the correct direction, no matter which way the lantern spins. To do this, we’ll build a rectifier circuit for a bipolar stepper motor (see Figure 10-18 in the recipe steps).

Shopping List:

• Electronics

• Stepper motor (SparkFun ROB-09238)

• Male header pins (SparkFun PRT-00116)

• Breadboard (like All Electronics PB-400)

• Jumper wires (like SparkFun PRT-00124) or hook-up wire to make your own

• Eight diodes (SparkFun COM-08589)

• One or more LEDs (yellow SparkFun COM-09594 used here, but choose any color)

• One or more 1,000 µF capacitors (SparkFun COM-08982)

• Hardware

• 1/4 in acrylic plastic sheet about 15 × 30 in or equivalent (size based on Ponoko P3 template) for gears, disks, and sail holder pieces


NOTE See the resources section of www.makingthingsmove.com for links to a file you can download and cut yourself (either with a laser cutter or to use as a template), as well as a link where you can buy the pieces.


• 10 in wide aluminum flashing (usually sold in rolls; you need about 2 ft length for this project)

• 5mm bore shaft collar with set screw (McMaster 57485K65)

• 7 1/2 in bore shaft collars with set screws (McMaster 6166K25)

• 18 in length of 1/2 in outer diameter aluminum tube (McMaster 1658T45 is 8 ft long but a good value if you have the means to cut it down to 18 in—a hacksaw will work)

• Two flanged sleeve bearings for 1/2 in shaft diameter (McMaster 2938T12)

• Thrust bearing cage assembly for 1/2 in shaft diameter (McMaster 5909K31) with two matching washers (McMaster 5909K44)

• Three female threaded standoffs, 4 in length, 1/4 in -20 screw size (McMaster 92230A350)

• Six socket head cap screws, 1/4 in -20 thread, 3/4 in length (McMaster 92196A540)

• Six lock washers for 1/4 in screw size (McMaster 92146A029)

• Six flat washers for 1/4 in screw size (McMaster 92141A029)

• Four M3 screws 40mm long (McMaster 91292A024)

• Four M3 lock washers (McMaster 92148A150)

• Four M3 washers (McMaster 91116A120)

• Set of inch and metric hex keys (like McMaster 7324A18)

• Hacksaw (like McMaster 4077A1)

• Deburring tool (like McMaster 4289A35) and/or rounded file

• Coarse sandpaper

• Epoxy putty

Recipe:

1. Order or make the gears, disks, and sail holders. See the Resources section at www.makingthingsmove.com for templates and links to where you can order these.

2. Put on your safety glasses and cut an 18 in length of the aluminum rod with a hacksaw. Use a deburring tool or file on the inside and outside of the end of the rod to smooth it and avoid cutting yourself.

3. Make sure your aluminum rod fits through the flanged sleeve bearings, thrust bearing and washers, and the shaft collars. Remember that issue of tolerances you learned about in Chapter 2? Look at the tolerances of all the parts:

• The aluminum rod has a ±.025 in outer diameter tolerance, which means it can range from 0.475 to 0.525 in.

• The shaft collars don’t give a tolerance for their inner diameters.

• The flanged sleeve bearings say +.001 to +.002 in for the inner diameter. This means they will be between 0.501 to 0.502 in.

• The thrust bearing says 1/2 in +0.002 to +0.007, which means the inner diameter can range from 0.502 to 0.507 in.

• The thrust washers don’t give any tolerance for the inner diameter.

This means that the outer diameter of the aluminum rod needs to be smaller than the smallest possible part it needs to fit into, which is the 0.501 in sleeve bearing. As you can see here, we have a good possibility for overlap in an inconvenient direction.

4. If your aluminum rod is too big for the sleeve bearing, put on your safety glasses, dust mask, and gloves (aluminum dust is not good for you). Grab the aluminum rod with the sandpaper and rotate it while you’re squeezing until you see aluminum dust coming off. Continue this until the rod fits through all the components.


NOTE If you’re lucky enough to have access to a lathe, it could be a big time-saver when you have a lot of aluminum to shave off. A bench grinder will work faster than sanding by hand, but it will be harder to maintain the round shape of the rod.


5. Assemble the base (refer to the full assembly in Figure 10-17 as you go through the steps). Start with the two disks, the hex standoffs, and the 1/4-20 screws, lock washers, and washers. Install the standoffs by sandwiching the acrylic disk, a washer, and a lock washer on each end with a 1/4-20 screw (see Figure 10-12).

6. Install one of the flanged sleeve bearings in the center hole of the base disk. The base is the one without the four holes to mount the motor.

FIGURE 10-12 Detail of installing the standoffs

image

FIGURE 10-13 The part stackup inside the base

image

7. Rest a thrust washer, thrust bearing, and then the other thrust washer on top of the flange. The inside of the base will start to look like Figure 10-13.

8. Slide the aluminum rod in from the top. Before it hits the sleeve bearing on the bottom, it should slide through the other sleeve bearing, a 1/2 in shaft collar, a laser-cut gear, two more 1/2 in shaft collars, and finally the thrust washer, bearing, washer stack.

9. Pull up slightly on the aluminum rod so it’s not hitting your work surface. Use your Allen key set to tighten the set screw in the lowest shaft collar. At this point, the shaft collar is resting on the thrust bearing and attached to the aluminum rod, so you should be able to spin the rod.

10. Lift the next shaft collar from the bottom up with the gear to about the halfway point inside the base. Tighten the set screw. This shaft collar will be attached to the gear with epoxy putty later, but do not do this yet.

11. Secure the top sleeve bearing with the top shaft collar, as shown in Figure 10-14.

FIGURE 10-14 Top sleeve bearing secured with shaft collar under the top disk

image

12. Before you continue up the rod, this is a good time to mount your motor. First, cut the wires to about 8 in long and solder a set of four male headers to the wires (just as in Project 6-9). Red and green should be next to each other on one side, and blue and yellow on the other.

13. Remove the screws that hold the motor together. Use the longer M3 screws from the shopping list to mount the motor from the back, on the underside of the top disk. Sandwich an M3 washer and lock washer with each screw (see Figure 10-15).

14. Slide the other gear onto the motor shaft and use the 5mm shaft collar to secure it temporarily. Adjust the height of both shaft collars until the gears are at the same height and mesh well. Now you can break out the epoxy putty and secure the gears to their respective shaft collars.

FIGURE 10-15 Stepper motor mounted

image

15. Continue up the aluminum rod. Slide on a 1/2 in shaft collar, one of the plastic sail holders, and then another 1/2 in shaft collar. Pull the lower shaft collar up so it’s not resting on the top of the base and secure it to the rod with its set screw. Then pinch the plastic sail holder with the shaft collar on top of it, and secure the assembly with a set screw. When you rotate the whole assembly by the shaft, it should rotate smoothly, and the sail holders should rotate with the shaft.

16. Cut out three sails for your wind turbine to catch the wind. There’s no right answer here, and you have a few different slots in the sail holders, so just use scissors to cut the aluminum flashing in a length you think will work. Then cut 1/2 in tabs into each corner to slide into the slots. Bend over the tabs to secure the sails (see Figure 10-16).

FIGURE 10-16 Bend the tabs in the aluminum flashing over to secure the sails.

image

FIGURE 10-17 Fully assembled wind lantern

image

17. Do the same shaft collar, sail holder, shaft collar assembly on the top of the sail to finish this section of the build. Your project should look like Figure 10-17 without the breadboard at this point. It should spin with very little friction when you turn it by hand with the aluminum rod.

18. Now, the electronics. We need to create a circuit like the one shown in Figure 10-18. Use the eight diodes and jumper wires to create this circuit on your breadboard as shown in Figure 10-19. It will tell any electricity generated in each coil to go to the same place: the power column on the right side of the breadboard. Make sure all your diodes are facing the right direction, and don’t forget to jump the ground columns across the board.

FIGURE 10-18 Rectifier circuit for a bipolar stepper motor

image

FIGURE 10-19 Rectifier circuit created on a breadboard

image

19. Notice the LED in the center and the two capacitors at the top and bottom of the board. Plug the long leg of your LED into the power column and the short one into ground. Before you add the capacitors, give the wind lantern a spin and watch the LED flicker!

20. Try adding at least one capacitor as shown in Figure 10-18. The negative marked side should go to ground, the other to power. The capacitor will store energy while the wind lantern is creating it, and release it when it is not. The resulting effect here is a smoother flicker on the LED. Try adding more LEDs and more capacitors until you get a smooth glow when you spin the aluminum rod. In Figure 10-20, we placed diffuser paper over the side of the lantern and used three LEDs and two capacitors to create a pleasing glow.

21. Now take it outside! See if it works with real wind. We had success on a street corner in Manhattan and on the roof of Eyebeam Art + Technology Center’s two-story building.

FIGURE 10-20 Wind lantern at work

image

Project 10-3: SADbot: The Seasonally Affected Drawing Robot

SADbot was created in collaboration with Ben Leduc-Mills for the window gallery at the Eyebeam Art + Technology Center. The main idea was to use solar energy to power a drawing machine that could interact with people outside the window through light sensors. You can re-create this project to install in your own window at home.

SADbot gets its name from the source of its power: the sun. Since the motors are solar-powered, they will run only if it has been sunny enough to store solar energy in the battery. When the batteries run low and the SADbot motors stop running, SADbot appears sad because it has to wait for the sun to come out before it can keep drawing.

Shopping List:

• Electronics

• Multimeter

• Arduino with USB cable and AC adaptor

• Soldering iron, stand, and solder

• Three small breadboards (like All Electronics PB-400)

• Jumper wires (like SparkFun PRT-00124)

• Hook-up wire: red, black, and white (SparkFun PRT-08023, PRT-08022, and PRT-08026)

• Two stepper motors (SparkFun ROB-09238)

• Two EasyDrivers (SparkFun ROB-09402)

• Male header pins (SparkFun PRT-00116)

• Four photocells (1KΩ – 10kΩ: SparkFun SEN-09088)

• Four 1KΩ resistors (SparkFun COM-08980)


NOTE You can also use a 1KΩ – 10kΩ photocell (SparkFun SEN-09088). In that case, you should use a 1KΩ resistor (SparkFun COM-08980) to get the best response.


• Benchtop power supply for testing

• 12V 5Ah SLA battery (PS-1250 F1 from Microbattery.com, www.microbattery.com)

• Solar charge controller (SKU 06-1024 from Silicon Solar, www.siliconsolar.com)

• 12V 7W solar battery charger panel (Silicon Solar SKU 9358)

• Hardware

• Large plywood or other wooden board to use for canvas (around 3 ft × 2 ft will work well)

• Eight M3 screws, 20mm length (McMaster 92095A185)

• Eight M3 lock washers (McMaster 92148A150)

• One pack M3 washers (McMaster 91116A120)

• Drill (either portable or drill press) and drill bits: 3/8 in, 1/8 in

• Diagonal cutters (like SparkFun TOL-08794)

• Two 3D printed pulleys


NOTE See the resources section on www.makingthingsmove.com for a link to a file you can download, as well as a link to where you can buy the pulleys.


• Spring clamp (like McMaster 5107A1) that will hold the marker

• Black marker

• Monofilament fishing line

• Large white paper

Recipe:

1. Prepare two stepper motor/EasyDriver/breadboard assemblies as you did in Project 6-9. Use a benchtop power supply to get 12V power and ground to the GND and M+ pins on each of the EasyDrivers. Set them up to interface with the Arduino as shown in Figure 10-21.

2. For the left motor:

• Arduino GND to GND on left EasyDriver

• Arduino pin 11 goes to DIR

• Arduino pin 12 goes to STEP

FIGURE 10-21 Arduino setup to run two stepper motors

image

3. For the right motor:

• Arduino GND (one of the two pins) to GND on right EasyDriver

• Arduino pin 6 goes to DIR

• Arduino pin 7 goes to STEP

4. Make sure the two stepper motors work. Type in the following code, verify it, and upload it to the Arduino.

   /*
   Driving two stepper motors with an Arduino through
   SparkFun’s EasyDriver v4.3
   By Ben Leduc-Mills and Dustyn Roberts
   Created: 2010.06
   */

   #include <Stepper.h> //import stepper library
   #define STEPS 200 // 360/1.8 (step angle) = 200 steps/revolution
 
   //declare new stepper objects from stepper library (one per motor)
   Stepper right_motor(STEPS, 6, 7); //6=DIR, 7=STEP
   Stepper left_motor(STEPS, 11, 12); //11=DIR, 12=STEP

   void setup()
   {
     //set motor speeds (in RPM)
     right_motor.setSpeed(200);
     left_motor.setSpeed(200);
   }

   void loop()
   {
     //step each motor every time through the loop
     right_motor.step(10);
     left_motor.step(10);
     delay(10); //gives the motor a chance to get to new step
   }

5. If the code works, your motors should just start spinning. Attach some tape flags to the motor shafts to help indicate what’s going on.

6. Play around with the voltage setting on the power supply. You’ll notice that the motors actually run at much lower than 12V. In fact, our motors would still spin as low as 3.7V and draw about 120 mA of no load current while there. At the full 12V, they ran at 240 mA no load, and jumped to about only 250mA when we attempted to stall the motor by hand. Since we’re using solar energy to charge batteries in this project, it’s good to know that the motors can handle some variability and aren’t too hungry for current.

7. Now make the motors respond to photocells. First, get out the third breadboard and wire up the photocells as you did in Project 6-8. Each photocell should have one leg connected to the power column and one leg connected to the ground column through a resistor (see Figure 10-22).

8. The leg going to ground should also go to one of the ANALOG IN pins on the Arduino. From left to right, connect the ground legs of the photocells to pins 0, 1, 2, and 3 on the Arduino, which correspond with up, down, left, and right in the code, respectively.

FIGURE 10-22 Two steppers wired to photocells

image

9. Jump power and ground to the breadboard from the Arduino GND and 5V pins. See Figure 10-23 for the full setup.

10. Now we will try some code that uses the photocells to move the stepper motors. Type in the following code, verify it, and upload it to the Arduino.

   /*
   Using photocells to drive two stepper motors
   with an Arduino through SparkFun’s EasyDriver v4.3
   CC-GNU GPL by Ben Leduc-Mills and Dustyn Roberts
   Created: 2010.06
   */

FIGURE 10-23 Full SADbot circuit-testing setup

image

   #include <Stepper.h> //import stepper library

   #define STEPS 200 // 360/1.8 (step angle) = 200 steps/revolution

   //declare new stepper objects from stepper library (one per motor)
   Stepper right_motor(STEPS, 6, 7); //6=DIR, 7=STEP
   Stepper left_motor(STEPS, 11, 12); //11=DIR, 12=STEP

   int distance; // how far motors should go
   int lowest; // variable to store lowest photocell value
   int i; // for looping

   // variables for 4 photocell values
   int photo_up;
   int photo_down;
   int photo_left;
   int photo_right;

   void setup()
   {
     Serial.begin(9600); //start serial printout so we can see stuff
        
     // set motor speeds (in RPM)
     right_motor.setSpeed(200);
     left_motor.setSpeed(200);
   }
   
   void loop()
   {

     //read and print all photocell values from analog pins 0-3
     photo_up = analogRead(0);
     Serial.print(“up”);
     Serial.println(photo_up);

     photo_down = analogRead(1);
     Serial.print(“down”);
     Serial.println(photo_down);

     photo_left = analogRead(2);
     Serial.print(“left”);
     Serial.println(photo_left);

     photo_right = analogRead(3);
     Serial.print(“right”); 
     Serial.println(photo_right);

     delay(1000); //give me time to read them in the monitor

     //store photocell values in an array
     int photoValues[]= {photo_up, photo_down, photo_left, photo_right};

     lowest = 9999; //set this higher than possible photocell values

     //loop to find lowest photocell value
     for(i = 0; i < 4; i++) //4 = number of photocells 
       {
       Serial.println(photoValues[i]); //prints out photoValue array
     //assign actual photocell value to “lowest” variable if it’s lower
     //than whatever “lowest” is set to (starts at 9999)
     if (lowest >= photoValues[i] )
      {
      lowest = photoValues[i];
      }

     //print it out to confirm that the lowest value is beig selected
     Serial.print(“lowest:”);
     Serial.println(lowest);

     delay(1000); //wait one second before looping so we can read the values

     }//end for
   distance = lowest; //set travel distance variable = lowest value

   //find the sensor that matched the lowest, go that direction
   //see below for what the up, down, left, right functions do
   if (lowest == photoValues[0])
     {
      up( distance );
     }
   else if (lowest == photoValues[1])
     {
      down( distance );
     }
   else if (lowest == photoValues[2])
     {
      left( distance );
     }
   else if (lowest == photoValues[3])
     {
      right( distance );
     }
  }//end loop
  /*
  Here are the directional functions. Loop size = distance.
  Positive step numbers are clockwise, negative counterclockwise
  */

  void up(int distance) {
    for( i = 0; i < distance; i++){
      right_motor.step(10);
      left_motor.step(-10);
    }
  }
  void down(int distance) {
    for( i = 0; i < distance; i++){
      right_motor.step(-10);
      left_motor.step(10);
    }
  }

   void left(int distance) {
     for( i = 0; i < distance; i++){
       right_motor.step(-10);
       left_motor.step(-10);
     }
   }

   void right(int distance) {
     for( i = 0; i < distance; i++){
       right_motor.step(10);
       left_motor.step(10);
     }
   }

11. Try covering up the photocells one at a time.

• When you cover the up photocell, the left motor should turn counterclockwise and the right motor should turn clockwise.

• When you cover the down photocell, the left motor should turn clockwise and the right motor should turn counterclockwise.

• When you cover the left photocell, both motors should turn counterclockwise.

• When you cover the right photocell, both motors should turn clockwise.

12. Get out your plywood board and put on your safety glasses. The stepper motor data sheet from SparkFun indicates that the motor mounting holes are 31mm apart in a square, with the shaft at the center. Make pencil marks up on the corners of your board where you want the motor shafts to go, and then measure and make marks at each corner of a 31mm square centered on that motor shaft mark. Plan your motor mount so it looks like Figure 10-24.

FIGURE 10-24 Motors mounted at the top corners of the plywood canvas

image

13. Use the 1/8 in drill bit to drill out the clearance holes for the M3 screws the motor will mount with. Use the 3/8 in drill bit to drill out the center hole. Now mount your motors with the M3 screws, lock washers, and washers, as shown in Figure 10-25. You may need fewer washers, depending on the board thickness you’re using.

14. Once both motors are mounted, confirm the circuit still works as intended and none of the wires in your circuit have come loose. Press the pulleys onto each motor shaft.

FIGURE 10-25 Detail of motor mounting

image

15. Now let’s get SADbot running off the battery charged by the solar panels through the charge controller (the Arduino should plug into the wall through the AC adaptor). First, simplify the wiring by choosing one EasyDriver board as the power hub (see Figure 10-26). Designate one side of the breadboard as the hub, and then use small jumper wires to jump the GND and M+ pins of the EasyDriver to this hub. Connect the power and ground columns of this hub to GND and M+ on the other EasyDriver breadboard with long lengths of hook-up wire.

16. Cut some more hook-up wire and connect this power hub to the two far-left screw terminals on the charge controller (refer to Figure 10-27).

17. Solder hook-up wire to the battery terminals (red for positive and black for negative). Use the screw terminals in the center of the charge controller to hold the stripped ends of these wires.

FIGURE 10-26 Simplify wiring so the power hub is on one EasyDriver board.

image

FIGURE 10-27 Charge controller indicating connections to solar panels

image

18. Cut off the RC plug that comes on the solar charger wires. Separate the two wires and strip the insulation off the ends to expose about 1/4 in of wire. To figure out which one is positive and which one is negative, use your multimeter. The black lead should be in the COM connection, and the red lead in the voltage-measuring connection, just as for testing batteries (see Figure 5-1 in Chapter 5). Now touch the red lead to one of the solar panel wires and the black lead to the other. If the reading on your multimeter is positive, you guessed right. If not, you guessed wrong.

19. Do this with both solar panels and squish both negative wires in the charge controller on the remaining negative terminal. Each positive wire gets its own screw terminal on the far right of the charge controller (see Figure 10-27).

20. If you’ve done everything right, your motors should be moving! Make sure the switch on the charge controller is on. You’ll want to put your solar panels in a sunny spot so the battery can charge as the motors use up the initial charge.

21. Now let’s make SADbot draw something interesting. Cut two approximately 5 ft lengths of fishing line and tie each on through the hole in the center of the pulleys. Tie the other ends of the line to a spring clamp and clamp onto a marker. Mount the white paper on your canvas board with tape or clamps (refer to Figure 10-24).

22. Let’s tell the stepper motors to draw in random directions by default, and then to behave as they did before when someone is covering a photocell. This will create a drawing like the ones SADbot made in Eyebeam’s window gallery (see Figure 10-28). You can install SADbot the same way if you just solder some hook-up wire to each photocell and position them however you want.

23. Type, verify, and then upload the following code to the Arduino.

   /*
   SADbot v.03

   SADbot will draw a random distance in random direction until a
   photocell is blocked. When SADbot detects a photocell has been blocked, it
   will draw towards it. Stepper motors are driven through SparkFun’s
   EasyDriver v4.3

FIGURE 10-28 SADbot’s first drawing in the Eyebeam window gallery

image

   CC-GNU GPL by Ben Leduc-Mills and Dustyn Roberts
   Created: 2010.06
   */

   #include <Stepper.h> //import stepper library

   #define STEPS 200 // 360/1.8 (step angle) = 200 steps/revolution
   
   //declare new stepper objects from stepper library (one per motor)
   Stepper right_motor(STEPS, 6, 7); //6=DIR, 7=STEP
   Stepper left_motor(STEPS, 11, 12); //11=DIR, 12=STEP

   int distance; // how far motors should go
   int lowest; // to store lowest photocell value
   int i; // for looping

   // variables for 4 photocells
   int photo_up;
   int photo_down;
   int photo_left;
   int photo_right;

   // Set canvas size. 1000 steps is roughly .4 inch
   #define CANVASWIDTH 32000
   #define CANVASHEIGHT 20000
   
   //total distance for bounds checking
   //SADbot starts at center (canvaswidth/2 and canvasheight/2)
   float totalWidth = CANVASWIDTH /2;
   float totalHeight = CANVASHEIGHT /2;

   int randomDirection;
   int randomDistance;

   void setup()
   {
     Serial.begin(9600); //start serial printout so we can see stuff

     // set motor speed (in RPM)
     right_motor.setSpeed(200);
     left_motor.setSpeed(200);

     //use random seed to get better random numbers
     //*set to an analog pin that you’re not using
     randomSeed(analogRead(4));

   }// end setup

   void loop()
   {
     //read and print all sensor values from analog pins 0-3
     photo_up = analogRead(0);
     Serial.print(”up”);
     Serial.println(photo_up);

     photo_down = analogRead(1);
     Serial.print(”down”);
     Serial.println(photo_down);

     photo_left = analogRead(2);
     Serial.print(”left”);
     Serial.println(photo_left);

     photo_right = analogRead(3);
     Serial.print(”right”);
     Serial.println(photo_right);

     delay(1000); //give me time to read them in the monitor

     //before drawing, check our totalHeight and totalWidth
     Serial.print(”totalHeight:”);
     Serial.println(totalHeight);
     Serial.print(”totaWidth:”);
     Serial.println(totalWidth);

     delay(1000); //give me time to read them in the monitor

     //store photocell values in an array
     int photoValues[]= {photo_up, photo_down, photo_left, photo_right};

     lowest = 9999; //set this higher than possible photocell values

     //loop to find lowest photocell value
     for(i = 0; i < 4; i++) //4 = number of sensors 
      {
      Serial.println(photoValues[i]); //prints out photoValue array

      //assign actual photocell value to “lowest” variable if it’s lower
      //than whatever “lowest” is set to (starts at 9999)
      if (lowest >= photoValues[i] ) 
        {
        lowest = photoValues[i];
        }
      //print it out to confirm that the lowest value is being selected
      Serial.print(“lowest:”);
      Serial.println(lowest);

      delay(1000); //wait one second before looping so we can read the values

       }//end for
     
     distance = lowest; //set travel distance = lowest value

     //if lowest value indicates a covered photocell, draw towards lowest
     if (lowest < 550 )
       {
       //find the sensor that matched the lowest, go that direction,  
       //but only if SADbot is within the bounds of the canvas
       if ((lowest == photoValues[0]) && ((totalHeight + distance) <
   CANVASHEIGHT))

        {
        up( distance );
        totalHeight += distance; //increment totalHeight variable
        }
     else if ((lowest == photoValues[1]) && ((totalHeight - distance) > 0))
        {
        down( distance );
        totalHeight -= distance; //decrement totalHeight variable
        }
     else if ((lowest == photoValues[2]) && ((totalWidth - distance) > 0))
        {
        left( distance );
        totalWidth -= distance; //decrement totalWidth variable
        }
     else if ((lowest == photoValues[3]) && ((totalWidth + distance) <
   CANVASWIDTH))
        {
        right( distance );
        totalWidth += distance; //increment totalWidth variable
        }
     }//end if
     
     //otherwise, no one is covering any sensors, draw according to random
     else
       {
       //pick random number 1 through 9 to map to direction  
       randomDirection = random(1, 9);
       Serial.print(“random direction:”);
       Serial.println(randomDirection);

       //pick random number 1 through 200 to map to distance
       randomDistance = random(1, 200);
       Serial.print(“random distance:”);
       Serial.println(randomDistance);
      
       //directions for any randomDirection value generated
       switch (randomDirection)
         {
         case 1: //go up
           if((totalHeight + randomDistance) < CANVASHEIGHT)
             {
             up(randomDistance);
             totalHeight += randomDistance;
             }
           break;

         case 2: //go down
           if((totalHeight - randomDistance) > 0)
             {
             down(randomDistance);
             totalHeight -= randomDistance;
             }
           break;

         case 3: //go left
           if((totalWidth - randomDistance) > 0)
             {
             left(randomDistance);
             totalWidth -= randomDistance;
             }
           break;

        case 4: //go right
           if((totalWidth + randomDistance) < CANVASWIDTH)
             {
             right(randomDistance);
             totalWidth += randomDistance; 
             }
           break;

        case 5: //go upRight
           if(((totalWidth + randomDistance) < CANVASWIDTH) && ((totalHeight + randomDistance) < CANVASHEIGHT))
             {
             upRight(randomDistance);
             totalWidth += randomDistance;
             totalHeight += randomDistance;
            }
           break;

        case 6: //go upLeft
           if(((totalWidth - randomDistance) > 0) && ((totalHeight + randomDistance) < CANVASHEIGHT))
             {
             upLeft(randomDistance);
             totalWidth -= randomDistance;
             totalHeight += randomDistance;
             }
           break;

        case 7: //go downRight
           if(((totalWidth + randomDistance) < CANVASWIDTH) && ((totalHeight - randomDistance) > 0))
             {
             downRight(randomDistance);
             totalWidth += randomDistance;
             totalHeight -= randomDistance;
             }
           break;

        case 8: //go downLeft
           if(((totalWidth - randomDistance) > 0) && ((totalHeight randomDistance) > 0))
             {
             downLeft(randomDistance);
             totalWidth -= randomDistance;
             totalHeight -= randomDistance;
             }
           break;

         default: //just in case
           left(0);

       } //end switch
     
     } //end else
   
   } //end loop()
   
   /*
   Here are the directional functions. Loop size = distance.
   Positive step numbers are clockwise, negative counterclockwise
   */

   void up(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(1);
        left_motor.step(-1);
        }
   }

   void down(int distance)
   {
     for( i = 0; i < distance; i++) {
       right_motor.step(-1);
       left_motor.step(1);
       }
   }

   void left(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(-1);
        left_motor.step(-1);
        }
   }

   void right(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(1);
        left_motor.step(1);
        }
   }

   void upRight(int distance) 
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(2);
        left_motor.step(-.2);
        }
   }


   void upLeft(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(.2);
        left_motor.step(-2);
        }
   }

   void downRight(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(-.2);
        left_motor.step(2);
        }
   }
   
   void downLeft(int distance)
   {
      for( i = 0; i < distance; i++) {
        right_motor.step(-2);
        left_motor.step(.2);
        }
   }

24. Enjoy! Play with the photocells so you can interact with SADbot and make interesting drawings.

References

1. Tom Igoe, “Phototransistors Photocells” (http://itp.nyu.edu/physcomp/sensors/Reports/PhototransistorsPhotocells).

2. Dan O’Sullivan and Tom Igoe, Physical Computing: Sensing and Controlling the Physical World with Computers (Boston: Thomson, 2004).

3. Jeff Feddersen, NYU/ITP Sustainable Energy class notes, spring 2010.

4. Jeff Feddersen, “Anatomy of a Stepper Motor” (http://itp.nyu.edu/sustainability/energy/texts/Rectification.pdf).