The layout of the PCB is designed here:
int light= 7;NOTICE: The code is specialised for my room. If you want to improve the code to use it by yourself, look at the "int ledlevel = map(sensorvalue, 0, 140, 255, 0)" function. The 140 gives the maximal value, the light turns off, when the sun is too bright. If there is no light, the light is set to the maximum value of 255.
int led = 9;
int relay = 2;
void setup(){
analogReference(DEFAULT);
pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);
Serial.begin(9600);
}
void loop(){
int sensorvalue = analogRead(light);
Serial.println(sensorvalue);
if(sensorvalue < 140){digitalWrite(relay, LOW);}
if(sensorvalue > 140){digitalWrite(relay, HIGH);}
int ledlevel = map(sensorvalue, 0, 140, 255, 0);
analogWrite(led, ledlevel);
delay(10000);
}
If you also use a relay, you also have to change the values in the if-functions.