micro:bit magic wand (intermediate)

 

“Any sufficiently advanced technology is indistinguishable from magic.” (Arthur C. Clarke). Heck yes it is! What are we waiting for, let’s use technology to create our own kind of magic!!

This project uses two micro:bit microcontrollers, a household cooling fan, and a few small electronic parts to create our very own magical wand. I chose to use the Wingardium Leviosa gesture, but you can most certainly adapt this project to cast other spells!

Please note that this is an intermediate project because it involves high voltage and current. Use proper safety protocols and always have another adult nearby.

Difficulty: Intermediate

Read Time: 15 min

Build Time: ~ 1 hr

Cost: ~ $40

Materials

  • Wand!
    • You can purchase custom wands or get creative and make your own!
  • Feather (for floating!)
  • Glove (for hiding the micro:bit wand controller)
  • One (1) household cooling fan (4A or less)
    • We do not modify the cooling fan so grab one you have around the house or borrow one from a favorite human.
  • One (1) extension cord
    • We WILL modify the extension cord, so use an extra one you don’t need or buy a cheap one.
  • Two (2) micro:bits
  • Two (2) micro:bit battery packs and two (2) AAA batteries
    • If you get the micro:bit Go bundle, it comes with a battery pack and batteries 🙂
  • Two (2) microUSB cables
  • One (1) PCB
    • Mine is 2cm x 8cm, any similar or larger PCB will work (but definitely do NOT use a breadboard as it cannot handle the high current)
  • One (1) solid state relay (JZC-11F)
    • Rated for 5Vdc input and 220/250 Vac and 5A output. You can use a different relay as long as it can switch

Magic? What! How??

One of my favorite scenes from the first Harry Potter book was when Hermoine makes a feather float with the spell Wingardium Leviosa. This simple spell captures the essence of why we love magic: that literally at the flick of our wrist and a few choice words, we can instantly make surprising (and impressive) things happen.

Although we don’t have exactly that kind of magic, we do have technology that sometimes seems miraculous. So that sort of counts! To mimic my fav scene, I wanted to levitate a feather. How can we move feathers from afar in real life? With wind!!

After building a beginner version of this project, I wasn’t 100% satisfied. I wanted to reach Hermione-level wizard status! So I designed a second version that can switch power for a large household fan.

This version uses a solid state relay to switch AC power with a DC trigger. You can imitate my design or, better yet, create your own! There are TONS of variations for this project that you can make with this basic framework, find a spell that inspires you and bring it to life!

This tutorial will show you how to do the following:

1. Write a simple block-based code for a micro:bit wand controller

2. Build a circuit to switch power for a 12V, 4A hosuehold fan.

3. Write a simple block-based code for a magical receiver that is triggered with a radio signal (aka bluetooth)

Code it: Wand Controller!

Let’s start with our magic wand!
We are using block-based coding via the Make Code website, but if you have experience w/ coding you can also program the micro:bit using micropython or C++ in your fav coding environment (e.g. Idle, Visual Studio Code, etc.).

Step 1: In the On Start block, set the Radio Group number. We’ll use the same number for the magical receiver micro:bit.

Step 2: Decide how you want your wand to trigger action.

The micro:bit has a 3-axis accelerometer, we will use this to set a gesture trigger.

Quick solution: Use the “on shake” block!

 

More complex, gesture-based solution:

Explore how the accelerometer works by printing to the Serial port with the “Serial write value” blocks (under the Advanced section). Open the Arduino IDE Serial Monitor to observe the micro:bit output as you make gestures. Use your observations to set triggers. (Code No. 2)

The example in Code No. 2 is my attempt at a Wingardium Leviosa gesture: swish-and-flick! (down in the z-direction and left in the x-direction). Use as-is or as a starting point for your own fav magical gesture!

Helpful Tips:

(1) Since microcontrollers process information super quickly, the pause block gives us time to finish the first part of the gesture before the micro:bit checks for the second part. 

(2) I added axes labels on the micro:bit so I could more easily figure out how to get the right motion for Wingardium Leviosa spell — definitely recommend this!

Step 3: Use the gesture to send a radio number (or string, just be consistent).

