Site wide message

Wizard lamp assembly & programming tutorial

Welcome, and thank you for buying our DIY wizard lamp! Here you'll find video tutorials, presented by our Design Engineer KP, to help you assemble and then program your wizard lamp. Under these videos there are written set instructions, as well as code for you to copy.

Good luck!

Video tutorials

Assembly

Programming

Parts (Included)

  • 1x Magic Wand Sensor
  • 1x LED Strip
  • 1x Arduino Nano
  • 1x USB cable
  • 4x Screws
  • Plywood
  • Diffusion Paper

Tools (not included)

  • Any glue of your choice. Kids should not use superglue.
  • Screwdriver
  • Scissors

Assembly

Start by assembling the electronics holder.



Plug in the Nano to the mini USB cable and place it on top of the 3mm plywood holder, there is a cutout for the SPI pins.




Then place the 6mm plywood spacer around the Nano.




Add the LED strip holder on top of that and screw it in place with 2 screws.






Next step cut the diffusion paper with scissors into 5 squares approximately 120mm by 120mm each.




Make a 30mm diameter hole in the centre of one of the squares for the sensor. You can do this with an exacto knife or fold the paper twice and cut the corner in the middle.




Glue the diffusion paper on all sides except the base. Glue the diffusion paper with a hole on the top panel.




Start assembling the box together. You have a top panel, base panel and four sides with opposite sides being the same.



Add some glue on the finger joints for one of the sides and glue it in place. It doesn’t matter which side you start with, the base panel is symmetrical.




Do the same for the adjacent panel. Don’t forget to put glue on both edges that are interlocked.





Do the same for the rest of the side panels.




Next step is to put the sensor together.



Bend the sensor 90° with the text on the sensor pointing up.




Thread the sensor through the 6mm plywood holder. Make sure that the side of the sensor with text on is pointing up as that is the side that will detect the magic wand.



Add plenty of glue around it and glue it to the middle of the top panel where we made a cutout earlier.




Add some glue in the cutout at the back of the sensor holder for cable strain relief.




Glue in the top panel in place.





Wiring


Sensor 

Nano 5V > Sensor VDD (RED connector)
Nano GND > Sensor GND (BLACK connector)
Nano PIN D8 > Sensor OUTPUT (Yellow connector)

LED Strip

Nano VIN > LED Strip +5V (RED connector)
Nano PIN D3 > LED Strip Din (White connector)
Nano GND > LED Strip GND (BLACK connector)

Wiring the LED Strip



If the led strip has an adhesive at the back remove the protective film first.



Add some glue to the 3mm ply and glue in the led strip in place with the wires coming out of the opposite side of the USB.




Connect the LED wires as shown in the image below. With the red connector going to the 5V pin, black connector going to the GND pin and the white connector going to D3 pin.



Next place the Nano close to the box and wire the sensor.



Connect the wires as shown in the images below. Red connector goes to 3V, yellow connector goes to D8 and black connector goes to GND pin.



Push the USB cable through the cutout and secure the electronics holder to the base with two screws. Be careful not to pinch any wires.






Congratulations, you have completed the assembly!

The lamp will turn on automatically once you plug it in and after that you can use the Magic Wand to turn it on or off. By default the colour is cool blue. You can change the colour by editing the Arduino code provided. Follow the instructions below on how to set up the Arduino programming environment and upload new code.

Programming that Extra Special Stuff

Extend your learning by altering the code on your Arduino to create different colours and effects!


Step 1 - Installing the Arduino Programmer

https://www.arduino.cc/en/main/software

Follow the link above to download the official Arduino IDE (Integrated Development Environment).

An IDE is like a text editor, except with several built in functions to make the lives of programmers easier. For example, the Arduino IDE includes a way to check if the code you’ve written is correct, and also a way to compile and send the code up to whatever compatible device you have connected.

Here you will be able to download and install the application for Linux, Mac OS, or Windows.  Follow the installation instructions.

How to install on Windows - https://www.arduino.cc/en/Guide/Windows

How to install on OS X - https://www.arduino.cc/en/Guide/MacOSX

How to install on Linux - https://www.arduino.cc/en/Guide/Linux


Step 2 - Installing the Adafruit NeoPixel Library

Our Wizard Lamp is lit up using a WS2812b RGB (red, green, blue) LED.

