Setting up a serial connection

when the room light is turned off, the led activates!

I pulled a value from a simple photoresistor to make this happen. The arduino code is posted bellow.

IMG_1810 IMG_1811

int led = 8;
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop() {
int sensorValue = analogRead(A1);
sensorValue = map(sensorValue,0,1024,0,500);
Serial.println(sensorValue);
delay(1);
if (sensorValue < 34) {
digitalWrite(led,HIGH);
} else {
digitalWrite(led,LOW);
}
}

Leave a Reply