Learn how to build simple circuits on the cyber:bot robot’s breadboard, and then create block programs to interact with them. Add LEDs with resistors, and make the LEDs blink. Then add a pushbutton to control the LED, with and without programming.
These activities are written assuming you are completing the cyber:bot Prerequisite tutorials first, and then doing the Main tutorials in sequence. For this tutorial you will need:
When you are done with these activities, you will understand how to connect electrical components on a solderless breadboard. You will be prepared to build sensor circuits for your cyber:bot that will allow it to roam around on its own.
The cyber:bot board has a built-in Propeller microcontroller on its underside. The Propeller has 32 digital input/output pins, called I/O pins for short, that are designed to interact with circuits. These are referred to by number, P0 through P31.
Some of the I/O pins are connected to circuits built into the cyber:bot board, that your robot is already using. For example, P16 through P19 are connected to 3-pin headers, where the servo motors are plugged into P18 and P19. In this activity, we will use P20 and P21, which are connected to tiny built-in LED lights. Later on, we will build circuits on the breadboard, and connect them to the sockets alongside labeled P0–P15. Projects sent to the micro:bit module can instruct the Propeller to interact with these built-in circuits.
We’ll experiment with the “O” (output) feature of an I/O pin with a program to turn the built-in LED circuit on and off.
On the cyber:bot, it’s a small part just above the P20 label in the lower-right corner of your board.
By using the cyber:bot extensions write digital block instead of the already included digital write block, the command is then sent to the Propeller microcontroller instead of being processed by the micro:bit. From there, the Propeller uses its pre-programmed firmware to interact with circuits connected to its I/O pins.
The block (Pin20) write digital (High) sets Propeller I/O pin P20 to “output high” which means it connects to its 3.3 V supply, as shown on the left side of the image below. The pin applies 3.3 V of electrical pressure to the LED circuit, causing electric current to pass through it and the light to turn on. After that, pause (2000) makes the program do nothing for 2000 ms, which keeps the light on for 2 seconds.
Next, (Pin20) write digital (Low). This sets P20 to output-low, which connects the pin to its 0 V ground supply voltage instead, as shown on the right side of the figure below. This takes away the electrical pressure, so the current stops flowing through the circuit and the light turns off. Another pause (1000) makes the light stay off for one second.
Those four commands are in a forever block loop, which repeats endlessly, so the light keeps blinking.
You can change the light’s blink rate by changing the pause block’s ms argument. For example, to make the light blink a lot faster, significantly reduce the pause time.
Expand your project to control the P21 light along with the P20 light.
Building and controlling circuits with the cyber:bot board is a great way to learn about electricity, and to experiment with making your own inventions. Building experimental circuits to design your own projects is called prototyping, and it is a real-world engineering skill.
Before you start your cyber:bot prototyping, there are three important Reference pages you should have handy, especially if you have never built circuits on a breadboard before. Just click on each link and the page will open in a new tab or window.
The cyber:bot Board has a solderless breadboard mounted on it. The breadboard lets you connect common electronic components together to build your own circuits.
The cyber:bot’s breadboard is surrounded on three sides by black sockets. These make it convenient to connect circuits on the breadboard to power, ground, and the Propeller I/O pins. There are also sockets to connect to a digital-to-analog converter signal from the Propeller chip, and to an analog-to-digital converter on the micro:bit.
Before you build circuits on the breadboard, let’s review:
You have blinked the built-in LEDs on your board. Now it’s time to build your own LED circuits on your cyber:bot board’s prototyping area.
A diode is an electrical part that only lets electricity flow through it in one direction. A light-emitting diode (LED) emits light when current passes through it. You have to make sure to connect an LED the right way for it to light up. If you plug an LED in backwards it will not hurt it, but it will not emit light.
An LED has two terminals: the anode and the cathode. In the picture below, the anode lead is labeled with the plus-sign (+), and it is the wide part of the triangle in the schematic symbol. The cathode lead is labeled with a minus-sign (-), and it is the line across the point of the triangle in the schematic symbol.
You can tell the anode and cathode apart by the shape of the LED’s plastic case. Look closely — it’s mostly round, but there is a small flat area near the cathode lead. Also note that the LED’s leads are different lengths. Usually, the shorter lead is connected to the cathode.
Always check the LED’s plastic case. Sometimes the leads have been clipped to the same length, or a manufacturer does not follow this convention.
Let’s build two LED circuits on your breadboard. In addition to the two LEDs, you will need two resistors. Unlike the LEDs, the resistors do not have positive and negative leads, so you don’t have to worry about plugging them in backward. Resistors resist the flow of electrical current. Each one has a value that tells how strongly it resists current flow, measured in ohms, often noted by Greek letter omega: Ω. Take a look at that Resistor Color Codes page to see how its bands indicate its value.
Parts Needed
(2) red LEDs
(2) 220 ohm resistors (red-red-brown)
(misc) Jumper wires
This is the same test code that was used to blink the built-in P20 LED earlier in this tutorial, with the I/O pin number updated.
Enter and flash the project pin_8_blink.
Many items you use every day have pushbuttons. Cell phones, microwave ovens, TV remotes, and computer keyboards might all have pushbuttons. Can you think of others?
Let’s use a common pushbutton circuit and build a program for monitoring it with your microcontroller. Then, let’s use a pushbutton’s state to control LED circuits. LEDs are just one example of a device you can turn on and off with a microcontroller. Your invention might instead use pushbuttons to control circuits for motors, heating elements, or other devices.
The micro:bit module has two built-in pushbuttons. You can also add more pushbuttons to your cyber:bot on the breadboard. Doing so, you will learn how a pushbutton circuit works.
A pushbutton is a device that makes an electrical connection between two of its terminal leads when its button is pressed. When the button is released into its normally-open state, the electrical connection is broken and no current flows through the device. Here is the schematic symbol:
…and here is a drawing that resembles a breadboard-friendly pushbutton:
Notice that when the button is pushed, all 4 pins are connected. However, when the button is not pushed, legs 1 and 4 are still connected and legs 2 and 3 are still connected.
If the pushbutton is pressed, the circuit applies 3.3 V to the I/O pin through the pushbutton, and a small amount of current also passes through the 10 kΩ resistor to ground. When the pushbutton is not pressed, the connection to the 3.3 V supply is broken, and so the circuit applies GND (0 V) to the I/O pin.
This circuit uses your board’s built-in P20 and P21 LEDs, along with two pushbutton circuits you will build onto your breadboard. Use 220 ohm resistors to connect the pushbutton circuits to the cyber:bot I/O pins and use 10 k-ohm resistors to connect the circuits to ground.
Parts
(2) pushbuttons
(2) 220 ohm resistors (red-red-brown)
(2) 10 k-ohm resistors (brown-black-orange)
This test project will display the state of the button connected to P3 on the micro:bit module’s display. The display will show a 1 if the button is pressed, or 0 if it is not pressed.
This Block code is all inside of a continuous forever loop. Inside the loop there is one if statement that checks two conditions.
The first condition that it checks is whether the (Pin3) read digital block is equal to 0. If this is true the micro:bit module will display a 0. The read digital block checks the input state of the pin, in this case P3. Thus, if the button is not being pressed, the input state at pin 3 is 0.
The second part of the if statement checks to see if the input state is 1 (button pushed), if so the micro:bit module will display a 1.
Active-high: The pushbutton circuit you are using is called active-high because the pushbutton sends the cyber:bot I/O pin a 3.3 V high signal when pressed (active) or a 0 V low signal when released.
Pull-down: The 10 k-ohm resistor in the schematic is called a pull-down resistor. It’s there so that the I/O pin will detect 3.3 V through the resistor when the button is pressed. If you leave it out, the I/O pin behaves more like an antenna, and nearby electric fields will end up controlling whether 1 or 0 is detected.
Active-low, pull-up: Pushbutton circuits can also be active-low. All you have to do is swap the pushbutton and 10 k-ohm resistor in the schematic. The pull-down resistor then becomes a pull-up resistor, and the I/O pin will detect 0 V when the button is pressed.
Now it is time to control an LED with a pushbutton.
Can you make the LED connected to P21 light when the button connected to P4 is pressed?