xPlora: Light Switch

Introduction
When the night falls, we need lights to help us see in the dark. Lights make it possible to see things at night, just like the sun during the day. When evening comes and its starts to get dark, we usually flip or press a switch to fill light in the room and continue with our important work.
A switch is the way we communicate with the lights, to tell them when to go on and when to go off. They are a staple not just in our homes but in buildings all around the world.
A light switch is a simple device that is used to control home lighting system. It is usaully fixed in a wall and can either be pressed or flipped to turn on or turn off electric light.
Things to learn
In this lesson, you will learn about:
- How a switch works
- How to connect a pushbutton switch
- How to build a simple light switch
How a switch works
Switches are simple devices that control the flow of electricity in a circuit. They act like a gate that can be opened or closed. When a switch is closed it allows electricity to flow through to turn on the bulb and when it is opened it stops the flow and turns off the bulb.

t: 00:20
A switch is made up of a metal contact that is conductive, allows electricity to pass through such as copper or iron and the outer housing is made up of an insulating material, does not allow electricity to pass through such as plastic or wood to make it safe from harm e.g electric shock.
image
There are different types of switches such as a push button that pressed or released, a toggle switch that is flipped up or down and many more.
image
Push buttons
A push button light switch allows the flow of electricity with just a push. When you press a push button switch, pressure is applied allowing contacts at the bottom of the switch to come together so that electricity can flow through them.
Push buttons are easy to use, come in many colours and can be used in different applications.
image
In this project we will use a push button switch
How to connect a pushbutton switch
About push button
A push button switch closes when the button is pressed and opens when it is released.
It has four pins but only two of the four pins can be used at a time.
Image: two images - side view with showing three pins and a top view
How it works
Push button has four pins but only two pins can be used at a time. This is because they are connected internally in two sets and only two pins are needed for wiring.
Image: showing internal connection
Why is it that only two pins of a button are used at a time when it has four?
- To place the button firmly on the breadboard.
- Use both sides of the breadboard to keep the layout tidy.
A push button is a two pin device, but has four pins for easier usage and convenience
How do you know which pins are paired up?
A push button switch can only fit across the breadboard centre divider in only one direction.
Image: showing the difference
Once you have placed the push button correctly, the pins are horizontally paired - pins on the top side of the divider are paired and pins on the bottom side of the divider are paired.
image: how they are paired
Pressed and released states
Image: Push Button pin out
Pressed and released and Animated
Pull down resistors
Build the project
In this section, we will build the light switch circuit on our Unda.Xplora Breadboard.
Components
To build the light switch project, pick out the following components from your components casing
Component | Description |
---|---|
1 x LED | ![]() |
1 x resistor (220 ohms) | ![]() |
1 x resistor (1Okilo-ohm) | ![]() |
1 x pushbutton | ![]() |
4 x jumper wire | ![]() |
1 x battery connector | ![]() |
1 x battery | ![]() |
1 x Unda Xplora | ![]() |
Step 1
Connecting the LED on the breadboard
- Step
- Build
- Placing the LED: Take the white LED from your Unda Xplora Kit. Identify the positive and negative pin of the LED; the positive pin has a longer leg than the negative pin. Place the LED on the breadboard with the negative leg of the LED placed on the negative bottom breadboard rail and the positive leg placed on the breadboard at pin b23 .
- Placing the resistor: Take one 220 ohm resistor from the kit and connect it from the positive leg of the LED from pin d23 to pin f23 of the breadboard.
- Connecting a jumper wire: Take a jumper wire and plug one of it's leg into digital pin D4 and insert the other leg into pin i23 next to the resistor.
Step 2
Connecting the pushbutton on the breadboard
- Step
- Build
- Placing the pushbutton: Pick one pushbutton from your Unda Xplora components kit. There are five different colored pushbuttons available; choose the one that you prefer. For this project we will use the Black pushbutton .
- Take note of the pinouts: You should observe that the pushbutton has four pins, two on each side. The two pins on either side are internally connected which means that use just two pins of the four pins that are not internally connected can be used.
- Connecting the Pushbutton: Connect the two top pins of the pushbutton at pins g6 and g8 of the breadboard and then connect the other two pins of the pushbutton at pins d6 and d8 of the breadboard.
Step 3
Connecting a resistor next to the pushbutton
- Step
- Build
- Placing the resistor: Pick one 10 Kilo Ohm resistor from your Unda Xplora components kit. Place one leg of the resistor next to one bottom pin of the pushbutton at pin c8 of the breadboard and place the other leg at the negative terminal of the bottom negative breadboard rail.
Step 4
Connecting a jumper wires to the pushbutton
- Step
- Build
- Connecting to 5V: Using a jumper wire (pick any color of your choice), connect from any 5V pin of the kit to one pin of the pushbutton at pin i6 of the breadboard. Ensure the jumper wire is connected to the correct pin as shown above. You can connect from any of the three 5V pins of the Unda Xplora Kit as long as the other side of the jumper wire is connected to pin i6 of the breadboard.
- Connecting to digital pin: Using a jumper wire, connect from digital pin D10 to one pin of the pushbutton at pin i8 of the breadboard.
Step 5
Connecting to Ground
- Step
- Build
- Connecting to GND: Using a jumper wire (pick any color of your choice), connect from GND pin of the Kit to the bottom breadboard negative rail . There are four GND pins on the kit and you can always connect from any one of them as long as the other pin of the GND is placed at the bottom breadboard negative rail.
Run the Project
Connect the battery to the battery connector and then plug it to the power port of your UNDA.Xplora to power it on.
Follow the steps below to load up the Light Switch Project.
Open Project
From the main window open the projects

Observation
When we run our project, we observe that the LED is off and stays off until we press the button which then turns our LED on. When we press the button again, the LED goes back off.
Why is this so?
Just like the light switches in our homes that turn the lights on and off, the button turns on and off the LED. When we first connect and run the projects, the LED is in the off state. Although it is connected and able to light up, our mini-computer tells the LED to stay off by sending a signal 0. Pressing the button sends a signal to our mini-computer to send the signal 1 to the LED hence it turns on.
Pressing the button again tells our mini-computer to send the next signal 0 which turns off the LED. Each time we press the button it sends a signal depending on whether the LED was on and off hence making the light switch.