PROJECT Nº 3: Solar lamp

Learn to build and program a lamp that turns on and off depending on the surrounding light, using the components of the Maker Control Kit and Maker Kit 1.

With the light sensor, you can measure the light where the lamp will be, when there is a maximum and minimum amount of light. Use the values obtained to determine when the light should turn on and when it should turn off. Have fun with your solar lamp!

INDEX OF EXERCISES:

  • Exercise 1.1: Measure the surrounding light
  • Exercise 2.2: Create the solar lamp

Exercise 1.1: Measure the surrounding light

Use the light sensor to measure the amount of light in the room where the lamp will be located. The light sensor will give a value between 0 and 1023.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 20 min.

MATERIALS:

  • 1 Light sensor
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer

What is a light sensor?

An analog light sensor is a resistor that varies its electrical resistance depending on the amount of light that hits it. It is also called a photoresistor or photoresistance.

CONNECTIONS:

Connect the light sensor to the analog port A0 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color:

PROGRAMMING CODE:

The program allows you to see the amount of ambient light that the sensor picks up on the computer. It will be a value between 0 and 1023.

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in it, copy the following program:
    int pinlight = A0, luz; // Light sensor connected to analog port A0; light = Dependent on ambient light reading.
    
    
    void setup() {
      // Put your setup code here, to run once:
      Serial.begin (9600);
      
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      //READ THE LIGHT INTENSITY FROM THE LIGHT SENSOR AND TURN THE LED10 ON OR OFF ACCORDING TO AN AVERAGE VALUE
      luz = analogRead( pinlight); // LIGHT INTENSITY READING FROM THE LIGHT SENSOR
      Serial.println (luz); // Show the value from the light sensor onscreen
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following these instructions:
    3.1. Select the type of board that you are going to use. If using the 4in1 Build&Code board, it is Boards → Arduino Uno.3.2. Select the port to which the 4in1 Build&Code board is connected.

    Connect → Serial port → COM (the number where the board is) connected).

    3.3. Insert the communication program between the program and the 4in1 Build&Code board. Connect → Upgrade firmware.

  4. Then click the green flag to start the program.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

With the light sensor placed where the lamp will be and connected to the 4in1 Build&Code board, measure the maximum light possible that the room will have and record the value. Measure the light again when the ambient light is suitable to turn on the lamp and record the value.

RESULT OF THE EXERCISE:

As a result of the exercise, you have obtained the light values for when it is necessary for the light to turn on and off.

 

Exercise 1.2: Create the solar lamp

After exercise 1.1, build and program the lamp. Add the white LED so that the lamp turns on and shines when there is not enough light in the area.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 60 min.

MATERIALS

  • 1 Light sensor
  • 1 White LED
  • 1 Clear or white plastic cup
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • Material to make the lamp structure
  • Adhesive

CONNECTIONS:

Use the connection that you have made to do exercise 1.1.

BUILDING THE STRUCTURE:

To build the lamp structure, you will use 150 mm x 18 mm wooden sticks and a plastic cup that is either white or transparent. Download the quick assembly guide and follow the steps shown.

PROGRAMMING CODE:

In exercise 1.1, you have obtained the maximum and minimum values of light in the room that you considered necessary for the lamp to turn on.

The program operates in the following way: When the light sensor has a reading less than the minimum value, the white LED will turn on to light up the room.

When the light sensor has a reading greater than the minimum, the white LED will turn off, since there will be enough light in the room.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    int pinlight = A0, luz; // Light sensor connected to analog port A0; light = Dependent on ambient light reading.
    int led10 = 10; // White LED connected to digital port 10
    
    void setup() {
      // Put your setup code here, to run once:
      pinMode ( led10, OUTPUT); // Configuration of the LED
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      //READ THE LIGHT INTENSITY FROM THE LIGHT SENSOR AND TURN THE LED10 ON OR OFF ACCORDING TO AN AVERAGE VALUE
      luz = analogRead( pinlight); // LIGHT INTENSITY READING FROM THE LIGHT SENSOR
      if (luz > 400) // IF THE VALUE IS GREATER THAN 400
      {
        digitalWrite ( led10, LOW); // LED10 = OFF
      }
      else // IF IT IS LESS THAN 400
      {
        digitalWrite ( led10, HIGH); // LED10 = ON
      }
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software 

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

Depending on the ambient light in the room, the lamp turns on and off automatically. You have made your solar lamp!

1 0

0