Small colorful electronic modules called littleBits allow a variety of gadgets and devices — like wearables, robots, interactive remote controllers, and physical games — to be created by makers, educators, and hobbyists.
littleBits has the capability to wirelessly interact with the Raspberry Pi Zero W thereby allowing IoT devices to be built. This tutorial will show you how to build a basic wireless controller. To get started, you will need a few off the shelf electronic components and a littleBits Bluetooth Low Energy (BLE) module to control a Pi Zero W.
- Raspberry Pi Zero WH
- General Purpose Silicon Diode (1N4001): D1
- Small electromechanical relay (5VDC/2A rated): K1
- General Purpose NPN Transistor (2N3904) or equivalent: Q1
- Tactile Pushbutton Switch: S1
- Resistor (100 ohm) [ Brown, Black, Brown, Gold stripes) +/- ¼ watt rated
- Solderless breadboard
- littleBits BLE
- littleBits power Bit
- littleBits proto-module
- littleBits mounting board
- Jumper wires
Transistor Relay Driver Circuit
To control the Pi Zero W, an electrical interface circuit is required. Traditionally, controlling a Pi Zero to generate text on the screen or to operate a LED a simple electric switch is used.
Although using an electric switch is an effective method to operate a Pi Zero, this electrical approach lacks the ability for wireless operation and control. Luckily, another method to operate the Pi Zero and allow wireless control is possible with a transistor relay driver circuit.
A transistor relay driver allows control of high current circuits using an external switching contact. Figure 1a illustrates a typical transistor relay driver circuit. As shown in Figure 1b, closing the electric switch will allow the transistor (Q1) to turn on.
With the transistor turned on, the electromechanical relay’s coil is electrically energized. This energized electromechanical relay closes its contacts using a magnetic field. The electromechanical relay’s contact provides a control signal to the appropriate GPIO of the Pi Zero W.
To show another perspective of a transistor relay driver circuit, a TinkerCAD model illustrates the operation of the electromechanical relay. Figure 2a demonstrates an open relay contact displayed by the ohmmeter’s infinite resistance reading.
Pressing the tactile switch energizes the electromechanical relay’s coil switching the contacts closed. The ohmmeter displays a continuity value of zero ohms.
With a good understanding of the operation of a transistor relay driver, the next step is wiring the transistor relay driver to the Pi Zero W.
Connecting the Pi Zero W to the littleBits module
The final construction of controlling a Pi Zero W with a littleBits module is the wiring of the transistor relay driver circuit to the small SBC. Figure 3 shows the block diagram of the wireless interface to operate a Pi Zero W. The tactile switch is used to test the transistor relay driver circuit prior to wirelessly controlling the Pi Zero W with a littleBits BLE bit and mobile device.
Use the electrical wiring diagram shown in Figure 4 to build the littleBits BLE controller. The placement of the electronic components should be as close to the wiring diagram as possible. To assist you in the wiring of the transistor relay driver circuit, an electrical pinout of the Pi Zero W is provided in Figure 5.
With the transistor relay driver circuit wired and tested on the solderless breadboard, you will build the code using EduBlocks. The basic code for testing littleBits BLE control interface is shown in Figure 6.
You can also code the software in the Python programming language as shown in Figure 7.
littleBits Gizmos and Gadgets App
To operate the BLE controller you will need the littleBits’ Gizmos and Gadgets app installed on an iOS or Android mobile device. The mobile device app allows a variety of controls such as a slider or button to operate the Pi Zero W. Also, the mobile device’s accelerometer by way of a shake motion can activate the Pi Zero W.
After you have installed the littleBits app on your mobile device, power the BLE controller interface with a 9V battery. Open Gizmos and Gadgets and pair the mobile device by selecting the wBLE icon. Select the button control and touch it with your finger. You should see the BLE message displayed on your HDMI monitor screen. Releasing the button will display the Waiting BLE message
You now have a wireless controller to explore the world of IoT. There is a multitude of awesome devices you can operate with your BLE controller. Happy IoT exploring!