The “radio send string” and “radio send number” blocks are found in the “radio” block set.

Step 4: Download and save the code onto the micro:bit!

Build it: Magical Receiver!

Grab your second micro:bit, your PCB, your soldering iron, and all of the electronic parts!

Quick overview: We are using the micro:bit 3.3V power out to trigger the DC side of the relay. The circuit is completed when the micro:bit P0 pin switches on the NPN transistor.

Step 1: Solder the relay and transistor to your PCB board.

Step 2: Solder the diode across the relay DC power pins to protect the micro:bit from stray voltage when the relay coils switch. The negative side of the diode (grey line) should connect to the relay DC positive power in pin.

Step 3: Solder one jumper wire to the relay DC positive power in pin. Connect an alligator clip between this wire and the micro:bit 3.3V output pad.

Step 4: Solder another jumper wire between relay DC power out (GND) pin and the transistor collector pin.

Step 5: Solder the third jumper wire to the transistor emitter pin. Connect an alligator clip between this wire and the micro:bit GND pad.

Step 6: Solder your resistor to the transistor base pin. Connect an alligator clip between the other end of the resistor and the micro:bit P0 pad.

Step 7: Remove 1/2″ (2 cm) of insulation from the 14 gauge wire on both sides. Solder one wire to the relay NO (normally open) pin and the other wire to the relay COM (or coil 2) pin.

Step 8: Cut the extension cord on one side only, and remove ~ 1/2″ (2cm) of insulation from side of the cut wire.

Step 9: Grab the 14 gauge wire and slide a piece of heat shrink tube onto each wire.

Step 10: Line up one end of the 14 gauge wire with one end of the extension cord wire, then twist the metal together. Secure the heat shrink tube with your fav. heat source (e.g. lighter, hair dryer, etc.). Repeat for the other wires and heat shrink tube.

Note: Orientation of the AC wires does not matter.

Code it: Magical Receiver!

Time to code our magical receiver!

Step 1: Set Radio Group to the same number as for the Wand Controller.

Step 2: Pull out a “on radio received” block and set it to “receivedNumber” (or “receivedString” if you used that for your Wand Controller).

Step 3: Drag a repeat block into the “on radio received” block and switch it to repeat 2 – 4 times.

Step 4: (Optional but recommended) Show an icon on the micro:bit to let you know if it received the string.

This is super duper helpful if/when you are debugging.

Step 5: Turn on Digital Pin 0! (aka “digital write pin P0” to 1)

This block is found under the “Pins” block under the Advanced tab.

Step 6: Pause for a few seconds.

I chose 2 seconds, you can keep this or adjust as desired.

Step 7: Turn off Digital Pin 0 (“digital write pin P0” to 0) and the micro:bit display.

Step 8: (Optional but recommended) Add a back-up trigger using micro:bit button A for testing and debugging purposes 🙂

Voila! Download the code onto your Magical Receiver micro:bit and we’re ready for the magical prop!

Test & Debug!

And now, for our favorite part: testing!!

Power up your micro:bits (via battery or microUSB), plug in the extension cord and plug the fan into the extension cord, then move your wand controller to check that the magical receiver turns on the fan.

When you are done testing, coat the magical receiver connections in hot glue to hold them in place. If you want an ultra-permanent solution, use epoxy (waterproof is a nice bonus feature). Recommended to avoid covering the micro:bit in glue so you can use it for future projects.

Not working as expected?

1. Power is the most common issue for makers of all experience levels. Double check that all the things are plugged in. Use the micro:bit controller quick trigger to test that the receiver shows the “got message” icon.

2. Fan not moving? When the relay switches, you will hear an audible click. Use the micro:bit controller quick trigger and listen for the sound.

I did notice that the micro:bit 2xAAA battery pack was insufficient power to trigger the relay. I ended up just using the microUSB cable but a 3xAAA battery pack should also do the trick.

3. Use a multimeter to check continuity of your solder joints and, if necessary, voltage across the relay DC coils.

Build your magical prop!

Now that you’ve tested and practiced your magical tech abilities, you’re ready to build your magical prop! Use gloves to hide the micro:bit wand controller + battery pack.

For the magical receiver: Where do you want to put the feather and how can you hide the fan?

For my demo, I just hid the fan off camera (shhhhh don’t tell!!), but if you are doing your magical performance in-person you can build an enclosure to hide the fan. I found that window screen mesh worked great to help hide the parts while still letting air flow through.

Want to do other kinds of magic? You can build different types of props! This same setup will work to turn on any low-power AC device like speakers or a screen! Just be sure that the maximum current draw is less than 5A.

Go forth and be magical!

Heck yes, wizard level: intermediate!! Practice your gesture so you can really impress all the people. And of course, teach others how to do this technological magic!

Leave a comment if you need some help, have any questions, or to show off your creations!

Happy making, friends!

Using Arduino for Citizen Science!

Science allows us to ask our most pressing questions and explore all sorts of curiosities. With some thought, hard work, and patience, we can use our explorations to build a better understanding and appreciation of the complex and beautiful world around us.

This tutorial will teach you how to use an Arduino (uno) microcontroller, how to use different types of sensors, and how to gather and visualize data. Along the way, we’ll build three projects: a tilt switch, a temperature and humidity sensor, and a light sensor!

Difficulty Level: Beginner

Read Time: 20 min

Build Time: Depends on your project! (Projects in this tutorial take about 15 – 20 min)

Pssst, What’s the Difference Between Citizen Science and “official Science”?

The biggest difference is that citizen science is, as I love to say, “hand wavy”, which means that there are lots of errors and uncertainties and no rigorous process to identify them. Because of this, conclusions reached through citizen science are much less accurate than science-science and should not be relied upon to make serious/life-altering/life-threatening claims or decisions.*

That being said, citizen science is a great way to build a fundamental understanding of all sorts of fascinating scientific phenomenon and is good enough for most day-to-day applications.

*If you are doing citizen science and you discover something potentially dangerous (e.g. high lead levels in water), inform your educator (if applicable) and contact the relevant authorities and professionals for assistance.

What Is Arduino??

Arduino is a microcontroller board and Integrated Development Environment (“IDE”), which is a fancy way of saying “coding program”. For beginners, I highly recommend Arduino Uno boards because they are super robust, reliable, and powerful.

Arduino boards are a good choice for citizen science projects because they have lots of input pins to read in both Analog and Digital sensors (we’ll get more into this later).

Of course, you can use other microcontrollers for citizen science depending on your (or your students’) needs, abilities, and comfort level. Here is an overview of microcontrollers to help ya decide what is best for you!

To flash, or program, an Arduino board, plug it in via USB, then:

1. Select the type of Arduino you’re using under Tools -> Boards.

 

2. Select the port (aka where it’s connected to your computer).

 

3. Click the Upload button and check that it finishes uploading.

Tools & Materials

If you’re just getting started, getting a kit is a quick & easy way to get a bunch of parts at once. The kit I’m using in this tutorial is the Elegoo Arduino Starter Kit.*

Tools

  • Arduino Uno
  • USB A to B cable (aka printer cable)
  • Jumper Wires
    • 3 male-to-male
    • 3 male-to-female
  • Breadboard
    • Optional but recommended to make your life easier and more fun 🙂

Materials

For the projects covered in this tutorial, you’ll need these parts from the Elegoo Arduino Starter Kit:

  • Tilt Switch
  • DTH11 Temperature and Humidity Sensor
  • LED
  • 100 Ohm Resistor

*Full disclosure: I purchase these same kits for workshops, but the kit used in this tutorial was donated by the lovely folks at Elegoo.

What Kinds of Sensors Can We Use?

When designing a science experiment, we typically start with a question: How much CO2 do plants absorb in a day? What is the impact force of a jump? What is consciousness??

Based on our question, we can then identify what we want to measure and do some research to figure out what sensor we can use to gather data (although it miiight be a bit tricky to gather data for that last question!).

When working with electronics, there are two main types of sensor data signals: Digital and Analog. In the photo, the first two rows of parts are all digital sensors, while the top two rows are analog.

There are many different types of digital sensors, and some are more challenging to work with than others. When doing research for your citizen science project, always check how the sensor puts out data (srsly tho) and make sure you can find an (Arduino) library for that specific sensor.

In the three projects covered in this tutorial we’ll use two types of digital sensors and one analog sensor. Let’s get a-learnin!

Digital Sensors!

Part 1: the Easy Ones

Most sensors you’ll use output a Digital Signal, which is a signal that is either on or off.* We use binary numbers to represent these two states: an On signal is given by a 1, or True, while Off is 0, or False. If we were to draw a picture of what a binary signal looks like, it would be a square wave like the one in the photo below!

There are some digital sensors, like switches, that are super easy and straightforward to measure because either the button is pushed and we get a signal (1), or it is not pushed and we have no signal (0). The sensors pictured in the bottom row of the first photo are all simple on/off types. The sensors on the top row are a bit more complex and are covered after our first project.

The first two projects in this tutorial will teach you how to use both types! Onward to build our first project!!

*On means an electrical signal in the form of electric current and voltage. Off means no electrical signal!

Project 1: Tilt Switch Digital Sensor

For this first project, let’s use a tilt switch, that black cylindrical sensor with two legs!
Step 1: Insert one leg of the tilt switch into Arduino Digital Pin 13, and the other leg into the GND pin right next to pin 13. Orientation doesn’t matter.

Step 2: Write a sketch that reads in and prints out the status of Digital Pin 13.

Or you can just use mine!

If you’re just getting started in coding, read through the comments to better understand how the sketch works and try changing some things to see what happens! It’s OK to break things, that’s a great way to learn! You can always re-download the file and start over 🙂

Step 3: To see your live data, click on the Serial Monitor button.

.. aaaand that’s it! You can now use the tilt switch to measure orientation! Set it up to call out your kitty when it knocks something over, or use it to keep track of how tree branches move during storms! .. & there are probably other applications in between those two extremes.

Digital Sensors!

Part 2: PWM and Serial Communication

There are many ways to create more complex digital signals! One method is called Pulse Width Modulation (“PWM”), which is a fancy way of saying a signal that is on for a certain amount of time and off for a certain amount of time. Servo motors (which can be used to measure position) and ultrasonic sensors are examples of sensors that use PWM signals.

There are also sensors that use serial communication to send data one bit, or binary digit, at a time. These sensors require some familiarity with reading datasheets and can be pretty tricky if you’re just getting started. Fortunately, common serial sensors will have code libraries* and sample programs to pull from so you can still cobble together something functional. More details on serial communication protocols is beyond the scope of this tutorial, but here is a great resource on serial communication from SparkFun to learn more!

For this sample project, let’s use the temperature and humidity sensor (DHT11)! This is a lil’ blue square with holes and 3 pins.

First we’ll need a couple of special libraries for the DHT11 sensor: the DHT11 library and the Adafruit Unified Sensor library.
To install these libraries (and most other Arduino libraries):

Step 1: Open up the Arduino library manager by going to Sketch -> Libraries -> manage Library

Step 2: Install and activate the DHT library by searching for “DHT” and then clicking Install for the “DHT Arduino Library” .

Step 3: Install and activate the Adafruit Unified Sensor library by searching for “Adafruit Unified Sensor” and clicking install.

Step 4: Insert the DHT library into your open sketch by going to Sketch -> Libraries, and clicking on the “DHT Arduino Library.  This will insert a couple of new lines at the top of your sketch, which means our library is now active and ready to use!

*Just like your fav local library, code libraries are a wealth of knowledge and other folks’ hard work that we can use to make our lives easier, yay!

Project 2: Temp and Humidity Digital Serial Sensor

 

Grab 3 male-to-female jumper wires from the Elegoo Arduino Starter Kit and we’re ready to go!

Step 1: With the header pins facing you, connect the rightmost header pin on the DHT11 to an Arduino ground (“GND”) pin.

 

Step 2: Connect the middle header pin to Arduino 5V output pin.

 

Step 3: Connect the leftmost header pin to Arduino Digital Pin 2.

Step 4: Finally, read the DHT library and try your hand at writing a sketch! Oooor you can use mine or the DHT test example sketch within Arduino -> Examples!

