Smart Lighting System


Thinking of building a smart house? Or you just want to wow yourself on the possibilities of using a microcontroller let’s take you through this tutorial of creating a smart lighting system that turns ON a bulb when the surrounding light (light from the sun) isn’t bright enough and it switches the bulb OFF when the surrounding light is bright.


List of Components


LDR – Light Dependent Resistor

Relay module


Jumper wires


InventOne dev board


You can get your components from any electronic store around you or you’d order online from aliexpress, hub360, or ebay. To order for  inventone boards please click this order link.



You might need to brush up on how a relay and LDR work.

To give you a head start, an LDR is a light dependent resistor whose resistance varies depending on the intensity of light falling on it when the light intensity is high enough the LDR behaves like a short circuit and when no light falls on it the LDR behaves like an open circuit.

Also a relay is a device used for switching a large electronic device using very small electrical signals. For example, a relay allows you to control AC using DC which is a valuable asset to every engineer.


Circuit diagram for smart lighting system
Circuit diagram for Smart Lighting System


Let’s get down to the tutorial, implement the circuit below taking note of the pin numbers while making your connections. Inventone has a 10bits ADC that accommodates a voltage input of 0-1V hence we need a voltage divider to convert the output voltage from the LDR (0-3.3V) to the required range of input voltage for the inventone board.



We would be using two pins on the inventone board, LDR pin and the Relay pin. The LDR pin would be used to read the voltage level from the LDR hence it is an input pin, while the Relay is an output pin since we would be using it to control the switching of the relay. Pin 0 is the only ADC pin on the inventone board.

In the void loop, note that we are using an analogRead( ) and not a digitalRead( ) this is because the LDR is an analog sensor that’s why we can only connect it to the ADC pin on the inventone board. Next we use an if statement to set the condition at which the relay gets turned on or off. All Serial.println( ) statements basically prints whatever is written within the parenthesis to the serial monitor.


/*This sketch is used to control a Bulb, the bulb comes on depending on the quantity of
the sun rays hiting the LDR-Light Dependent Resistor*/

int LDR = 0;
int Relay = 13;

void setup() {
     pinMode(LDR, INPUT);
     pinMode(Relay, OUTPUT);

void loop() {
     int value = analogRead(LDR);

     //When the light intensity is much, the LDR becomes a
     //shortcircuit and we get a HIGH on the LDR pin.

     if (value <= 512){
         digitalWrite(Relay, LOW);
         Serial.println("I'm alive");

     //Switch on the relay when we have low light intensity.

     else {
         digitalWrite(Relay, HIGH);