Loading... Please wait...

LightDependentResistor

LightDependentResistor

This example shows how to use a light dependent resistor to determine the relative ambient light.

Hardware Required

  • Arduino Board
  • Light dependent resistor (LDR) supplied in the oddWires kit
  • 10K ohm resistor (one of the 10 supplied in the oddWires kit)

Circuit

To build the circuit, attach one end of a 10k-ohm resistor to GND and connect the other to the LDR. Then attach the other end of the LDR to Vcc (+5V). Connect the center of the resistor/light depdendent resistor join to Analog pin A0. The ambient light is proprtional to the analog voltage measured.

 

arduino-thermistor-voltage-divider-bb.png

Code

/* Here is a bare-bones Arduino sketch to read the output of a light depdendent resistor light detector.
   The data are read every 1.0 second in this example. However, you can change the
   sampling rate by simply changing the argument of the delay() statement.
   
   If you use a 1K ohm pad resistor you will measure somewhere around 4V when open to full
   light and down to around 2V when fully dark.
 */
 
#define inPin0 A0
 
void setup(void) {
 
  Serial.begin(9600);
  Serial.println();
     
}
 
void loop(void) {
   
  int pinRead0 = analogRead(inPin0);
  float pVolt0 = pinRead0 / 1024.0 * 5.0;
  Serial.print(pVolt0);
  Serial.println();
   
  delay(1000);
   
}

 

What's News

newsletter

Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires