A Sorting box

Sep.23.19
Project Members : Hyelim Lim, Yuan Chen



Harry Potter is a series of fantasy novels written by British author J. K. Rowling. The books have attracted a wide adult audience as well as younger readers and are often considered a cornerstone of modern young adult literature.

One of the most impressive highlights in the book is the scene that students are assigned their houses by a talkative sorting hat. Base on this scene, my team came up with the idea: a “sorting box”. With a LCD display screen, four buttons, and an Ardurino board, we make the sorting box.


Here is how the sorting box works: when the LCD display turns on, the screen says: “Welcome to Hogwarts!“ After that the player chooses the button, the screen will show the name of the house based on the representative color of each house:
Red : Gryffindor, Blue : Ravenclaw, Yellow : Hufflepuff, Green : Slytherin

The name of the chosen house will only remain on the screen for 3 seconds. Then, it will go back to the greeting page. The player can press another button.


The possible improvement from this stage: If my team get the chance to improve the project, we will make a real sorting hat. I will mount the screen onto a hat. By putting the hat on the player’s head, a switch will be triggered. The hat will show a random house’s name out of the 4 houses, and the back light of the screen will light up in the representative color of that house.

This is the code : 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#include <LiquidCrystal.h>          //the liquid crystal library contains commands for printing to the display

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);   // tell the RedBoard what pins are connected to the display

//set the pins where the buttons
const int BluePin = 2;
const int YellowPin = 3;
const int RedPin = 5;
const int GreenPin = 4;

int BlueState = 0;         // variable for reading the pushbutton status
int RedState = 0;         // variable for reading the pushbutton status
int YellowState = 0;         // variable for reading the pushbutton status
int GreenState = 0;         // variable for reading the pushbutton status

void setup() {

  lcd.begin(16, 2);                 //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high
  lcd.clear();                      //clear the display
  // initialize the pushbutton pin as an input:
  pinMode(BluePin, INPUT);
  pinMode(YellowPin, INPUT);
  pinMode(RedPin, INPUT);
  pinMode(GreenPin, INPUT);

  Serial.begin(9600);
}

void loop() {
  // read the state of the pushbutton value:
  BlueState = digitalRead(BluePin);
  RedState = digitalRead(RedPin);
  YellowState = digitalRead(YellowPin);
  GreenState = digitalRead(GreenPin);
  Serial.print("B: ");
  Serial.println(BlueState);
  Serial.print("Y: ");
  Serial.println(YellowState);  
  Serial.print("R: ");
  Serial.println(RedState);  
  Serial.print("G: ");
  Serial.println(GreenState);



  lcd.setCursor(0, 0);              //set the cursor to the 0,0 position (top left corner)
  lcd.print("Welcome to");
  lcd.setCursor(0, 1);
  lcd.print("Hogwarts");  //print hello, world! starting at that positio

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (RedState == HIGH) {
    // PrintA:
    lcd.clear();                      //clear the display
    lcd.setCursor(0, 0);              //set the cursor to the 0,0 position (top left corner)
    lcd.print("Gryffindor");       //print hello, world! starting at that positio
    delay(2000);
  } else if (BlueState == HIGH) {
    // PrintB:
    lcd.clear();
    lcd.setCursor(0, 0);              //set the cursor to the 0,0 position (top left corner)
    lcd.print("Ravenclaw");       //print hello, world! starting at that positio
    delay(2000);
  } else if (YellowState == HIGH) {
    // PrintC:
    lcd.clear();
    lcd.setCursor(0, 0);              //set the cursor to the 0,0 position (top left corner)
    lcd.print("Hufflepuff");       //print hello, world! starting at that positio
    delay(2000);
  } else if (GreenState == HIGH) {
    // PrintD:
    lcd.clear();
    lcd.setCursor(0, 0);              //set the cursor to the 0,0 position (top left corner)
    lcd.print("Slytherin");       //print hello, world! starting at that positio
    delay(2000);
  } else {
  }
}