Home Chipkit Chipkit Uno and LDR warning example

Chipkit Uno and LDR warning example

by shedboy71

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

Code

[codesyntax lang=”cpp”]

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);
    delay(500);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

[/codesyntax]

Share

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More