When you’ve got it up and running, go forth and measure the temperature and humidity of all the things! .. Like an animal’s breath, a greenhouse, or your favorite climbing spot at different times of the year to find the *perfect* sending temp.

Analog Sensors!

After the difficult dive into digital sensors, analog sensors can seem like a breeze! Analog signals are a continuous signal, like the photo below.

Most of the physical world exists in analog (e.g. temperature, age, pressure, etc.), but since computers are digital*, most sensors will output a digital signal. Some microcontrollers, like Arduino boards, can also read in analog signals**.

For most analog sensors, we give the sensor power, then read in the analog signal using the Analog Input pins. For this test, we’ll use an even simpler setup to measure the voltage across an LED when we shine a light on it.

*Computers use digital signals to store and transmit info. This is because digital signals are easier to detect and are more reliable, since all we’ve got to worry about is getting a signal or not versus having to worry about the quality/accuracy of the signal.

** To read in an analog signal on a digital device, we must use an Analog-to-Digital, or ADC, converter, which approximates the analog signal by comparing the input to a known voltage on the device, then counting how long it takes to reach the input voltage. For more info, this is a helpful site.

Project 3: LED As a Light Sensor!

Grab an LED (any color except white), a 100 Ohm resistor, and 2 jumper cables. Oh, and a breadboard!

Step 1: Insert the LED into the breadboard with the longer leg on the right side.

Step 2: Connect a jumper wire from Arduino Analog Pin A0 and the longer LED leg.

Step 3: Connect the resistor between the shorter LED leg and the breadboard negative power rail (next to the blue line).

Step 4: Connect the Arduino GND pin to the negative power rail on the breadboard.

Step 5: Write a sketch that reads in Analog Pin A0 and prints to the Serial Monitor!

Here is a sample code to get ya started.

Visualizing Data: Arduino IDE!

The Arduino IDE comes with built-in tools to visualize data. We’ve already explored the basics of the Serial Monitor which allows us to print sensor values. If you want to save and analyze your data, copy the output directly from the Serial Monitor and paste into a text editor, spreadsheet, or other data analysis tool.

The second tool we can use to see our data in the Arduino program is the Serial Plotter, a visual version (aka graph) of the Serial Monitor. To use the Serial Plotter, go to Tools –> Serial Plotter. The graph below is the output of the LED as a light sensor from Project 3!*

The plot will auto-scale and as long as you’re using Serial.println() for your sensors, it will also print all of your sensors in different colors. Hooray! That’s it!

*If you look at the end, there is a super interesting wave pattern which is likely due to the Alternating Current (“AC”) in our overhead lights!

Visualizing Data: Excel!

For more serious data analysis, there’s a super cool (and free!) add-in for Excel called Data Streamer*, which you can download here.

This add-in reads from the serial port, so we can use the exact same coding technique of printing data to serial to get data directly into Excel.. heck yes!!

How to use the Data Streamer Add-In:

1. Once you’ve installed it (or if you have O365), click on the Data Streamer tab (far right) in Excel.

2. Plug in your Arduino and click “Connect Device”, then select the Arduino from the drop-down menu.

3. Click “Start Data” to start data collection! You’ll see three new sheets open up: “Data In”, “Data Out”, and “Settings”.

Live data is printed in the Data In sheet.  Each row corresponds to a sensor reading, with the newest value printed in the last row.

By default we only get 15 rows of data, but you can change this by going to “Settings”. We can gather up to 500 rows (limit is due to Excel bandwidth — there’s a lot happening in the background!).

 

4. Add a Plot of your data! Do some data analysis!
Scatter plots show you how the sensor readings change over time, which is the same thing we saw in the Arduino Serial Plotter.

To add a Scatter Plot:

Go to Insert -> Charts -> Scatter. When the plot pops up, right click on it and choose “Select Data”, then Add. We want our data displayed on the y-axis, with “time”** on the x-axis.

To do this, click the arrow next to the y-axis, go to the Data In sheet, and select all of the incoming sensor data.

We can also do calculations and comparisons in Excel! To write a formula, click on an empty cell and type an equals sign (“=”), then the calculation you want to do. There are lots of built-in commands like average, maximum, and minimum.

