Purpose:
In a previous exploration we looked at how to communicate with the Arduino through the serial monitor which is handy and you will find it useful almost every time you create a sketch for your own purposes. In some way the serial monitor is like the mouth and ears of the Arduino that allow it to communicate with humans. What we need to do now is create additional senses for our Arduino so it can have a greater awareness of what is happening in the world around it. You can imagine how handy it would be to be aware of how much light there is, how wet the soil is, whether a particular switch has been engaged, and hundreds of other characteristics of the world.
What the Arduino can detect is voltage. This is it's only sense. In order to sense the sort of features of the world that I mentioned above we have to create some way to convert light or wetness or contact into a voltage. The generic term for objects that do this is transducers though we usually refer to them as sensors. There are photosensors, pressure sensors, and a myriad of other sensors. The sensors themselves can be quite complicated but ultimately what they are doing is converting something about the world into a voltage that the Arduino can measure. As you might imagine there are a nearly limitless set of possibilities and we will only scratch the surface.
Given our experiences this term with my labs I would hasten to note that this lab may have some unexpected bugs and oddness in the exercises. I apologize in advance and ask you to remember that what I'm trying to facilitate is how you are learning how to learn. I actually find out more about how to help you from the tasks that don't work so well than the ones that go smoothly. I'm sorry for the frustration that produces but that is part of the process.
Procedure:
I want to start by discussing an important distinction about the pins on the Arduino. As you may have noticed some of the input/output (I/O) pins are labeled as digital and some are labeled as analog. Each type of pin is useful for diferent tasks. When the Arduino looks at a digital pin it can only tell if it's High or Low (nominally 5 V or 0V though it is more complex than this). Through the analog pins the Arduino is able to distinguish a range of voltages between 0 V and 5 V (again the details are more complex but this is a good starting point).
1) Here are some documents to read before we get too deep into this. Read these two pages on digitalRead and analogRead. Follow up on by reading about logic levels and pin levels (ignore the rest of the page for now).
2) Then get a potentiometer from the lab instructor and follow through this tutorial. You will find some additional useful information on Adafruit's version of this activity here and here. Before you move away from this section of the lab repeat the same experimental setup but with the potentiometer connected to a digital pin (using digitalRead()) and notice what happens as you turn the adjustment on the pot!
3) Now read these two threads from stackexchange. The first one reflects a reasonable but erroneous use of a photocell to make sensor for an Arduino. The second explains a bit better why the circuit is set up the way it is. Be sure you understand what was wrong with the first one.
5) Finally go through this Adafruit tutorial (you may well want to read the sections leading up to this part) and be ready to demonstrate that you can use your photocell to turn on an LED in response to a particular light level. Be ready to demonstrate that your can set the response level of your system using the serial monitor.
- LAB Deliverables:
1)Demo: Demonstrate that you can read voltages controlled by a potentiometer with your Arduino and print the result to the serial monitor. You will be asked to change the wiper on the potentiometer and show that the output changes.
2) Demo: Demonstrate that you can do the same process described in 1) for a digital pin.
3) Document/Turnitin: Determine the typical resistance of your photocell and explain your reasoning for the choice of resistor you are pairing with it. Your response.
4) Demo: Demonstrate that you can turn on an LED in response to a particular light level detected by your photocell and adjust the level at which the LED is turned on. Communicate that level via the serial monitor.
This link provides a central location for documents and links specifically relevant to this lab.
More general resources for this course and the lab are accessible from the Web Resources page.