Lightsensor test - LucasSerra/coffeeMachine GitHub Wiki
// Defines the pins to which the light sensor and LED are connected. const int pinLight = A0; const int pinLed = 7;
// Defines the light-sensor threshold value to see if the room light is on or off int thresholdvalue = 400;
void setup() { Serial.begin(9600); // Configure the LED's pin for output signals. pinMode(pinLed, OUTPUT); }
void loop() { // Read the value of the light sensor. The light sensor is an analog sensor. int sensorValue = analogRead(pinLight);
Serial.println(sensorValue);
// Turn the LED on if the sensor value is below the threshold.
if(sensorValue < thresholdvalue)
{
Serial.println("luz apagada");
}
else
{
Serial.println("luz acesa");
}
}