For the Microcontroller to properly communicate with this LED, we need to give it the vocabulary for our instructions. Luckily, there’s a free and widely used Library that is available for us to download and install.

Open Arduino IDE and click Sketch -> Include Library -> Manage Libraries...

Type "NeoPixel" in the search bar, select the Adafruit NeoPixel from the results and click Install.



We’ve written some different behaviours for you to download and install for your Wizard Lamp.  Copy the code below into your Arduino IDE as a New Sketch or download the direct file here.

Download the code from this page by clicking on Clone or download and then Download ZIP.



Install the Code

Easy: Change the colour of your light (rainbow colours)

Step 1:

Copy and paste the code below into your Arduino IDE as a New Sketch and upload it.  Once you’ve copied or downloaded one these files, you can open them up with the Arduino IDE you just installed.

File Name: DIY_Wizard_Lamp_Rainbow.ino

Download file: here

Or copy below:

/**************************************************************************
* Magic Wand Activated Wizard Lamp
*
* Written by The Magic Of Things
*************************************************************************/


#include <Adafruit_NeoPixel.h>

// Arduino pin connected to the LED strip
#define stripPin 3

// How many LEDs are attached to the Arduino
#define numberOfPixels 5

// Setup the NeoPixel library with the number of pixels, pin and type of pixel
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numberOfPixels, stripPin, NEO_GRB + NEO_KHZ800);

int sensorPin = 8; // Arduino pin connected to the Hall effect sensor
int currentState = HIGH; // the current state of the output pin
int sensorReading; // reading from the sensor pin
int previousSate = LOW; // the previousSate reading from the input pin

// Variables used for debouncing
long time = 0; // the last time the output pin was toggled
long debounce = 100; // delay between readings

void setup()
{
//Initialise the sensor pin as an input with a pullup resistor
pinMode(sensorPin, INPUT_PULLUP);
//Initialise the led strip
strip.begin();
}


//Main program loop
void loop(){

//Turn the light ON
if (currentState == HIGH) {
cycleColors();
}

//Turn light OFF
if (currentState == LOW) {
turnOff();
}

// Function that checks a wand tap and it will toggle the lamp on/off with every tap
checkState();
}


void cycleColors(){
int i, j;
for(i=0; i<256; i++) {

for(j=0; j<strip.numPixels(); j++) {
strip.setPixelColor(j, colorWheel((j+i) & 255));
}

strip.show();

//Delay between colour changes in ms
delay(200);

//Keep checking for a wand tap during the animation
checkState();
if (currentState == LOW) {
turnOff();
break;
}
}
}


// Transition the colours
unsigned long colorWheel(byte colorPosition) {
colorPosition = 255 - colorPosition;
if(colorPosition < 85) {
return strip.Color(255 - colorPosition * 3, 0, colorPosition * 3);
}
if(colorPosition < 170) {
colorPosition -= 85;
return strip.Color(0, colorPosition * 3, 255 - colorPosition * 3);
}
colorPosition -= 170;
return strip.Color(colorPosition * 3, 255 - colorPosition * 3, 0);
}

//Function to turnoff the led strip
void turnOff(){
for(int i=0;i<numberOfPixels;i++){
strip.setPixelColor(i, strip.Color(0,0,0)); // Turn pixels off.
strip.show(); // Show the selected colour on the pixel
}
}

// Function that checks a wand tap and it will toggle the lamp on/off with every tap
void checkState(){
sensorReading = digitalRead(sensorPin); //Get a reading from the sensor

// if the input changed between HIGH and LOW and we've waited long enough
// for debouncing, toggle the output pin and record the current time
if (sensorReading == LOW && previousSate == HIGH && millis() - time > debounce) {
if (currentState == HIGH)
currentState = LOW;
else
currentState = HIGH;

time = millis();
}

previousSate = sensorReading;
}


Step 2: Upload the file (see "Uploading the code to the board" below)


Harder: Change the colour of your light (single colour)

Step 1: Copy and paste the code below into your Arduino IDE as a New Sketch and upload it.  Once you’ve copied or downloaded one these files, you can open them up with the Arduino IDE you just installed.

File Name: DIY_Wizard_Lamp.ino

Download file: here

Or copy below:

/**************************************************************************
* Magic Wand Activated Wizard Lamp
*
* Written by The Magic Of Things
*************************************************************************/

