We all love the many visual elements in the Harry Potter movies, and this project combines two of the most iconic: the Marauder’s Map and the Weasley ‘who is home?’ clock. The project uses a Raspberry Pi to detect the presence of people on the network and an Arduino Uno to control the clock hands.
The full article can be found in The MagPi 56 and was written by Spencer Organ.
You'll need
- Servos (continuous and position)
- Watch hands
- Arduino Uno
- 2× Mini breadboard
- Transparent medium breadboard
- Pimoroni Explorer HAT Pro
- 2× 5V mini DC relay
- 4× LED, male-to-male and male-to-female jumper cables
- A box or clock body
- Background graphics
STEP-01 Preparing the setup
We start the project by setting up the Raspberry Pi and Explorer HAT Pro. Install the libraries for the Explorer HAT Pro using the tutorial on the Pimoroni GitHub page. In this project we will be using two of the 5V DC outputs from the HAT to activate a relay. Note: These ports don’t actually output 5V, but connect to ground when activated.
STEP-02 Configure the code
Clone the Python code from the GitHub. You will need to find the MAC addresses for each of the devices you will be detecting on the network, and substitute them into the code. It is important that all the devices are on the same network as the Pi. On an iOS device you can find your MAC address under Settings > General > Wi-Fi address; on an Android device, it’s in Settings > About phone (or tablet) > Status.
STEP-03 Connect the servos
We then need to connect the two servos to the Arduino. Use a breadboard to connect a common 5V and ground line from the Arduino. Connect the red power cables on each of the servos to the common 5V line, and the brown wire to the common ground. Use jumper cables to connect the orange signal wire of the continuous servo to digital pin 12 on the Arduino, and the orange signal wire of the position servo to digital pin 11. The continuous rotation servo will become our second hand on the clock face, and the position servo will show whether people are home or away.
STEP-04 Connect the LEDs
We will be using four LEDs to light up different parts of the Marauder’s map. Connect the short leg (cathode) to a common ground. Connect the long leg (anode) to digital pins 5,6,7, and 8.
The following LED pins are used:
- Digital Pin 5 = Person 2
- Digital Pin 6 = Away notification
- Digital Pin 7 = Person 1
- Digital Pin 8 = Home notification
STEP-05 Link the Pi and Arduino
Before connecting the relays, we will need to look at the pin guide and identify the two pins for the coil and the two pins for the switch. One side of the coil on both relays should be connected to the 5V output on the Explorer HAT Pro. The other side of the of the relay coil should then be connected to output 1 and 2 on the Explorer HAT Pro. The common switch connector on both relays should then be connected to the common ground on the Arduino. The switch connector on the first relay is connected to Digital 1 on the Arduino, and the switch connector on the second relay is connected to Digital 2. We will be using the switch connector, which is activated when the relay receives power.
STEP-06 Assembling the project
We will need to download the code for the Arduino and upload it to the Uno from the GitHub again. We then need to assemble our project. In our example we have used a fruit box, but you could use an old clock, a cardboard box, or a hobby box. We need to (carefully) screw clock hands to the two servos; take care not to move the servo as it can cause damage. Mount the two hands so that that the continuous rotation servo can move freely and the positional servo can move up and down.
Code Listing
!/usr/bin/env python import subprocess import time import explorerhat occupant = ["Person 1 device","Person 2 device"] # MAC addresses for our devices - in order of people above address = ["XX:XX:XX:XX:XX:XX","XX:XX:XX:XX:XX:XX"] while True: print("starting loop") output = subprocess.check_output("sudo arp-scan -l", shell=True) print ("starting scan") for i in range (len(address)): if address[i] in output: print address[i] print occupant[i] if "XX:XX:XX:XX:XX:XX:XX" in output: #Person 1 MAC address explorerhat.output[0].on() else: explorerhat.output[0].off() if "XX:XX:XX:XX:XX:XX:XX" in output: #Person 2 MAC address explorerhat.output[1].on() else: explorerhat.output[1].off() time.sleep(60)