Hookup chat line

If you have not previously installed an Arduino library, please check out our installation guide.language:c /****************************************************************************** Photocell_Example sketch for Spark Fun's photocell - light-variable resistor (https:// Jim Lindblom @ Spark Fun Electronics April 28, 2016 Create a voltage divider circuit combining a photocell with a 4.7k resistor. - The photocell should connect from A0 to 3.3V - Connect an LED to pin 13 (if there's not one built into your Arduino) As the resistance of the photocell increases (surroundings get darker), the voltage at A0 should decrease.

Development environment specifics: Arduino 1.6.7 ******************************************************************************/ const int LIGHT_PIN = A0; // Pin connected to voltage divider output const int LED_PIN = 13; // Use built-in LED as dark indicator // Measure the voltage at 5V and the actual resistance of your // 47k resistor, and enter them below: const float VCC = 4.98; // Measured voltage of Ardunio 5V line const float R_DIV = 4660.0; // Measured resistance of 3.3k resistor // Set this to the minimum resistance require to turn an LED on: const float DARK_THRESHOLD = 10000.0; void setup() void loop() After uploading, open your serial monitor, and set the baud rate to 9600 bps.

The typical light resistance of photocells varies by component.

The mini photocell, for example, usually produces a resistance between 8-20kΩ in normal lighting conditions.

The graph below demonstrates the mini photocell’s illumination and resistance relationship: As you can tell from the graph above, these sensor’s aren’t designed for absolute lux-measurement accuracy – they leave a lot of room for interpretation.

Breadboard and Jumper Wires – The photocell’s legs, like any through-hole resistor, can be bent and shaped to fit.Shining an LED on the sensor can drop the resistance to near-zero, but usually the resistance of the photocell falls between 8-20kΩ in normal lighting conditions.By combining the photocell with a static resistor to create a voltage divider, you can produce a variable voltage that can be read by a microcontroller’s analog-to-digital converter.To measure the photocell’s resistance with a microcontroller’s ADC, we actually have to use it to generate a variable voltage.By combining the photocell with a static resistor, we can create a voltage divider that produces a voltage dependent on the photocell’s resistance.

Leave a Reply