Chipkit Uno and LDR warning example

This example is like a dark activated alarm using an LDR and a LED, in this case when the value read in drops below a certain level the LED will light. In the real world you could make a dark activated night light or alarm.

Its a fairly basic circuit, I connected the LED to D8, no real reason. LDR still connects to A0

Schematic and Layout

Chipkit and LDR and LED_schem Chipkit and LDR and LED_bb


int sensorPin = A0; // select the input pin for the ldr
int ledPin = 8; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() 
  pinMode(ledPin, OUTPUT);
void loop() 
  sensorValue = analogRead(sensorPin);
  if(sensorValue <= 400)
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin, LOW);
Previous articleChipkit UNO and LDR example
Next articleChipkit Uno and DHT11 sensor example