PROJECT Nº 4: Lamp with intermittent light

Use the components of the Maker Control Kit to learn how to build and program a lamp that, with the push of a button, blinks three times and then turns off.

For this project, you will use the button and the white LED. Press the button once so that the LED blinks three times.

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 of controlling the behavior of the LED with the button. At the push of a button, the LED will turn on and off three times at intervals of 0.25 seconds. Then, it will turn off entirely.

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; // LED connected to digital port 9
int PButton = 4, ValueButton; // Button connected to digital port 4 // Button reading variable

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

void loop() {
  // put your main code here, to run repeatedly:
  ValueButton = digitalRead(PButton); // Button reading
  if(ValueButton == HIGH) // If the button is pushed 
  {
   for(int x = 0; x<3; x++) // Repeat 3 times
   {
    digitalWrite (PLED, HIGH); // LED = ON
    delay(250); // wait 250 ms
    digitalWrite (PLED, LOW); // LED = OFF
    delay(250); // wait 250 ms
   }   
  }
  else // If the button is not pushed
  {
    digitalWrite(PLED,LOW); // LED = 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:

When the lamp button is pushed, the LED will blink 3 times at intervals of 0.25 seconds and then turn off.

0 0

0