Light-following Robot

The questions below are due on Friday November 01, 2024; 05:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Today we're going to build a little robot car that will follow a light around as you move it. Here's a taste of what it might look like at the end of the lab:

Our little robot (a variant of a Braitenberg vehicle) has two "eyes" (photoresistors) which serve to detect the presence and approximate position of a light, and two motors which it can use to move toward that light. One thing to notice about this behavior is that it requires not only responding to input light (we'll get to that later), but also making the motors turn in both directions depending on the brightness of the light, similar to what we saw last week.

Check Yourself 1:
Thinking back to last week's lab, how did the motor's speed relate to its voltage? How were we able to make it turn in both directions despite only having a unipolar power supply?

1) Like a Moth to a Flame

Before we can build our little robot, we need a circuit design. We can take inspiration from our circuit from last week, generating a drop across the motor proportional to the difference between a control voltage and an adjustable offset voltage.

Today, though, we're going to do everything with pure analog circuitry rather than with a Teensy. Rather than the voltage from our DAC, we'll use a photoresistor to make a voltage that changes with the light falling on it.

So that we can do that, let's do some experiments with the photoresistor. Grab two from the cart and use your multimeter to answer the following questions (and write down the results so that you're prepared to discuss them during your checkoff).

Note that the photoresistors are highly directional, and they're made even more directional by the little piece of plastic we attached to each one. The photoresistors respond to light shining directly on the surface of the sensor (the beige part with the dark squiggly line), and light from other angles will have a harder time reaching the sensor. The intention is that the plastic piece blocks light from the overhead room lights but allows light from straight ahead to reach the sensor, as shown in the diagram below:

Hold the photoresistor so that the little plastic bit is blocking the light from above, and make some measurements:

  • What is the approximate resistance of the photoresistor in ambient light?
  • What if you cover it up so that it's dark?
  • What if you shine a light on it (from a phone flashlight, maybe) from 6 inches away? 3 inches away? 1 inch?

Now, knowing what we know about the photoresistor, we can go about designing a circuit to generate a voltage that varies with the light on the photoresistor. In particular, we would like to make a voltage that goes down as the amount of light falling on the photoresistor goes up.

We would like for the voltage to go down as the light gets brighter, and we would like to have as big a difference as we can between ambient light and having a bright light (like a cell phone flashlight) nearby. We can do this with a voltage divider with our photoresistor and a separate, constant resistor, powered by the 9{\rm V} battery. Given the design goals, which of the following is the more appropriate voltage divider? Don't just randomly click a choice; think about it first!

 

     ...or...     

 

Which circuit meets our design goal? 

OK, cool; we can use something like that to provide the voltage on one side of the motor (where our DAC was last week). And, like we did before, we can use a voltage divider to make ourselves an offset voltage. But for today, let's use a potentiometer for that instead of two fixed resistors, so that we can adjust the offset voltage.

As we mentioned in the prelab, unfortunately, with our 9V battery powering our circuit instead of 20V, the simple design from last week (i.e., putting the sensor's voltage on one side of the motor and the offset voltage on the other) won't cut it because it won't be able to make a big enough drop across the motor that way; instead, we need to use something fancier. The high-level idea is that we'll use the circuit from the prelab, with v_{\rm in} coming from our photoresistor-divider circuit, and v_{\rm offset} coming from our potentiometer (so that we can adjust it as necessary).

Check Yourself 2:
Draw a complete schematic for your circuit, including the circuit for generating the control voltage, the circuit for generating the offset voltage, the motor, and any other components you might need.

Check Yourself 3:
Double-check:
  • Will your circuit cross over the reference voltage in different lighting conditions (causing the motor to turn both directions)?
  • Will either your control voltage or your offset voltage be affected by adding the motor?

Feel free to check with us if you want before moving on; we're happy to take a look at your schematic.

We're here to help!

If you're unsure or want us to double-check your design, or if you have any questions about how things are working, feel free to ask! But either way, be prepared to discuss your schematic drawing during your checkoff.

1.1) Experimental Setup

Ultimately, our little robot is going to need two of these setups (each photosensor is responsible for controlling one motor). But let's start by building just one (though it's worth trying to put it in a strategic spot on the breadboard, knowing we're going to need to build a second one later).

There is still an open question before we start building: what value should we use for R? While this decision is ultimately ours to make, we want to make sure that as we move from ambient light to a light right in front of the robot, we see a big change in voltage. What does this mean about how R should relate to the resistance of the photoresistor? Let's let R_{\rm photo} refer to the resistance of the photoresistor when a bright light is about 6 inches away from it.

 

Which of the following do we want?

Now go ahead and build your circuit. Grab yourself a little breadboard (one of the half-length ones), one L272 op-amp package, a potentiometer, a motor, a battery connector, and a 9V-battery. Go ahead and put a wheel on your motor, too, so it's easier to see how it's spinning. But note that the wheel has a directionality to it: there is a little "bump" on one side that should point inward toward the motor, like so:

And the wheel should go on as far as it can so that it's almost all the way up against the gearbox.

Also, as you're building, recall that the L272 package has two op-amps inside of it, connected like so:

Once you've built it, try the following to test it out:

  • turn the switch on the battery holder to "ON" (and make sure there's a battery inside),
  • hold a light (from your phone or a flashlight or something) a short distance away,
  • move the light closer and farther from the sensor, and
  • observe how the motor moves.

As the light gets farther away from the photosensor, the motor should start spinning faster and faster in one direction. When the light is a few inches away from the sensor, the motor should stop; and if you move the light closer than that, the motor should turn in the other direction.

Turning the pot should adjust the "set point," i.e., the distance between the light and the sensor at which the motor stands still (versus moving backwards or forwards).

Checkoff 1:
Show your schematic and your working circuit to a staff member. Your circuit should work as described above.

1.2) Car Body

