Hi! I found code for twinkling lights to sew onto a skirt and I need to incorporate the light sensor into it. The idea is that when the lights go out, I need the skirt's LEDs to sparkle with the code. I do not know how to incorporate that into the code.
Here is the original post with the code: Beginning LilyPad Arduino - SparkFun Electronics
The first step could be to try to turn the onboard LED on/off with an LDR connected to an analogue input.
If you can do that, then think of combining the LDR code with the code you have.
Try this (untested).
Leo..
int LDRpin = A0; // LDR between A0 and ground
int ledPin = 13; // use the onboard LED for testing
int sensorValue = 0; // the light/dark value
void setup() {
pinMode(LDRpin, INPUT_PULLUP); // enable the internal pullup resistor, so you don't need an external one
pinMode(ledPin, OUTPUT); // make the LEDpin an output
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(LDRpin); // read A0
Serial.println(sensorValue);
if (sensorValue > 900) { // if darker than this value
digitalWrite(ledPin, HIGH); // LED on
}
if (sensorValue < 800) { // if lighter than this value
digitalWrite(ledPin, LOW); // LED off
}
delay(1000); // some delay
}