Introduction: The Magic Window (Arduino + Hall Sensor)
Project overview
Here is just a simple guide on how to create your own "magic window" using an Arduino and Processing.
This window will switch videos when closing the doors. This design uses an Arduino UNO, a Hall Sensor and you also need a laptop with Processing on it. Ultimately from this tutorial, I hope you learn how to use a Hall Sensor and combine this knowledge with Processing to control video and many other things! :)
Step 1: What Do We Need?
Just to get the sensor working:
- Arduino Uno (or any other Arduino board compatible with processing)
- Hall Sensor (The little black thing measuring magnetic fields)
- 10k resistor
- Jumper wires (x3)
- A magnet
- (Breadboard could come in handy for testing purposes)
The wooden construction:
- 6mm MDF - 600mm by 300mm (x6)
- 4mm MDF - 600mm by 300mm (x2)
- 3mm MDF - 600mm by 300mm (x4)
- Door knobs (x2)
Piano hinges
A old monitor to display the videos
Programs:
- Arduino
- Processing (install libraries > Serial, Sound, Video)
Step 2: Making the Sensor Work! (Arduino Code)
BEGIN ARDUINO CODE
const int buttonPin = 2; // the pin that the Hall Sensor is attached to
const int ledPin = 13; // the pin that the LED is attached to// Variables will change: int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input: pinMode(buttonPin, INPUT_PULLUP); Serial.begin(9600); }void loop() {// read the pushbutton input pin: buttonState = digitalRead(buttonPin); //Serial.println(buttonState); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == LOW) { Serial.println("1"); } else {
Serial.println("2"); } // Delay a little bit to avoid bouncing delay(10); }
lastButtonState = buttonState;
}
END ARDUINO CODE
When done correctly. Getting a magnet close to the Hall Sensor wil show 1 in the serial monitor.
Moving the magnet away from the sensor wil give 2 in the serial monitor.
Step 3: Using the Serial Data in Processing
Before testing to code, make sure you installed the correct libraries! (install by adding library and searching for official Processing sound, serial and video libraries!
- import processing.sound.*;
- import processing.serial.*;
- import processing.video.*;
BEGIN PROCESSING CODE
import processing.sound.*;
import processing.serial.*; import processing.video.*;Serial magnetPort; String val = ""; final static byte Videosum = 6; Movie[] myMovie = new Movie[Videosum]; int Shuffle; boolean speel = false; String res =""; int lf = 10; SoundFile file;
void setup() {
size(1280, 1024); // canvas where video plays String portName = Serial.list()[1]; magnetPort = new Serial(this, portName, 9600); //baud rate // movie files placed in map myMovie[0] = new Movie(this, "/you/data/movieclip1.mp4"); myMovie[1] = new Movie(this, "/you/data/movieclip2.mp4");
myMovie[2] = new Movie(this, "/you/data/movieclip3.mp4"); myMovie[3] = new Movie(this, "/you/data/movieclip4.mp4"); myMovie[4] = new Movie(this, "/you/data/movieclip5.mp4"); myMovie[5] = new Movie(this, "/youdata/movieclip6.mp4");
file = new SoundFile(this, "/you/data/mysterysound.wav");
for(int i=0; i myMovie[i].loop(); } magnetPort.bufferUntil(lf); }
void draw()
{ //constant afspelen if(speel == true){ image(myMovie[Shuffle], 0, 0, width, height); //file.stop();} else {
// } }
void movieEvent(Movie m) {
m.read(); }void serialEvent(Serial p){
// print("hier"); // if data is available val = p.readString(); println(val); res = trim(val); // print data naar console // println(res);
if ((res.equals("2") == true)) { speel = true; //defineren boolean Shuffle = int(random(0, 5)); file.stop(); file.amp(0); } if ((res.equals("1") == true)) { speel = false; file.amp(1); file.play(); }
}
END PROCESSING CODE
Arduino should send the 1 and 2 from step 2 which Processing uses to start the videofiles!
A shuffle function is added for randomizing the videos.
We hooked up the old monitor to test the image quality.
Step 4: Assembling the Wooden Construction
Lasercut the design and assemble the pieces. You may need wood glue for extra firmness!
The doors are made by lasercutting 5 wooden pieces and glueing them together.
Inside the box is enough space to place the monitor and behind that a laptop.
There is also room for the Arduino Uno.
As you can see, a magnet was placed on the right door (red circle). The Hall sensor is placed in the green circle. This way we can use our Arduino and Hall sensor to recognize if the doors are open or closed.
Attachments
Step 5: The End Result.

Runner Up in the
Sensors Contest 2017

Participated in the
Microcontroller Contest 2017
2 Comments
6 years ago
That's a fun idea! I'd set this up in a history or geography class to show different places around the world. The kids would love it :)
Reply 6 years ago
That's a awesome idea ^^! Thank you :)