// Include Arduino Wire library for I2C #include // Define Slave I2C Address #define SLAVE_ADDR 9 // Define LED Pin int LED = 13; // Variable for received data int rd; // Variable for ldr status int ldrStatus; void setup() { pinMode(LED, OUTPUT); // Initialize I2C communications as Slave Wire.begin(SLAVE_ADDR); // Function to run when data received from master Wire.onReceive(receiveEvent); // Setup Serial Monitor Serial.begin(9600); } void receiveEvent() { // read one character from the I2C rd = Wire.read(); } void loop() { delay(50); // Calculate ldr value ldrStatus = map(rd, 1, 255, 0, 1023); if (ldrStatus >=300) { // if the value is higher than 300, LEDs is off digitalWrite (LED, LOW); Serial.println("it's bright"); } else { // if the value is lower than 300, both LEDs is on digitalWrite (LED, HIGH); Serial.println("it's dark"); } Serial.println(ldrStatus); }