PROJECT Nº 1: Turn the LED indicators on and off

Learn how to create a program to turn on and turn off the LED indicators by doing these three exercises.

EXERCISES INDEX:

  • Exercise 1.1: Turn an LED indicator on and off using the button
  • Exercise 1.2: Use the potentiometer to control how long is an LED on and off
  • Exercise 1.3: Use the potentiometer to control how long are 2 LEDs on and off

Exercise 1.1: Turn an LED indicator on and off using the button

Create a program so that, when pressing the button, the LED turns on and when the button is not pressed, the LED turns off.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 20 min.

MATERIALS:

  • 1 Button
  • 1 red LED
  • 1 USB – Micro USB cable
  • Computer

The Mini Lab will have to be built according to the instructions manual.

What is a button?

A button is a switch mechanism that when pressed it sends a signal.

What is an LED?

An LED is a light-emitting diode and it emits light when electricity passes through it. It has an Anode and a Cathode. “LED” comes from “Light Emitting Diode”.

CONNECTIONS:

  1. Connect the button to the digital port 4 of the Build&Code 4in1 board.
  2. Connect the LEDs to the digital port 3 of the Build&Code 4in1 board.

PROGRAMMING CODE:

You can do this project using the Arduino, Bitbloq and other visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code

  1. Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
  2. Open the Arduino program and copy the following program in it:
    int valuepuls = 0, pinpuls = 4; // BUTTON VARIABLE AND PIN
    int led3 = 3; // LED CONECTION PIN
    void setup() {
      //LEDS CONFIGURATION
    pinMode (led3, OUTPUT);
      //BUTTON CONFIGURATION
      pinMode (pinpuls, INPUT);
    }
    void loop() { 
      // WHEN PRESSING THE BUTTON THE LED3 WILL TURN ON
    valuepuls = digitalRead (pinpuls); 
      if (valuepuls == HIGH) // BUTTON NOT PRESSED
      {
        digitalWrite (led3, LOW); // LED3 = OFF
      }
      else
      {
        digitalWrite (led3, HIGH); // LED3 = ON
      }
    }
    
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. Open the software and copy the following code. Use the following image as a guide:
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Bitbloq code 

  1. Download Bitbloq and install the Web2board app.
  2. Open the software and copy the following code.
    • Hardware
    • Software
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE:

When pressing the button, the LED will turn on. When the button is not pressed, the LED will turn off.

 

Exercise 1.2: Use the potentiometer to control how long is an LED on and off

Learn to create a program to control how long is an LED on and off using the potentiometer. Turn the potentiometer to vary how long is the LED on and off.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 20 min.

MATERIALS:

  • 1 green LED
  • 1 Potentiometer
  • 1 USB – Micro USB cable
  • Computer

The Mini Lab will have to be built according to the instructions manual.

CONNECTIONS:

  1. Connect the potentiometer to the analog port A1 of the Build&Code 4in1 board.
  2. Connect the LEDs to the digital port 10 of the Build&Code 4in1 board.

PROGRAMMING CODE:

You can do this project using the Arduino, Bitbloq and other visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code

  1. Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
  2. Open the Arduino program and copy the following program in it:
    int led10 = 10, brightness; // PORT 10 AND LED BRIGHTNESS VARIABLE
    int pot = 0, pinpot = A1; // POTENTIOMETER PORT VARIABLES
    void setup() {
      // put your setup code here, to run once:
    // LED 10 CONFIGURATION
    pinMode (led10, OUTPUT);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      pot = analogRead (pinpot); // READING OF THE POTENTIOMETER VALUE
      digitalWrite (led10, HIGH); // LED 10 = ON
      delay ((pot));  // STAND BY TIME ACCORDING TO THE READING OF THE POTENTIOMETER
     digitalWrite (led10, LOW); // LED 10 = OFF
      delay ((pot));
    
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. Open the software and copy the following code. Use the following image as a guide:
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly

Bitbloq code

  1. Download Bitbloq and install the Web2board app.
  2. Open the software and copy the following code.
    • Hardware
    • Software
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE:

When moving the potentiometer, you will vary how long is the LED on and off, making it blink.

 

Exercise 1.3: Use the potentiometer to control how long are 2 LEDs on and off

Learn how to create a program to control how long are the LEDs on and off using the potentiometer so that when one LED is on, the other is off. 

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE:  20 min.

MATERIALS: 

  • 1 green LED
  • 1 red LED
  • 1 Potentiometer
  • 1 USB – Micro USB cable
  • Computer

The Mini Lab will have to be built according to the instructions manual.

What is a potentiometer?

A potentiometer is a resistance that variates according to its position. If you set its position at the extremes, you will get the minimum and maximum values of the input voltage. If the position is intermediate, you will get a voltage fraction proportional to the position in which the potentiometer is set. This behavior is called voltage divider.

CONNECTIONS:

  1. Connect the LEDs to the digital ports 10 and 3 of the Build&Code 4in1 board.
  2. Connect the potentiometer to the analog port A1 of the Build&Code 4in1 board.

PROGRAMMING CODE:

You can do this project using the Arduino, Bitbloq and other visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code

  1. Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
  2. Open the Arduino program and copy the following program in it:
    int led10 = 10, led3 = 3, brightness; // PORT 10 AND LED BRIGHTNESS VARIABLE
    int pot = 0, pinpot = A1; //POTENTIOMETER PORTS VARIABLES
    
    void setup() {
      // put your setup code here, to run once:
      // CONFIGURATION LED 10 AND LED 3 
      pinMode ( led10, OUTPUT);
      pinMode ( led3, OUTPUT);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      pot = analogRead (pinpot); // READING OF THE POTENTIOMETER VALUE
      digitalWrite (led10, HIGH); // LED 10 = ON
      digitalWrite (led3, LOW); // LED 3 = OFF
      delay ((pot));  // STAND BY TIME ACCORDING TO THE POTENTIOMETER READING
     digitalWrite (led10, LOW); // LED 10 = OFF
      digitalWrite (led3, HIGH); // LED 3 = ON
      delay ((pot));
    }
    

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. Open the software and copy the following code. Use the following image as a guide:
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Bitbloq code

  1. Download Bitbloq and install the Web2board app.
  2. Open the software and copy the following code.
    • Hardware
    • Software
  3. Configure and upload the code, following the indications on the Mini Lab First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE:

When moving the potentiometer, you will vary how long are the LEDs on and off, making a blink.

3 0

0