Spirit In A Box Halloween Trick

Updated 22 January 2024

Introduction

This project was born from the desire to craft a captivating and spine-tingling magic trick that would add an air of mystique to a Halloween and supernatural-themed party that I would be attending. It aimed to immerse partygoers in an unforgettable experience, wherein the host took center stage to perform, aiming to amaze, trick, and send shivers down their spines through a series of magic tricks.

The core mechanics of this specific enchanting trick involve technology, blending an Arduino-programmed Wemos D1 Mini, a 5V Electromagnet, and a bell to create an illusion of ghostly presence. The Electromagnet was strategically positioned beneath the box's top, near a hanging bell, and controlled by a MOSFET Power Switch soldered to the Wemos D1 Mini. When triggered, the Electromagnet activates for 1 second, followed by a 0.5-second pause, making the bell sway and emit an eerie ring.

The real magic unfolded through wireless control, with the Wemos D1 Mini acting as an access point, creating a web server accessible via an IP address. A simple webpage allowed users, for me in this case, to remotely control the bell, enhancing the illusion of a ghostly presence. This wireless operation is seamlessly integrated with our constant connectivity to smartphones. The best part is, in this day and age, someone being on their phone is natural and unsuspicious,

What made this trick even more enchanting was its self-sufficiency, being entirely battery-powered and devoid of visible external wires. This added an extra layer of mystery, allowing placement in any location without revealing the secret. However, it's important to note that this trick required a partner, similar to scenes in movies where a crafty assistant secretly aided the main character in their deception, to maintain the illusion.

Parts & Tools

Parts Used:


Tools:

 

Wiring Diagram

Code

/*MIT License

Copyright (c) 2023 That's So Mo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This code has been modified by That's So Mo to be "suited" for the magic bell trick, it was initially created by Awais Naeem over at www.embedded-robotics.com
This code will configure ESP8266 in SoftAP mode and will act as a web server for atleast two connecting devices. Indiviual will then be allowed to turn On/Off the magnet.
 */
 
#include 
#include 
 
/*Specifying the SSID and Password of the AP*/
 
const char* ssid = "TrudyNet7315"; //Access Point SSID
const char* password= "Test123456"; //Access Point Password
uint8_t max_connections=2;//Maximum Connection Limit for AP
int current_stations=0, new_stations=0;
 
//Specifying the Webserver instance to connect with HTTP Port: 80
ESP8266WebServer server(80);
 
//Specifying the Pins connected from magnet to Wemos
uint8_t magnet_pin=D1;
 
//Specifying the boolean variables indicating the status of wemos to Magnet
bool magnet_status=false;
 
void setup() {
  //Start the serial communication channel
  Serial.begin(115200);
  Serial.println();
 
  //Output mode for the magnet Pins
  pinMode(magnet_pin,OUTPUT);
   
  //Setting the AP Mode with SSID, Password, and Max Connection Limit
  if(WiFi.softAP(ssid,password,1,false,max_connections)==true)
  {
    Serial.print("Access Point is Created with SSID: ");
    Serial.println(ssid);
    Serial.print("Max Connections Allowed: ");
    Serial.println(max_connections);
    Serial.print("Access Point IP: ");
    Serial.println(WiFi.softAPIP());
  }
  else
  {
    Serial.println("Unable to Create Access Point");
  }
 
  //Specifying the functions which will be executed upon corresponding GET request from the client
  server.on("/",handle_OnConnect);
  server.on("/magneton",handle_magneton);
  server.on("/magnetoff",handle_magnetoff);
  server.onNotFound(handle_NotFound);
   
  //Starting the Server
  server.begin();
  Serial.println("HTTP Server Started");
}
 
void loop() {
  //Assign the server to handle the clients
  server.handleClient();
     
  //Continuously check how many stations are connected to Soft AP and notify whenever a new station is connected or disconnected
  new_stations=WiFi.softAPgetStationNum();
   
  if(current_stationsnew_stations)//Device is Disconnected
  {
    current_stations=new_stations;
    Serial.print("Device disconnected from SoftAP... Total Connections: ");
    Serial.println(current_stations);
  }
 
  //Turn the magnet ON/OFF as per their status set by the connected client
   
  //magnet
  if(magnet_status==false)
  {
    digitalWrite(magnet_pin,LOW);
  }
  else
  {
    digitalWrite(magnet_pin,HIGH);
    delay(1000);
    digitalWrite(magnet_pin,LOW);
    delay(500);        
  }
 
}
 
void handle_OnConnect()
{
  Serial.println("Client Connected");
  server.send(200, "text/html", HTML()); 
}
 
void handle_magneton()
{
  Serial.println("magnet ON");
  magnet_status=true;
  server.send(200, "text/html", HTML());
}
 
void handle_magnetoff()
{
  Serial.println("magnet OFF");
  magnet_status=false;
  server.send(200, "text/html", HTML());
}
  
void handle_NotFound()
{
  server.send(404, "text/plain", "Not found");
}
 
String HTML()
{
  String msg=" \n";
  msg+="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  msg+="<title>Magnet Control</title>\n";
  msg+="<style>html{font-family:Helvetica; display:inline-block; margin:0px auto; text-align:center; background-color:#2B2934;}\n";
  msg+="body{margin-top: 50px;} h1{color: #000000; margin: 50px auto 30px;} h3{color:#000000; margin-bottom: 50px;}\n";
  msg+=".button{display:block; width:80px; background-color:#f48100; border:none; color:white; padding: 13px 30px; text-decoration:none; font-size:25px; margin: 0px auto 35px; cursor:pointer; border-radius:4px;}\n";
  msg+=".button-on{background-color:#26282d;}\n";
  msg+=".button-on:active{background-color:#26282d;}\n";
  msg+=".button-off{background-color:#000000;}\n";
  msg+=".button-off:active{background-color:#000000;}\n";
  msg+="</style>\n";
  msg+="</head>\n";
  msg+="<body>\n";
  msg+="<h1>The Bell Magic Trick Server</h1>\n";
  msg+="<h3>Using Access Point (AP) Mode</h3>\n";
   
  if(magnet_status==false)
  {
    msg+="<p>MAGNET Status: OFF</p><a class=\"button button-on\" href=\"/magneton\">ON</a>\n";    
  }
  else
  {
    msg+="<p>MAGNET Status: ON</p><a class=\"button button-off\" href=\"/magnetoff\">OFF</a>\n";
  }
   
  msg+="</body>\n";
  msg+="</html>\n";
  return msg;
}

Photo Gallery

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.