Arduino Sunset-Dimmer

I made myself an Arduino Sunset-Dimmer, which increases the light when the sun goes down.
 The layout of the PCB is designed here:




The Code is designed this way:
int light= 7;

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);
}
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.
If you also use a relay, you also have to change the values in the if-functions.

Beliebte Posts aus diesem Blog

Smarthome Entwicklung

ESP8266: LED-Matrix Control by Webinterface

Getting Started: ESP8266-12E [ENGLISH]