- //january 8, 2015
- // Light on/off
- // LED changes color depending on darkness that photo
- // resistor receives
- int Pr = 0; // will be used for analog 0.
- int PrValue = 0; // value of output
- int Pr_Input = 700; // value of when light is on
- void setup()
- {
- Serial.begin(9600); //start serial Monitor
- pinMode(13, OUTPUT); // pin 13 as output
- }
- void loop()
- {
- PrValue = analogRead(Pr);
- Serial.println(PrValue); //prints photoresistor value
- delay(100); // value updated every 0.1 second.
- if (PrValue < Pr_Input) // if sensor value is less than 700, light will turn on.
- {
- digitalWrite(13, HIGH); //turns on LED
- }
- else
- {
- digitalWrite(13, LOW); // LED off
- }
- }