User Tools

Site Tools


tutorials:learn:sensors:cds.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:learn:sensors:cds.html [2010/10/06 19:22]
daigo
tutorials:learn:sensors:cds.html [2016/01/28 18:05] (current)
Line 1: Line 1:
- 
 ====  ==== ====  ====
 +[[http://​www.ladyada.net/​images/​sensors/​cds_LRG.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cds_t.jpg?​nolink&​500x376 ​ |}}]]
  
  
-[[http://​www.ladyada.net/​images/​sensors/​cds_LRG.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cds_t.jpg?​500x376 ​ |}}]] 
  
 +{{ http://​www.ladyada.net/​images/​sensors/​LDR.jpg?​nolink&​486x139 |}}
  
  
-{{ http://​www.ladyada.net/​images/​sensors/​LDR.jpg?​486x139 |}} 
  
- +{{ http://​www.ladyada.net/​images/​sensors/​cdsconstruction.gif?​nolink&500x463 |}}
- +
-{{ http://​www.ladyada.net/​images/​sensors/​cdsconstruction.gif?​500x463 |}}+
  
  
 ==== What is a photocell? ​ ==== ==== What is a photocell? ​ ====
- 
- 
  
  
Line 23: Line 18:
  
  
-Photocells are basically a resistor that changes its resistive value (in ohms Ω) depending on how much light is shining onto the squiggly face. They are very low cost, easy to get in many sizes and specifications,​ but are very innacurate. Each photocell sensor will act a little differently than the other, even if they are from the same batch. The variations can be really large, 50% or higher! For this reason, they shouldn'​t be used to try to determine precise light levels in lux or millicandela. Instead, you can expect to only be able to determine basic light changes+Photocells are basically a resistor that changes its resistive value (in ohms Ω) depending on how much light is shining onto the squiggly face. They are very low cost, easy to get in many sizes and specifications,​ but are very innacurate. Each photocell sensor will act a little differently than the other, even if they are from the same batch. The variations can be really large, 50% or higher! For this reason, they shouldn'​t be used to try to determine precise light levels in lux or millicandela. Instead, you can expect to only be able to determine basic light changes
  
  
Line 30: Line 25:
  
  
-==== Some basic stats  ==== 
  
  
 +
 +==== Some basic stats  ====
  
  
 These stats are for the photocell in the Adafruit shop which is very much like the [[http://​www.ladyada.net/​media/​sensors/​PDV-P8001.pdf|PDV-P8001]]. Nearly all photocells will have slightly different specifications,​ although they all pretty much work the same. If there'​s a datasheet, you'll want to refer to it These stats are for the photocell in the Adafruit shop which is very much like the [[http://​www.ladyada.net/​media/​sensors/​PDV-P8001.pdf|PDV-P8001]]. Nearly all photocells will have slightly different specifications,​ although they all pretty much work the same. If there'​s a datasheet, you'll want to refer to it
- 
  
  
   ***Size: **Round, 5mm (0.2") diameter. (Other photocells can get up to 12mm/​0.4"​ diameter!)   ***Size: **Round, 5mm (0.2") diameter. (Other photocells can get up to 12mm/​0.4"​ diameter!)
   ***Price:** [[http://​www.adafruit.com/​index.php?​main_page=product_info&​cPath=35&​products_id=161|$1.00 at the Adafruit shop]]   ***Price:** [[http://​www.adafruit.com/​index.php?​main_page=product_info&​cPath=35&​products_id=161|$1.00 at the Adafruit shop]]
-  ***Resistance range: **200K&​Omega; ​(dark) to 10K&​Omega; ​(10 lux brightness)+  ***Resistance range: **200K ​Ω (dark) to 10KΩ (10 lux brightness)
   ***Sensitivity range:** CdS cells respond to light between 400nm (violet) and 600nm (orange) wavelengths,​ peaking at about 520nm (green).   ***Sensitivity range:** CdS cells respond to light between 400nm (violet) and 600nm (orange) wavelengths,​ peaking at about 520nm (green).
   ***Power supply:** pretty much anything up to 100V, uses less than 1mA of current on average (depends on power supply voltage)   ***Power supply:** pretty much anything up to 100V, uses less than 1mA of current on average (depends on power supply voltage)
-  *[[http://​www.ladyada.net/​media/​sensors/​PDV-P8001.pdf|**Datasheet**]] and another [[http://​www.ladyada.net/​media/​sensors/​DTS_A9950_A7060_B9060.pdf|**Datasheet**]] +  ​***[[http://​www.ladyada.net/​media/​sensors/​PDV-P8001.pdf|Datasheet]]** and another ​**[[http://​www.ladyada.net/​media/​sensors/​DTS_A9950_A7060_B9060.pdf|Datasheet]]** 
-  *Two[[http://​www.ladyada.net/​media/​sensors/​APP_PhotocellIntroduction.pdf| ​**application notes on using**]] and [[http://​www.ladyada.net/​media/​sensors/​gde_photocellselecting.pdf|**selecting photocells**]] where nearly all of these graphs are taken from +  *Two**[[http://​www.ladyada.net/​media/​sensors/​APP_PhotocellIntroduction.pdf|application notes on using]]** and **[[http://​www.ladyada.net/​media/​sensors/​gde_photocellselecting.pdf|selecting photocells]]** where nearly all of these graphs are taken from  
 ==== Problems you may encounter with multiple sensors... ​ ==== ==== Problems you may encounter with multiple sensors... ​ ====
- 
- 
  
  
Line 61: Line 55:
  
  
 +As we've said, a photocell'​s resistance changes as the face is exposed to more light. When its dark, the sensor looks like an large  resistor up to 10MΩ, as the light level increases, the resistance goes  down. This graph indicates approximately the resistance of the sensor ​ at different light levels. Remember each photocell will be a little different so use this as a guide only!
  
- +{{  http://​www.ladyada.net/​images/​sensors/​graph.gif?​nolink&500x351 ​ |}}
-As we've said, a photocell'​s resistance changes as the face is exposed to more light. When its dark, the sensor looks like an large  resistor up to 10M&​Omega;,​ as the light level increases, the resistance goes  down. This graph indicates approximately the resistance of the sensor ​ at different light levels. Remember each photocell will be a little different so use this as a guide only! +
- +
-{{  http://​www.ladyada.net/​images/​sensors/​graph.gif?​500x351 ​ |}}+
  
  
Line 75: Line 67:
 Photocells, particularly the common CdS cells that you're likely to find, are not sensitive to all light. In particular they tend to be sensitive to light between 700nm (red) and 500nm (green) light. Photocells, particularly the common CdS cells that you're likely to find, are not sensitive to all light. In particular they tend to be sensitive to light between 700nm (red) and 500nm (green) light.
  
-{{  http://​www.ladyada.net/​images/​sensors/​cdsspectrum.gif?​516x389 ​ |}}+{{  http://​www.ladyada.net/​images/​sensors/​cdsspectrum.gif?​nolink&516x389 ​ |}}
  
  
Line 83: Line 75:
  
 ==== What the heck is lux?  ==== ==== What the heck is lux?  ====
- 
- 
  
  
 Most datasheets use [[http://​en.wikipedia.org/​wiki/​Lux|lux]] to indicate the resistance at certain light levels. But what is [[http://​en.wikipedia.org/​wiki/​Lux|lux]]?​ Its not a method we tend to use to describe brightness so its tough to gauge. Here is a table [[http://​en.wikipedia.org/​wiki/​Lux|adapted from a Wikipedia article on the topic!]] Most datasheets use [[http://​en.wikipedia.org/​wiki/​Lux|lux]] to indicate the resistance at certain light levels. But what is [[http://​en.wikipedia.org/​wiki/​Lux|lux]]?​ Its not a method we tend to use to describe brightness so its tough to gauge. Here is a table [[http://​en.wikipedia.org/​wiki/​Lux|adapted from a Wikipedia article on the topic!]]
- 
  
  
 ^Illuminance^Example^ ^Illuminance^Example^
-|**0.002 lux** |Moonless clear night sky | +|**0.002 lux**|Moonless clear night sky | 
-|**0.2 lux** |Design minimum for emergency lighting (AS2293).| +|**0.2 lux**|Design minimum for emergency lighting (AS2293).| 
-|**0.27 - 1 lux** |Full moon on a clear night|  +|**0.27 - 1 lux**|Full moon on a clear night| 
-|**3.4 lux**|Dark limit of civil twilight under a clear sky|  +|**3.4 lux**|Dark limit of civil twilight under a clear sky| 
-|**50 lux**|Family living room| +|**50 lux**|Family living room|
 |**80 lux**|Hallway/​toilet| |**80 lux**|Hallway/​toilet|
-|**100 lux** |Very dark overcast day| +|**100 lux**|Very dark overcast day| 
-|**300 - 500 lux** |Sunrise or sunset on a clear day. Well-lit office area.|  +|**300 - 500 lux**|Sunrise or sunset on a clear day. Well-lit office area.| 
-|**1,000 lux** |Overcast day; typical TV studio lighting|  +|**1,000 lux**|Overcast day; typical TV studio lighting| 
-|**10,000 - 25,000 lux** |Full daylight (not direct sun)| +|**10,000 - 25,000 lux**|Full daylight (not direct sun)| 
-|**32,000 - 130,000 lux** |Direct sunlight| ​+|**32,000 - 130,000 lux**|Direct sunlight|
  
 ==== Testing your photocell ​ ==== ==== Testing your photocell ​ ====
  
  
 +The easiest way to determine how your photocell works is to[[http://​www.ladyada.net/​learn/​multimeter/​| connect a multimeter in resistance-measurement mode]] to the two leads and see how the resistance changes when shading the sensor with your hand, turning off lights, etc.  Because the resistance changes a lot, an auto-ranging meter works well  here. Otherwise, just make sure you try different ranges, between 1MΩ and 1KΩ before '​giving up'
  
 +[[http://​www.ladyada.net/​images/​sensors/​cdslitmm.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdslitmm_t.jpg?​nolink&​500x375 ​ |}}]]
  
-The easiest way to determine how your photocell works is to[[http://​www.ladyada.net/​learn/​multimeter/​| connect a multimeter in resistance-measurement mode]] to the two leads and see how the resistance changes when shading the sensor with your hand, turning off lights, etc.  Because the resistance changes a lot, an auto-ranging meter works well  here. Otherwise, just make sure you try different ranges, between 1M&​Omega;​ and 1K&​Omega;​ before '​giving up' +[[http://​www.ladyada.net/​images/​sensors/​cdscovered.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdscovered_t.jpg?​nolink&500x375 ​ |}}]]
- +
-[[http://​www.ladyada.net/​images/​sensors/​cdslitmm.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdslitmm_t.jpg?​500x375 ​ |}}]] +
- +
-[[http://​www.ladyada.net/​images/​sensors/​cdscovered.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdscovered_t.jpg?​500x375 ​ |}}]]+
  
  
 ==== Connecting to your photocell ​ ==== ==== Connecting to your photocell ​ ====
- 
- 
  
  
 Because photocells are basically resistors, they are non-polarized. That means you can connect them up '​either way' and they'​ll work just fine! Because photocells are basically resistors, they are non-polarized. That means you can connect them up '​either way' and they'​ll work just fine!
  
-[[http://​www.ladyada.net/​images/​sensors/​cdsbb.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdsbb_t.jpg?​500x376 ​ |}}]]+[[http://​www.ladyada.net/​images/​sensors/​cdsbb.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdsbb_t.jpg?​nolink&500x376 ​ |}}]]
  
  
Line 129: Line 114:
 Photocells are pretty hardy, you can easily solder to them, clip the leads, plug them into breadboards,​ use alligator clips, etc. The only care you should take is to avoid bending the leads right at the epoxied sensor, as they could break off if flexed too often. Photocells are pretty hardy, you can easily solder to them, clip the leads, plug them into breadboards,​ use alligator clips, etc. The only care you should take is to avoid bending the leads right at the epoxied sensor, as they could break off if flexed too often.
  
-[[http://​www.ladyada.net/​images/​sensors/​cdswired.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdswired_t.jpg?​500x376 ​ |}}]]+[[http://​www.ladyada.net/​images/​sensors/​cdswired.jpg|{{ ​ http://​www.ladyada.net/​images/​sensors/​cdswired_t.jpg?​nolink&500x376 ​ |}}]]
  
  
Line 135: Line 120:
  
  
 +{{ blip>​2135323| }}
 + ​[[http://​www.adafruit.com/​blog/​2009/​05/​19/​piezo-with-an-arduino-photoresistor/​|Noisemaker that changes frequency based on light level. ​   ]]
  
- ​\\ ​ 
  
-Noisemaker that changes frequency based on light level. ​   ​+{{ youtube>​t5IS33X6Dm8 ||}} 
 + Motor value and directional control with photoresistors and microcontroller
  
-<object width="​425"​ height="​344"><​param name="​movie"​ value="​http://​www.youtube.com/​v/​t5IS33X6Dm8&​hl=en&​fs=1"​></​param><​param name="​allowFullScreen"​ value="​true"></​param><​param name="​allowscriptaccess"​ value="​always"></​param></​object>​ +{{ youtube>​jbJu1xQ4rRk ​|}}
- \\  +
-Motor value and directional control with photoresistors and microcontroller +
- +
-<object width="​425"​ height="​344"><​param name="​movie"​ value="​http://​www.youtube.com/​v/​jbJu1xQ4rRk&​hl=en&​fs=1"></​param><​param name="​allowFullScreen"​ value="​true"></​param><​param name="​allowscriptaccess"​ value="​always"></​param></​object>​ +
- ​\\ ​+
 Line-following robot that uses photocells to detect the light bouncing off of white/black stripes ​ Line-following robot that uses photocells to detect the light bouncing off of white/black stripes ​
  
-<object width="​550"​ height="​316"​><param name="​allowfullscreen"​ value="​true"​ /><​param name="​allowscriptaccess"​ value="​always"​ /><​param name="​movie"​ value="​http://​vimeo.com/​moogaloop.swf?​clip_id=4212409&​server=vimeo.com&​show_title=0&​show_byline=0&​show_portrait=0&​color=00ADEF&​fullscreen=1"​ /></​object>​ +{{ vimeo>​4212409 ​}}
- ​\\ ​+
 [[http://​tinkerlog.com/​2009/​04/​18/​arduino-powered-braitenberg-vehicle/​|Another robot, this one has two sensors and moves towards light]] (they'​re called Braitenberg vehicles) [[http://​tinkerlog.com/​2009/​04/​18/​arduino-powered-braitenberg-vehicle/​|Another robot, this one has two sensors and moves towards light]] (they'​re called Braitenberg vehicles)
  
-<object width="​425"​ height="​344"​><param name="​movie"​ value="​http://​www.youtube.com/​v/​EW3nTjMCdcg&​color1=0xb1b1b1&​color2=0xcfcfcf&​feature=player_embedded&​fs=1"></​param><​param name="​allowFullScreen"​ value="​true"></​param></​object>​ +{{ youtube>​EW3nTjMCdcg ​|}}
- ​\\ ​+
 [[http://​www.instructables.com/​id/​Another_Arduino_Laser_Tripwire/​|Using a photocell and pocket laser pointer to create a breakbeam sensor]] ​ [[http://​www.instructables.com/​id/​Another_Arduino_Laser_Tripwire/​|Using a photocell and pocket laser pointer to create a breakbeam sensor]] ​
  
  
 ==== Analog voltage reading method ​ ==== ==== Analog voltage reading method ​ ====
- 
- 
  
  
 The easiest way to measure a resistive sensor is to connect one end to Power and the other to a **pull-down** resistor to ground. Then the point between the fixed pulldown resistor and the variable photocell resistor is connected to the analog input of a microcontroller such as an Arduino (shown) The easiest way to measure a resistive sensor is to connect one end to Power and the other to a **pull-down** resistor to ground. Then the point between the fixed pulldown resistor and the variable photocell resistor is connected to the analog input of a microcontroller such as an Arduino (shown)
  
-{{  http://​www.ladyada.net/​images/​sensors/​cdsanasch.gif?​162x322 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdspulldowndiag.gif?​604x362 |}}+{{  http://​www.ladyada.net/​images/​sensors/​cdsanasch.gif?​nolink&162x322 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdspulldowndiag.gif?​nolink&604x362 |}}
  
  
Line 172: Line 150:
  
  
-The way this works is that as the resistance of the photocell decreases, the total resistance of the photocell and the pulldown resistor decreases from over 600K&​Omega; ​to 10K&Omega;. That means that the current flowing through both resistors increases which in turn causes the voltage across the fixed 10K&​Omega; ​resistor to increase. Its quite a trick!+The way this works is that as the resistance of the photocell decreases, the total resistance of the photocell and the pulldown resistor decreases from over 600KΩ to 10KΩ. That means that the current flowing through both resistors ​//increases// which in turn causes the voltage across the fixed 10KΩ resistor to increase. Its quite a trick!
  
  
-^Ambient light like...^^Ambient light (lux)^^Photocell resistance (&Omega;)^^LDR + R (&Omega;)^^Current thru LDR +R^^Voltage across R^| +^Ambient light like...^Ambient light (lux)^Photocell resistance (Ω)^LDR + R (Ω)^Current thru LDR +R^Voltage across R^ 
-^Dim hallway^^0.1 lux^|600K&​Omega;​| \\ |610 K&​Omega;​| \\ |0.008 mA| \\ |0.1 V| \\ +^Dim hallway^0.1 lux|600KΩ|610 KΩ|0.008 mA|0.1 V| 
-^Moonlit night^^1 lux^|70 K&​Omega;​| \\ |80 K&​Omega;​| \\ |0.07 mA| \\ |0.6 V| \\ +^Moonlit night^1 lux|70 KΩ|80 KΩ|0.07 mA|0.6 V| 
-^Dark room^^10 lux^|10 K&​Omega;​| \\ |20 K&​Omega;​| \\ |0.25 mA| \\ |2.5 V| \\ +^Dark room^10 lux|10 KΩ|20 KΩ|0.25 mA|2.5 V| 
-^Dark overcast day / Bright room^^100 lux^|1.5 K&​Omega;​| \\ |11.5 K&​Omega;​| \\ |0.43 mA| \\ |4.3 V| \\ +^Dark overcast day / Bright room^100 lux|1.5 KΩ|11.5 KΩ|0.43 mA|4.3 V| 
-^Overcast day^^1000 lux^|300 &​Omega;​| \\ |10.03 K&​Omega;​| \\ |0.5 mA| \\ |5V| \\ |+^Overcast day^1000 lux|300 ​Ω|10.03 KΩ|0.5 mA|5V|
  
  
 +//This table indicates the approximate analog voltage based on the sensor light/​resistance w/a 5V supply and 10KΩ pulldown resistor//
  
-This table indicates the approximate analog voltage based on the sensor light/​resistance w/a 5V supply and 10K&​Omega;​ pulldown resistor 
  
  
 +If you're planning to have the sensor in a bright area and use a 10KΩ pulldown, it will quickly //​saturate//​. That means that it will hit the '​ceiling'​ of 5V and not be able to differentiate between kinda bright and really bright. In that case, you should replace the 10KΩ pulldown with a 1KΩ pulldown. In that case, it will not be able to detect dark level differences as well but it will be able to detect bright light differences better. This is a tradeoff that you will have to decide upon!
  
  
-If you're planning to have the sensor in a bright area and use a 10K&​Omega;​ pulldown, it will quickly saturate. That means that it will hit the '​ceiling'​ of 5V and not be able to differentiate between kinda bright and really bright. In that case, you should replace the 10K&​Omega;​ pulldown with a 1K&​Omega;​ pulldown. In that case, it will not be able to detect dark level differences as well but it will be able to detect bright light differences better. This is a tradeoff that you will have to decide upon! +^Ambient light like...^Ambient light (lux)^Photocell resistance (Ω)^LDR + R (Ω)^Current thru LDR+R^Voltage across R^ 
- +^Moonlit night^1 lux|70 KΩ|71 KΩ|0.07 mA|0.1 V| 
- +^Dark room^10 lux|10 KΩ|11 KΩ|0.45 mA|0.5 V| 
-^Ambient light like...^^Ambient light (lux)^^Photocell resistance (&Omega;)^^LDR + R (&Omega;)^^Current thru LDR+R^^Voltage across R^ +^Dark overcast day / Bright room^100 lux|1.5 KΩ|2.5 KΩ|2 mA|2.0 V| 
-^Moonlit night^^1 lux^|70 K&​Omega;​| \\ |71 K&​Omega;​| \\ |0.07 mA| \\ |0.1 V| \\ +^Overcast day^1000 lux|300 ​Ω|1.3 KΩ|3.8 mA|3.8 V| 
-^Dark room^^10 lux^|10 K&​Omega;​| \\ |11 K&​Omega;​| \\ |0.45 mA| \\ |0.5 V| \\ +^Full daylight^10,​000 lux|100 ​Ω|1.1 KΩ|4.5 mA|4.5 V| 
-^Dark overcast day / Bright room^^100 lux^|1.5 K&​Omega;​| \\ |2.5 K&​Omega;​| \\ |2 mA| \\ |2.0 V| \\ +//This table indicates the approximate analog voltage based on the sensor light/​resistance w/a 5V supply and 1K pulldown resistor//
-^Overcast day^^1000 lux^|300 &​Omega;​| \\ |1.3 K&​Omega;​| \\ |3.8 mA| \\ |3.8 V| \\ +
-^Full daylight^^10,000 lux^|100 &​Omega;​| \\ |1.1 K&​Omega;​| \\ |4.5 mA| \\ |4.5 V| \\ +
-This table indicates the approximate analog voltage based on the sensor light/​resistance w/a 5V supply and 1K pulldown resistor +
  
 Note that our method does not provide linear voltage with respect to brightness! Also, each sensor will be different. As the light level increases, the analog voltage goes up even though the resistance goes down: Note that our method does not provide linear voltage with respect to brightness! Also, each sensor will be different. As the light level increases, the analog voltage goes up even though the resistance goes down:
  
-<p align="​center"​ class="​style1"​>Vo = Vcc ( R / (R + Photocell) )+<code>Vo = Vcc ( R / (R + Photocell) )</​code>​
  
 That is, the voltage is proportional to the **inverse** of the photocell resistance which is, in turn, inversely proportional to light levels That is, the voltage is proportional to the **inverse** of the photocell resistance which is, in turn, inversely proportional to light levels
Line 209: Line 184:
  
 ==== Simple demonstration of use  ==== ==== Simple demonstration of use  ====
- +{{  http://​www.ladyada.net/​images/​sensors/​cdslitetestdiag.gif?​nolink&628x394 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdsliteschem.gif?​nolink&286x357 |}}
- +
-{{  http://​www.ladyada.net/​images/​sensors/​cdslitetestdiag.gif?​628x394 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdsliteschem.gif?​286x357 |}}+
  
 This sketch will take the analog voltage reading and use that to determine how bright the red LED is. The darker it is, the brighter the LED will be! Remember that the LED has to be connected to a PWM pin for this to work, I use pin 11 in this example. ​ This sketch will take the analog voltage reading and use that to determine how bright the red LED is. The darker it is, the brighter the LED will be! Remember that the LED has to be connected to a PWM pin for this to work, I use pin 11 in this example. ​
  
-These examples assume you know some basic Arduino programming. If you don't, [[../​arduino/​index.html|maybe spend some time reviewing the basics at the Arduino tutorial?]] +These examples assume you know some basic Arduino programming. If you don't, [[http://www.ladyada.net/learn/​arduino/​index.html|maybe spend some time reviewing the basics at the Arduino tutorial?]]
  
 <code C>/* Photocell simple testing sketch. ​ <code C>/* Photocell simple testing sketch. ​
Line 248: Line 220:
   ​   ​
   delay(100);   delay(100);
-}</​code>​ +}</​code>​{{ ​ http://​www.ladyada.net/​images/​sensors/​cdslitetestout.gif?​nolink&500x357 ​ |}}
-{{  http://​www.ladyada.net/​images/​sensors/​cdslitetestout.gif?​500x357 ​ |}}+
  
  
Line 257: Line 228:
  
 ==== Simple code for analog light measurements ​ ==== ==== Simple code for analog light measurements ​ ====
- 
- 
  
  
 This code doesn'​t do any calculations,​ it just prints out what it interprets as the amount of light in a qualitative manner. For most projects, this is pretty much all thats needed! This code doesn'​t do any calculations,​ it just prints out what it interprets as the amount of light in a qualitative manner. For most projects, this is pretty much all thats needed!
  
-{{  http://​www.ladyada.net/​images/​sensors/​cdspulldowndiag.gif?​604x362 ​ |}} +{{  http://​www.ladyada.net/​images/​sensors/​cdspulldowndiag.gif?​nolink&604x362 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdsanasch.gif?​nolink&162x322 |}}<code C>/* Photocell simple testing sketch. ​
-{{ http://​www.ladyada.net/​images/​sensors/​cdsanasch.gif?​162x322 |}} +
-<code C>/* Photocell simple testing sketch. ​+
  
 Connect one end of the photocell to 5V, the other end to Analog 0. Connect one end of the photocell to 5V, the other end to Analog 0.
Line 301: Line 268:
 }</​code>​ }</​code>​
  
- +To test it, I started in a sunlit (but shaded) room and covered the sensor with my hand, then covered it with a piece of blackout fabric.{{ ​ http://​www.ladyada.net/​images/​sensors/​cdssimpletestout.gif?​nolink&508x316 ​ |}}
-To test it, I started in a sunlit (but shaded) room and covered the sensor with my hand, then covered it with a piece of blackout fabric. +
-{{  http://​www.ladyada.net/​images/​sensors/​cdssimpletestout.gif?​508x316 ​ |}}+
  
  
 ==== BONUS! Reading photocells without analog pins  ==== ==== BONUS! Reading photocells without analog pins  ====
- 
- 
  
  
 Because photocells are basically resistors, its possible to use them even if you don't have any analog pins on your microcontroller (or if say you want to connect more than you have analog input pins). The way we do this is by taking advantage of a basic electronic property of resistors and capacitors. It turns out that if you take a capacitor that is initially storing no voltage, and then connect it to power (like 5V) through a resistor, it will charge up to the power voltage slowly. The bigger the resistor, the slower it is.  Because photocells are basically resistors, its possible to use them even if you don't have any analog pins on your microcontroller (or if say you want to connect more than you have analog input pins). The way we do this is by taking advantage of a basic electronic property of resistors and capacitors. It turns out that if you take a capacitor that is initially storing no voltage, and then connect it to power (like 5V) through a resistor, it will charge up to the power voltage slowly. The bigger the resistor, the slower it is. 
  
-{{  http://​www.ladyada.net/​images/​sensors/​RCtimecapture.jpg?​640x480 ​ |}} \\  +{{  http://​www.ladyada.net/​images/​sensors/​RCtimecapture.jpg?​nolink&640x480 ​ |}} \\ //This capture from an oscilloscope shows whats happening on the digital pin (yellow). The blue line indicates when the sketch starts counting and when the couting is complete, about 1.2ms later.//
-This capture from an oscilloscope shows whats happening on the digital pin (yellow). The blue line indicates when the sketch starts counting and when the couting is complete, about 1.2ms later.+
  
  
Line 320: Line 282:
 This is because the capacitor acts like a bucket and the resistor is like a thin pipe. To fill a bucket up with a very thin pipe takes enough time that you can figure out how wide the pipe is by timing how long it takes to fill the bucket up halfway. ​ This is because the capacitor acts like a bucket and the resistor is like a thin pipe. To fill a bucket up with a very thin pipe takes enough time that you can figure out how wide the pipe is by timing how long it takes to fill the bucket up halfway. ​
  
-{{  http://​www.ladyada.net/​images/​sensors/​CdSRCtimediag.gif?​598x379 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdsRCschm.gif?​182x345 |}}+{{  http://​www.ladyada.net/​images/​sensors/​CdSRCtimediag.gif?​nolink&598x379 ​ |}}{{ http://​www.ladyada.net/​images/​sensors/​cdsRCschm.gif?​nolink&182x345 |}}
  
  
  
 In this case, our '​bucket'​ is a 0.1uF ceramic capacitor. You can change the capacitor nearly any way you want but the timing values will also change. 0.1uF seems to be an OK place to start for these photocells. If you want to measure brighter ranges, use a 1uF capacitor. If you want to measure darker ranges, go down to 0.01uF. In this case, our '​bucket'​ is a 0.1uF ceramic capacitor. You can change the capacitor nearly any way you want but the timing values will also change. 0.1uF seems to be an OK place to start for these photocells. If you want to measure brighter ranges, use a 1uF capacitor. If you want to measure darker ranges, go down to 0.01uF.
 +
  
 <code C>/* Photocell simple testing sketch. ​ <code C>/* Photocell simple testing sketch. ​
Line 385: Line 348:
   ​   ​
   return reading;   return reading;
-}</​code>  ​ +}</​code> ​ {{  http://​www.ladyada.net/​images/​sensors/​cdsrctimeout.gif?​nolink ​ ​|}} ​
-{{  http://​www.ladyada.net/​images/​sensors/​cdsrctimeout.gif ​ |}} +
/home/ladyada/public_html/wiki/data/attic/tutorials/learn/sensors/cds.html.1286392929.txt.gz · Last modified: 2016/01/28 18:05 (external edit)