To use a command, type the equals sign, the command name, and an open parenthesis, then select the data you’re analyzing and close the parentheses.

5. To send more than one column of data (AKA more than one sensor), print the values on the same line separated by a comma, with a final blank new line, like this:

Serial.print(sensorReading1); 
Serial.print(","); 
Serial.print(sensorReading2); 
Serial.print(","); 
Serial.println();

*Full disclosure: Although this tutorial is not affiliated, I do work w/ the Microsoft Hacking STEM team which developed this add-in.

**If you want the actual time to be on the x-axis, select the timestamp in Column A on the Data In sheet for the x-axis values in your Scatter Plot. Either way, we’ll see our data as it changes over time.

Go Forth and Measure All the Things!!

Alright folks, that’s all! Time to go outward and upward! Use this as a foundation to start exploring sensors, Arduino coding, and data analysis to tackle your questions, curiosities, and fav mysteries in this big, beautiful world.

Remember: there are lots of folks out there to help you along the way, so please leave a comment if you have a question!

Need some more ideas? Here’s how to make a wearable state change switch, a solar-powered remote temperature sensor, and an Internet-connected industrial scale!

Like this tutorial and want to see more? Support our projects on Patreon! 😀

Make a Sneaky Wearable ‘State Change Switch’!

 

Secretly change settings for your wearable outfits or use this button as a secret prank trigger! Here’s a quick & easy tutorial on how to build and program a “state change switch.” AKA a button that cycles through different settings. It’s super easy and has tons of practical applications!

Read Time: ~ 5 min
Build Time: ~ 30 min
Cost: Super cheap (>$5)

Materials!

materials1-sm

— Glove (just one.. but you should probably wear two to avoid giving away the secret)

— Three (3) stranded wire segments (24/26 gauge), approx. 3 ft

Wires should be long enough to reach from your palm to wherever you want to hide the electronics. I hid mine in a belt pouch, but you could also opt for a pocket, backpack, etc.

— One (1) 10kOhm resistor

— One (1) pushbutton (aka momentary switch)

— One (1) 1″ x 1″ piece of thin wood

Those free wood swatches at hardware stores are perfect!

— Microcontroller

I used the SparkFun EL Sequencer b/c I was using this switch to select different settings for my Hallowen EL Wire costume. Check out the tutorial to learn how to build your own version of this costume, or you can use this state change switch with any ol’ microcontroller for your own awesome project!

 

Build it!

schematic_bb

buttonbase1-sm

1. Drill holes in a small piece of wood for the button feet.

resistor1-sm

2. Solder a wire to one of the button legs, and a resistor to the other button leg on the same side. Solder a black wire to the resistor.

3. On the other side of the button, solder a wire to the leg across from the resistor.

4. Test electrical connections, then coat all solder joints in hot glue.

buttonbase-bottom2-sm

5. Connect the black wire to the microcontroller ground, and the wire on the same side to the microcontroller voltage output (Vcc).

6. Connect the wire on the other side to a microcontroller digital (or analog) input pin (see schematic above), and then onward to programming!

buttonbase-solder-sm

 

Program it!

code-screenshot

Most folks that program state change switches use the modular, or mod, operator* to tell different settings apart. It’s not perfect, but for how little code is involved it’s a good way to cycle through different settings and get back to our original state.

Here’s a quick sketch that will allow you switch between three different settings by pushing the button. As is, it’s written to switch between three different digital output settings. In other words, if you have a motor connected to your microcontroller, the button will switch the motor from constantly on, to pulsing (i.e. repeatedly on/off), to constantly off, then back to constantly on.

*The mod operator (usually “%”) divides the number by the value after the operator and gives you the remainder. For example, if you see: 10%2, it means 10 / 2 = 5, which equals 0, since there is no remainder. Another example is 10%3, which equals 1, since 10 / 3 = 3.33, and 0.33 is one out of three. Here’s more info on this or feel free to leave a comment if you have any questions!

 

Finish & Test!

Connect the button wire leads to your microcontroller inputs, run the full program and test to see that it works as expected. If it’s all good, put the glove on and push the state change switch and watch as your costume/insertotherawesomeprojecthere changes through different settings!

Now go forth and show off your project around town!