#define PIN_RELAY  3  // Naar ingang relay.
#define PIN_LDR A0    // lees de waarde van photoresistor - sensor.
float analogLux;      // waar de berekende lux waarde naar geschreven wordt.
void setup() {
  // put your setup code here, to run once:
  pinMode(PIN_RELAY, OUTPUT);
  pinMode(PIN_LDR, INPUT);
  Serial.begin(115200);
}
void loop() {
  // put your main code here, to run repeatedly:
  analogLux = leesLuxWaardeVanSensor ();// waarde in leesLuxW... gaat naar analogLux. 
   Serial.println(analogLux);
  deWaardeVanAnalogLux();   // we wijzen een void functie toe.
}
void deWaardeVanAnalogLux() {         // void functie 
  if (analogLux > 100) {
    digitalWrite(PIN_RELAY, HIGH);   // Code van void functie ( deWaardeVanAnalogLux).
  }
  else {
    digitalWrite(PIN_RELAY, LOW);
  }
}
float leesLuxWaardeVanSensor() {      // bereken de Lux waarde met volgende code.
  // These constants should match the photoresistor's "gamma" and "rl10" attributes
  const float GAMMA = 0.7;
  const float RL10 = 50;
  // Convert the analog value into lux value:
  int analogValue = analogRead(PIN_LDR);
  float voltage = analogValue / 1024. * 5;
  float resistance = 2000 * voltage / (1 - voltage / 5);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
  return lux;      // schrijf lux waarde terug naar lijn 15  'LeesLuxWaardeVanDeSensor'
}