PROJECT Nº 3: Lamp with variable light intensity

Use the components of the Maker Control Kit to learn to build and program a lamp whose light intensity increases to the maximum at the push of a button and then gradually decreases until it turns off. 

For this project, you will use the button and the white LED. When the button is pushed, the intensity of the LED light will gradually increase to the maximum and then decrease until it turns off.

LEVEL OF DIFFICULTY:  Beginner.

DURATION OF THE EXERCISE: 30 min.

MATERIALS:

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

What is an LED?

An LED is a semiconductor electrical component (diode). When a small current passes through it, the diode emits light.

What is a button?

A button or switch is an electric operator that, when pushed, allows electrical current to flow, and when it is no longer pressed, it interrupts it.

CONNECTIONS:

  1. Connect the white LED to digital port 9 on the 4in1 Build&Code control board.
  2. Connect the button to digital port 4 on the 4in1 Build&Code control board.

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

BUILDING THE STRUCTURE:

To build the lamp structure, you will use 150 mm x 18 mm wooden sticks, a clear or white plastic cup, and hot silicone to make all the structure’s joints. Download the quick setup guide and follow the steps shown.

PROGRAMMING CODE:

The program consists in controlling the behavior of the LED and the button. When the button is pushed once, the LED will turn on and gradually increase in intensity until it reaches the maximum. Then, the LED light will decrease in intensity, also gradually, until it turns off.

To control the brightness of the LED, you will have to connect it to one of the digital ports with PWM output, marked with this symbol: ~

Then, the PWM digital port will be working like an output port, but instead of constantly emitting a low or high value, it will be able to make very fast changes to play with mid-range values. This will allow the LED to emit various levels of brightness.

The PWM has a resolution of 256 states that go from 0 to 255. If you write the value 15, the LED will barely turn on, since it will be off for more time than it will be on. If you write the value 127, you will see the LED shine at 50% of its maximum potential, since it will be on 50% of the time and off the other 50%. If you write the value 250, you will see that it will shine as if at 100%.

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.
nt PLED = 9; // Digital port 9 where the LED is connected
int PButton = 4, ValueButton; // Digital port 4 where the button is connected // Variable to know the status of the button

void setup() {
  // put your setup code here, to run once:
  pinMode (PLED, OUTPUT); // Configure the LED signal as output
  pinMode (PButton, INPUT); // Configure the Button signal as input
}

void loop() {
  // put your main code here, to run repeatedly:
  ValueButton = digitalRead(PButton); // Read the value of the button and save it in the variable
  if(ValueButton == HIGH) // If the button is pushed
  {
    for(int x=0; x<256; x=x+10) // Increase the brightness value of the LED { analogWrite (PLED, x); // Turn on the LED in terms of brightness delay(50); // 50 ms wait } for(int x=255; x>0; x=x-10) // Decrease the brightness value of the LED
    {
      analogWrite (PLED, x); // Turn on the LED in terms of brightness
      delay(50); // 50 ms wait
    }
  }
  else // If the button is not pushed
  {
    digitalWrite(PLED,LOW); // LED = OFF off
  }
}

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 First Steps for the 4in1 Build&Code board document.

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 indicated in the First Steps for the 4in1 Build&Code board document.

RESULT OF THE EXERCISE:

You have built a lamp that turns the LED on and off at the push of a button, gradually changing its brightness.

0 0

0