Now that we've got that much working, we're ready to start building our little robot. Before we finish building the circuit, though, let's put together the physical body of the robot (we want to do this first so that we have a way to test everything when the time comes).

We can put together the physical body of the robot as follows:

  • Grab a second motor, and make sure both of your motors have wheels attached.

  • Grab four nuts, four bolts, two motor brackets, and a dark grey acrylic motor mount from the cart.

  • To add one motor:

    • Put the motor bracket on the gearbox end of the motor (there is a little slot in the bracket that should line up with a part on the gearbox):

    • Put one of the nuts into the little hole on top of one of the brackets (the hole is vaguely hexagonal in shape and so should be a perfect fit):

    • Use your finger to hold the nut in place and turn things over. Then put the bolt through the hole and give it a few turns so it stays in place:

    • Repeat that process for the other bolt.

    • Use a screwdriver to finish tightening both bolts:

  • Now attach the second motor as well, following those same steps again.

  • Then put your screwdriver back when you're done; we don't have enough for everyone to hang on to them.

  • We'll also use some zipties to keep the wires in a reasonable place before moving on, so that they aren't dragging on the ground when our robot starts moving. Do like this (though you don't have to struggle as much as I do in the video if you don't want to):

    You can then use scissors or something else sharp to cut off the long end of the ziptie that remains (we don't want it dragging on the ground either!). But please be careful when using sharp things.

  • Stick the acrylic to the back of the breadboard (note that you can peel back the paper backing on the bottom of the breadboard to reveal some sticky-tape that you can fasten things to). Try to fasten it so that it's aligned with the breadboard as straight as possible (there are little marks on the acrylic to help you; they should line up with the sides of the breadboard).

    When all is said and done it should look something like:

  • Attach a 9V-battery holder to the other side of the breadboard using the same technique, leaving enough room on one side for the little switch on the 9V-battery holder. Do it like in the photo below, with the battery case toward the back of the breadboard and with the switch facing upward off to one side. This helps keep the weight of the battery roughly centered with respect to the breadboard:

1.3) Circuit Layout

Now we're ready to build our circuit!

Go ahead and lay out your design on the breadboard, using two separate pots so as to make a separate v_{\rm offset} for each motor so that we can adjust each one separately. Note that even though your design should have four op-amps in it, we only need two of the L272 packages (since each one contains two op-amps).

Also, it's a good idea to put the photoresistors toward the end of the breadboard with the wheels attached and point them forward so the robot's "eyes" are looking directly in front of it, with the blinders blocking the overhead lights, like so:

2) Testing

Before you turn your little robot loose on the world, we can do some testing to make sure that it's going to move in roughly the way we expect it to. Set your little robot up on something (like a laptop charger) so that the wheels are free to rotate without making contact with the tabletop (so that we can see how they are moving without our robot running away from us!). Then, when you power things on, you should be able to see how the wheels will move. What we're hoping for is:

  • In ambient light (i.e., with no flashlight nearby), the wheels are spinning so as to move the robot forward (it should be seeking out a bright light source in this case).
  • When the light is directly in front of the robot and about 6 inches away, neither motor is turning.
  • When the light moves closer (still directly in front), the wheels start spinning so as to move the robot backwards), and they should be spinning about the same speed as each other.
  • When the light moves farther away (still directly in front), the wheels start spinning so as to move the robot forward, and they should be spinning about the same speed as each other.
  • When the light gets closer to the left eye than the right eye, the right motor should be spinning faster than the left motor (or, the left motor should be spinning backwards and the right one forwards), so as to turn the robot to face the light. And similarly, if the light gets closer to the right eye, the motors should be moving so as to turn the robot to face the light.

There are several things you can adjust in your circuit to make this happen. If motors seem to be spinning in the wrong directions, how can you fix that? If the motors don't seem to be behaving symmetrically (i.e., the right motor is spinning way faster than the left motor), how can you fix that?

Check Yourself 4:
Now we're ready to actually try it! Be ready to pick up your robot if it starts to run away, but you should be able to get it to follow a cell phone flashlight.

It should approach a nearby light source (including turning itself to face the light if it is slightly off-axis), then maintain a fixed distance from the light (even if the light moves), as shown in the video at the very top of the page.

If it is moving too fast, or in an arc rather than a straight line, you can use the pots to adjust things. Or, if one of the wheels isn't making solid contact with the ground, ask as for help; we have some little weights that we can use to help with that kind of thing.

When it's working, you're ready for your checkoff.

Checkoff 2:

For this checkoff:

  • Discuss your schematic with a staff member.
  • Were there any issues you ran into, either in the design, the physical construction, or the circuit layout?
  • Demonstrate your working robot to a staff member.

Don't forget to clean up when you're done by:

  • keeping your robot if you want it (no need to tear apart the circuit), including the battery, motors, everything;
  • throwing away any left-over resistors and cut wires, or any garbage that's at your spot; and
  • turning off your scope and hanging up the probes.

3) (Optional) Additional Behaviors

Right now, our little robot actively seeks out light sources and turns to face them. But we can make it do other (similarly intelligent) behaviors as well, by changing the way we're connecting the motors to the sensors. For example, by swapping the connections on the motors so that the left eye controls the right motor and vice versa, we can make the robot run toward the light and turn away at the last moment instead of turning toward it. What other kinds of behaviors can you make by changing around the connections?