#define LDR 2 #define REDLight 7 #define GREENLight 8 float LDRval = 0; float sunny = 0; // calibrate sensor value WHEN LIGHT float dark = 1024; // calibrate sensor value WHEN DARK float treshold = 50; // define treshold to turn lights ON or OFF #include SoftwareSerial mySerial(0, 1); // RX, TX (0 y 1) void setup() { mySerial.begin(9600); pinMode(LDR, INPUT); pinMode(6, OUTPUT); pinMode(8, OUTPUT); } void loop() { if (analogRead(LDR) < 500) { digitalWrite(7,HIGH); digitalWrite(8,LOW); } else { digitalWrite(7,LOW); digitalWrite(8,HIGH); } LDRval = map(analogRead(LDR),sunny,dark,0,100); mySerial.print("LDR Read: "); mySerial.print(analogRead(LDR)); mySerial.print(" Light Percent: "); mySerial.print(LDRval); mySerial.println(" %"); }