The Sorting Hat

There can’t be a Marauder’s Map without Hogwarts, there can’t be Hogwarts without houses, and there can’t be houses without the magical sorting hat. Alas, as we are not fictional wizards, so we used the magic of technology to make our hat.

Our hat consists of two main parts: A toy hat stuffed with a MyRio, and a laptop running a LabVIEW code.

The Hat

The toy hat we bought already contained motors that actuated when the hat spoke, giving it the illusion of life. To activate it you just pressed a button on the brim and the hat would cycle through 5 different pre-programmed voice lines and assign you a house. Unfortunately there was no way to link this existing hardware with our LabVIEW code, so we gutted it and hooked the motors and button up to a MyRio. Utilizing LabVIEW’s shared variables we were then able to read the button and actuate the motors wirelessly.

Below you can see the circuit we used to run the hat off the Rio.

The hat came with a 5 volt DC motor connected to a cam shaft that flexed the upper part of the hat to make its eyebrows move. Since the MyRIO runs on 3.3 volt logic, we had to use an H bridge to control the motor. The Vin for the motor was connected to the 5 volt pin on the MyRio, and the actuation of the motor was controlled with 2 digital logic pins. Since the direction of the motor didn’t mater (the hat moved in the same pattern either way), we had one pin always connected to ground and the other turn the motor on and off. The button on the side of the hat was also utilized. When the button was pressed, the MyRio sensed the press and started the code for the talking hat. Every time the hat talked, the motor was also prompted to move.

The Code

Here is a screenshot of the labview code. It’s pretty large so click on it to see the specifics

The labview code that ran the hat was built as a series of 6 frames in a flat sequence structure. Once someone hit the button on the hat the code was set into motion as a boolean in the first frame got set to true. The second frame played a wav file that asked the user to state their name, while at the same time it actuated the hat motors so it looked like it was talking. The third frame started by running the google speech API. It works by recording sound for 2 seconds, sending that sound as a wav file to google, and then google replies with the most probable text translation of the sound byte. If google was unable to find recognizable words in this sound byte the api instead throws an error. If our code received the error statement a new wav file was played that prompted the user to restate their name. Otherwise their name was displayed and the user was asked to confirm that it was, in fact, their name. From there, a random house is chosen and a wav file is played in frame 4 that says what house they’ve been sorted into and asks them if they’re the final student. Frame five ran the google speech API again, trying to find a “yes” or “no” response. Frame six took the user’s name and house, paired them together into a cluster, and sent them to an array outside the main loop. If the user said no in frame 5, the code repeated. if they said yes, then the code would end, the array of names and houses would be turned into a JSON string, and that JSON would be sent to the could for other project groups to use.

 

Here is a video of the hat sorting Anna.

The SWOT

  • Strengths
    • The hat is fun for children and adults alike
    • Unlike most aspects of this project it can be marketed as a standalone product
    • Being able to speak directly to the hat is engaging and will keep people interested
  • Weaknesses
    • The voice control is finnicky. It requires a quiet room and a clear voice or else it wont pick up what you’ve said
    • Putting a MyRio on your head makes the whole thing very heavy and unweildy
    • The battery pack is even heavier than the rio itself
    • Since the voice control runs off of google, it needs to be always connected to wifi to function.
  • Opportunities
    • Universal would love a product like this related to the harry potter universe. See strengths as to why
    • The same concepts could be applied to other talking toys, as currently the market is filled with toys that can’t respond to a what a child says.
  • Threats
    • There are a lot of talking toys on the market and as the technology gets cheaper this sort of device will be able to be made en masse
    • It relies on the google voice API, so it would have to get licenced by google before it could be sold by another company
    • Since the device is always connected to wifi it needs adequate protection against hackers who might want to steal information stored on the device.