Introduction: Working Harry Potter Wand With AI

At first, I was going to make a Harry Potter wand that would glow at the tip. After that, I decided, it would be cool if you could cast spells with this. So the result of that thought was this, a code that would harness the power of machine learning and find out which spell is being cast, and cast it. I hope you enjoy making your AI. I used Chat GPT to help with some of the code, so please be aware that I did not completely write it.

Supplies

Materials

1x Joystick

1x 2 color led

1x Push button

A few female-to-female jumper wires

1x 2 AAA battery pack with batteries

Aluminium Foil

wooden kebab skewer

Tools used


Soldering iron/ wood burner

3D pen

Hot glue


Software


I used pyCharm IDE with Python 3.12.2

Step 1: Connecting the Electronics

You can skip ahead to step to step 5 if you bought a wand or have a pre-made one. Just attach a distinctive color like red or green to the front and start coding.

Here the connections are straightforward

First, you connect the battery's positive to the 5V of the joystick.

Next, you connect the VRX and the VRY of the joystick to the red and green legs of the LED.

Then you connect the ground leg of the LED to one side of the button.

Lastly, connect the remaining side of the button to the battery's ground.

You can refer to the pictures for any clarification, but the wiring is simple for this project and there is no soldering.

Step 2: Connecting It to the Skewer

This step is easy, but make sure the button and joystick are on opposite sides of the skewer around 1 inch apart. Also, if you want a shorter wand you can trim the edge of it. Also here I removed the joystick's cap because it was too large.

Step 3: Wrapping It in Foil

Here you wrap the skewer in around 3-4 layers of aluminum foil. Be careful to keep an opening for the button, joystick, and LED so you can still control the colors of the light. Before wrapping it test that it displays the 2 different colors.

Step 4: Adding the Surface

For this project, I used a 3d pen to make the surface. You can paint directly onto the foil, but I do not feel like it gives the project a finished look. My 3D pen was cheap(around $10), and there are better pens and more skilled people but I feel that the overall look is nice. After adding the filament, I melt and smooth it back down using a soldering iron and it makes a difference. After that, I just coated it with some paint and I was done. You can see that it can emit 3 different colors, red, orange, and green.

Step 5: Collecting Data for the AI

So now we are going to start collecting data for our model. First, you can collect some data for the model for none. This is going to be so that the AI can recognize if a spell is not being cast. So each time run the program and hold the wand so that it learns if a spell is not being cast. For the Lumos spell, you can refer to the chart, and then change lines 77 and 80 from None to Lumos. Then you record yourself doing a lot of these spells using the code. Then you do the same thing for Nox. You should have around 70 pictures for each file. For this one, you have to install the libraries openCV2 and scikitlearn.

Attachments

Step 6: Training the Model

As long as you saved the files as "Lumos", "Nox", and "None", all you have to do is run the code. If you want to you can run this multiple times and choose the one with the highest percentage. (Around 96 or 95 percent). For this one, you have to install the libraries keras, openCV2, and scikitlearn.

Attachments

Step 7: Testing With the Model

Now you just have to run the code attached. This will turn the brightness to 100 if you cast Lumos, and turn the brightness to 20 if you cast Nox. For this step, you need to install the library screen_brightness_control. The video adjusted for the change in brightness, but you can see that it changed.

Attachments

Step 8: Now Were Done!

Now you can test around with these codes, and code some more spells, or modify the ones here. With this model, instead of making if change the brightness, I trained it to also turn on the light when running Lumos.

Books and Bookshelves Contest

Participated in the
Books and Bookshelves Contest