///////////////////////////////////////////////////////////////////////////
//////////The following segment sets up all the technical stuff////////////
///You shouldn't change these lines unless you're a well trained wizard!///
///////////////////////////////////////////////////////////////////////////


#include <Adafruit_NeoPixel.h>

// Arduino pin connected to the LED strip
#define stripPin 3

// How many LEDs are attached to the Arduino
#define numberOfPixels 5

// Setup the NeoPixel library with the number of pixels, pin and type of pixel
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numberOfPixels, stripPin, NEO_GRB + NEO_KHZ800);

int sensorPin = 8; // Arduino pin connected to the Hall effect sensor
int currentState = HIGH; // the current state of the output pin
int sensorReading; // reading from the sensor pin
int previousSate = LOW; // the previousSate reading from the input pin

// Variables used for debouncing
long time = 0; // the last time the output pin was toggled
long debounce = 100; // delay between readings

//////////////////////////////////////////////////////////////////
///////OK, with that out of the way, let's see what's next.///////
//////////////////////////////////////////////////////////////////
///This following line lets you change the color of your light.///
//////////////////////////////////////////////////////////////////

//Set the pixel colour
// strip.Color takes RGB values, from 0,0,0 up to 255,255,255
int r = 180, g = 255, b = 255;

//

//////////////////////////////////////////////////////////////////////////////////////
///////The following segment, once again, just deals with the technical aspects///////
//////////////////////////////////////////////////////////////////////////////////////

void setup()
{
//Initialise the sensor pin as an input with a pullup resistor
pinMode(sensorPin, INPUT_PULLUP);
//Initialise the led strip
strip.begin();
}


//Main program loop
void loop(){

//Turn the light ON
if (currentState == HIGH) {
singleColor();
}

//Turn the light OFF
if (currentState == LOW) {
turnOff();
}

// Function that checks a wand tap and it will toggle the lamp on/off with every tap
checkState();
}

//Single colour animation
void singleColor(){
for(int i=0; i<numberOfPixels; i++) {
strip.setPixelColor(i,r,g,b);
}
strip.show();
}


//Function to turnoff the led strip
void turnOff(){
for(int i=0;i<numberOfPixels;i++){
strip.setPixelColor(i, strip.Color(0,0,0)); // Turn pixels off.
strip.show(); // Show the selected colour on the pixel
}
}

// Function that checks a wand tap and it will toggle the lamp on/off with every tap
void checkState(){
sensorReading = digitalRead(sensorPin); //Get a reading from the sensor

// if the input changed between HIGH and LOW and we've waited long enough
// for debouncing, toggle the output pin and record the current time
if (sensorReading == LOW && previousSate == HIGH && millis() - time > debounce) {
if (currentState == HIGH)
currentState = LOW;
else
currentState = HIGH;

time = millis();
}


previousSate = sensorReading;
}


Step 2: Look for this section of code:

//Set the pixel colour

int r = 0, g = 255, b = 255;

Change the number values in this line:


int r = 0, g = 255, b = 255;

To change the colour.

Note: Any line of code starting with a // is called a Comment. This is solely included for documentation and for users to read and understand how some of the code works, and will be ignored by the Microcontroller (Arduino).

Values may go from 0 (meaning no light) to 255 (for full brightness of each respective color)

For example:

int r = 255, g = 0, b = 0;

Means Red will be at maximum brightness, while Green and Blue are completely dark.

The result is a bright red light.


int r = 0, g = 0, b = 255;


Results in a bright blue, as the other two colors are off.

We’ve included some values below for a few different colors you might like, but feel free to mix and match to find your own combinations.



You can also visit websites such as THIS ONE, where you can select a colour, and see the RGB values for it. Note that the numbers you get may require further tweaking, as they are calibrated to a different colour space.

Step 3: Upload the file (see "Uploading the code to the board" below)


Uploading the code to the board



Click on Tools and from the drop down menu select:

Board: "Arduino Nano"
Processor: "ATmega328P(Old Bootloader)"
Port will be selected automatically but if it doesn't work change it other available port.
After selecting the board, processor and port click on the arrow in the top left corner to upload the code.

You might need the CH340 USB drivers in order to upload to the bard. You can download them from here:

CH340 Windows
CH340 Linux
CH340 MAC

Prefer a pdf format, or want to print it out? Find our written tutorial here

Looking for your next project?

Why not check out our monthly susbscription kit! Get a new project every month, including a wand-interactive chest!

wizard chest