Control two LEDs by the Micro:bit board

Micro:bit 27-05-23
295 0

Tutorial plan

  1. Role of LEDs in robotics

  2. The components needed to control two LEDs by Micro:bit

  3. Mounting the Micro:bit board with two LEDs

  4. Lighting two LEDs by the Micro:bit card

  5. Blink  two LEDs by the Micro:bit board

  6. Turn on two LED using the buttons on the Micro:bit board

Role of LEDs in robotics

LEDs (Light-Emitting Diodes) play several important roles in robotics. Here are a few key roles of LEDs in robotics:

  1. Indication and Status Display: LEDs are commonly used in robotics to indicate the status of different components or processes. For example, they can be used to indicate when a robot is powered on, when it is charging, or when it is in a specific mode of operation. LEDs provide a visual feedback mechanism for users or operators to understand the robot's current state.
  2. Navigation and Obstacle Detection: In robotic systems that operate in environments with low light or limited visibility, LEDs can be used for navigation and obstacle detection. For instance, robots may be equipped with infrared LEDs and sensors to detect objects or surfaces and navigate accordingly. These LEDs emit light that is not visible to the human eye but can be detected by the robot's sensors.
  3. Communication: LEDs can be employed for communication purposes in robotics. For instance, robots can use arrays of LEDs to display visual patterns or messages to interact with humans or other robots. By modulating the intensity or color of the LEDs, robots can convey information or instructions.
  4. Vision Systems: LEDs are often used in conjunction with cameras and vision systems in robotics. LEDs can provide controlled illumination in specific wavelengths or patterns to improve image quality and enhance object recognition capabilities. By using LEDs, robots can ensure consistent lighting conditions, reducing the impact of varying ambient light.
  5. Safety and Signaling: LEDs are also utilized for safety and signaling purposes in robotics. For example, robots working in hazardous environments or sharing spaces with humans can use LEDs to indicate their presence or potential dangers. These LEDs can emit bright, attention-grabbing lights or warning signals to alert humans to keep a safe distance or take appropriate actions.
  6. Aesthetics and Human-Robot Interaction: LEDs can be incorporated into robot designs for aesthetic purposes, making robots more visually appealing or providing a futuristic appearance. Additionally, LEDs can be used to enhance human-robot interaction by creating expressive robot faces or incorporating dynamic lighting effects that convey emotions or intentions.

The components needed to control two LEDs by Micro:bit

To control two LEDs using a Micro:bit, you will need the following components:

  1. Micro:bit board: The Micro:bit is a small programmable microcontroller board that serves as the brain of your project. It has built-in features like an LED matrix, buttons, and GPIO (General Purpose Input/Output) pins that can be used to control external components. Micro:bit board
  2. The GPIO expansion card for the Micro:bit card expands the capabilities of the Micro:bit board by adding more input/output (GPIO) pins and additional functionality. The GPIO expansion card for the Micro:bit card
  3. LEDs: You'll need two LEDs of your choice. LEDs come in different colors, so you can select the colors that suit your project. Red LED and green LEDs
  4. Resistors: LEDs require current-limiting resistors to prevent excessive current flow and protect them from damage. The value of the resistor depends on the forward voltage and forward current specifications of your LEDs. A commonly used resistor value for LEDs is around 220-330 ohms. two resistors
  5. Jumper wires: These wires are used to make connections between the Micro:bit and the LEDs. Jumper wires
  6. Breadboard is a common tool used in robotics and electronics to create circuit prototypes and temporary connections. It makes it easy to test and connect electronic components together without having to solder the connections. Test plate

Mounting the Micro:bit board with two LEDs

Once you have these components, you can follow these steps to control the LEDs with a Micro:bit:

  1. Connect the red LED:
    • Connect the longer leg (anode) of the LED to one end of the resistor.
    • Connect the other end of the resistor to P0 pin of the Micro:bit's GPIO pins (Pin 0).
    • Connect the shorter leg (cathode) of the LED to the Micro:bit's ground (GND) pin.
  2. Connect the green LED:
    • Repeat the same connections as for the red LED, but use a different GPIO pin (Pin 1) on the Micro:bit.

Mounting the Micro:bit board with two LEDs

Mounting the Micro:bit board with two LEDs

Lighting two LEDs by the Micro:bit card

To light two LEDs using a Micro:bit :

  1. Open the MakeCode editor (https://makecode.microbit.org/).
  2. In the editor, start with a "on start" block from the "Basic" category.
  3. Inside the "on start" block, add the following code:Makecode-lighting-two-LEDs
    This code will light the two LEDs
  4. Download the program to the Micro:bit:
    • Click on the "Download" button in the MakeCode editor to download the program as a .hex file.
    • Transfer the .hex file to the Micro:bit by copying it to the Micro:bit drive that appears when connected via USB.

Now, when you power up the Micro:bit, it will execute the program you created, and you should see the two LEDs light up.

Blink  two LEDs by the Micro:bit board

Ensure that each LED has its own resistor and is connected to a separate GPIO pin.

Once you have the connections set up, you can program the Micro:bit to blink the LEDs. Here's an example program using MakeCode:

  1. Open the MakeCode editor (https://makecode.microbit.org/).
  2. In the editor, start with a "forever" block from the "Basic" category.
  3. Inside the "forever" block, add the following code:Makecode-Blink-two-LEDs
  4. Download the program to the Micro:bit:
    • Click on the "Download" button in the MakeCode editor to download the program as a .hex file.
    • Transfer the .hex file to the Micro:bit by copying it to the Micro:bit drive that appears when connected via USB.

The program alternates between turning on the red LED and turning off the green LED, then turning off the red LED and turning on the green LED, creating an alternating flashing effect.

Between each LED state change, the program waits for one second using the “pause(ms)(1000)” function to create a one-second pause.

Turn on two LED using the buttons on the Micro:bit board

Once you have the connections set up, you can program the Micro:bit to control the LEDs using the buttons. Here's an example program using MakeCode:

  1. Open the MakeCode editor (https://makecode.microbit.org/).
  2. In the editor, start with an "on button A pressed" block from the "Input" category.
  3. Place a "digital write pin P0 to 1" block inside the "on button A pressed" block to turn on the red LED connected to Pin 0.
  4. Place "digital write pin P1 to 0" block inside the "on button A pressed" block to turn off the green LED connected to Pin 1.
  5. In the editor, insert the "on button B pressed" block from the "Input" category.
  6. Place "digital write pin P0 to 0" block inside the "on button B pressed" block to turn off the red LED connected to P0.
  7. Place "digital write pin P1 to 1" block inside the "on button B pressed" block to turn on the green LED connected to P1.Makecode-Turn on two LED using the buttons on the Microbit board
  8. Download the program to the Micro:bit:
    • Click on the "Download" button in the MakeCode editor to download the program as a .hex file.
    • Transfer the .hex file to the Micro:bit by copying it to the Micro:bit drive that appears when connected via USB

Now, when you press any of the buttons on the Micro:bit, it will execute the program you created, and both LEDs will turn on simultaneously. Release the buttons to turn the LEDs off again.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info