2023 Group 3 – Aladdin Genie Lamp

User-interactive Theatrical Props

By: Emma Gonzalez, Liyana Iqbal, Deepika Nimmala

Maker Manual

Final Product – watch with full volume

Tools And Supplies

  1. Servo
  2. LEDs (blue x1, red x6)
  3. Micro SD card module & SD card
  4. Mini Speaker
  5. Ultrasonic sensor
  6. Buttons x3
  7. Wood
  8. Cardboard
  9. Cotton balls
  10. Soldering kit
  11. Glue gun

Breadboard Layout Diagrams

Ultrasonic sensor, SD card and speaker breadboard layout
Genie servo motion and LEDs animation

Build Section

Arduino boards:

On one breadboard we built the audio and ‘rubbing’ interactions. First the SD card and mini speaker were wired up to play the noise of the genie ‘waking up’ and then activate the dialogue of the genie. The MP3 player is only activated once the sliding mechanism exposes the ultrasonic sensor. The slider is gently slid back onto the ultrasonic sensor to ensure that the audio does not replay, imitating the rubbing of the lamp. On another breadboard we built the genie mechanism and LED animation to create a magical aesthetic for the lamp. By pressing the on button for the LEDs, the LEDs will light up one by one in a loop of 10 rounds. This animation should be activated first so that it occurs whilst the sound effects are played in the background. Then, pressing the on button for the genie mechanism will allow the servo to spin out of the lamp, turn on the LED and reveal the genie mechanism. This can be left as is during the duration of the scene, then when it is time for the genie to exit the stage, the off button can be pressed to turn the servo back into the lamp, hiding the mechanism.

Making of slider mechanism
Ultrasonic sensor sliding mechanism
Buttons for LED animation and servo

3D High fidelity Prototype

Draw the outline of the lamp shape onto wood then cut this out. Cut out a square base and glue these pieces together using a glue gun, or use pins/screws to attach them together. Place the breadboards inside the lamp firmly, securing it using tape. Cover the gaps and build the side faces of the lamp using cardboard since this is more flexible therefore easier to bend into shape.

Complete Code

Code for LED animation and servo genie mechanism:

#include <Servo.h>
Servo myservo;
int pos= 0;
int ledPin = 11;      // select the pin for the LED

int buttonPin1 = 12;
int buttonPin2 = 13;
int ledPins[] = {2,3,4,5,6,7}; 
int buttonPin3 = 8;


void setup() {
  // put your setup code here, to run once:
myservo.attach(10);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
 
  pinMode(buttonPin3, INPUT);
  //Set each pin connected to an LED to output mode (pulling high (on) or low (off)
 for(int i = 0; i < 6; i++){         //this is a loop and will repeat 6 times
     pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
  }                                   //the code this replaces is below
 
}

void loop() {


  // put your main code here, to run repeatedly:
if(digitalRead(buttonPin1) == LOW){
  Serial.println("button 1 works");
  for(pos = 150; pos>=0; pos-=1){
  myservo.write(pos);
  delay(15);
}
  digitalWrite(ledPin, LOW); // turn LED ON
  delay(100);

}
else if (digitalRead(buttonPin2) == LOW){
    Serial.println("button 2 works");
  for(pos = 0; pos<=150; pos+=1){
    myservo.write(pos);
    delay(15);
  }

  digitalWrite(ledPin, HIGH); // turn LED ON
  delay(100);
}
  else if(digitalRead(buttonPin3)==LOW){
     oneAfterAnotherLoop();  
 //does the same as oneAfterAnotherNoLoop but with 
                             //much less typin
  }

}

 void oneAfterAnotherLoop(){
  int delayTime = 100; //the time (in milliseconds) to pause between LEDs
                       //make smaller for quicker switching and larger for slower
 for(int i = 0; i < 10; i++){  
//Turn Each LED on one after another
  for(int i = 0; i <= 5; i++){
    digitalWrite(ledPins[i], HIGH);  //Turns on LED #i each time this runs i
    delay(delayTime);                
  }                                  
                                     
//Turn Each LED off one after another
  for(int i = 5; i >= 0; i--){  //same as above but rather than starting at 0 and counting up
                                
    digitalWrite(ledPins[i], LOW);  //Turns off LED #i each time this runs i
    delay(delayTime);                
  }                                  
 }                                    
                                     
}

Code for ultrasonic sensor and SD card & mini speaker:

#include "SD.h"          // Include the SD library for working with SD cards
#define SD_ChipSelectPin 10  // Define the chip select pin for the SD card
#include "TMRpcm.h"      // Include the TMRpcm library for playing audio
#include "SPI.h"         // Include the SPI library for communication with SD card

TMRpcm tmrpcm;            // Create an instance of the TMRpcm class

const int trigPin = 5;     // Define the trigger pin for the ultrasonic sensor
const int echoPin = 6;     // Define the echo pin for the ultrasonic sensor

long duration;             // Variable to store the duration of the ultrasonic pulse
int distance;              // Variable to store the calculated distance from the ultrasonic sensor
bool audioPlayed = false;  // Flag to track whether audio has played

void setup() {
  tmrpcm.speakerPin = 9;   // Set the speaker pin for audio output
  pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
  pinMode(echoPin, INPUT);  // Set the echo pin as an input
  Serial.begin(9600);       // Start serial communication with a baud rate of 9600

  if (!SD.begin(SD_ChipSelectPin)) { // Initialize the SD card and check for failure
    Serial.println("SD fail");
    return;
  }
}

void loop() {
  digitalWrite(trigPin, LOW);          // Set the trigger pin to low
  delayMicroseconds(2);                  // Wait for 2 microseconds

  digitalWrite(trigPin, HIGH);         // Generate a 10-microsecond pulse on the trigger pin
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);    // Measure the duration of the pulse on the echo pin
  distance = duration * 0.034 / 2;      // Calculate the distance based on the speed of sound

  Serial.print("Distance: ");
  Serial.println(distance);              // Print the calculated distance to the serial monitor

  if (distance > 160 && !audioPlayed) { // If the distance is greater than 160 and audio has not played
    tmrpcm.setVolume(6);                 // Set the volume for audio playback
    tmrpcm.play("test.wav");             // Play the audio file "test.wav"
    audioPlayed = true;                  // Set the flag to true after playing audio

  } else if (distance <= 5) {            // If the distance is less than or equal to 5
    // Reset flags if distance is continuously under 10
    audioPlayed = false;                 // Reset the audio played flag
    delay(15);                            // Introduce a delay to avoid rapid flag toggling
  }
}

Testing and Shortcomings

As displayed in the design blog below, we conducted testing by running the codes for each component separately to identify any errors before combining the codes together to develop our interactions. This enabled us to understand what each line of code would do and order the functions accurately to initiate interactions in the order we want. A shortcoming that we have faced in this project is the sound of the audio outputted by the mini speaker being too quiet. We researched different ways to amplify the audio but soon realised that this would mean we need to order new components which we did not have enough time for. When we initially tried the ‘rubbing’ effect using a motion sensor, we discovered that it was too sensitive therefore would always stay on. If we correlated the motion sensor to the SD card and speaker in the code, this would mean that the audio plays repeatedly. Therefore, we made the decision to use an ultrasonic sensor instead to activate the audio.

Project Task List

TasksMember(s)
Brainstorming concepts Liyana and Deepika
Coding and WiringDeepika and Liyana
DocumentationLiyana
Creating 3D prototypes + Final productDeepika
Updating the blogLiyana and Emma

Design Blog

13/11/2023 – Brainstorming session:

After confirming that we will be working on the ‘user-interactive theatrical props’ project, we researched and made a list of popular theatre shows where we believed interactive props are essential to the storyline. We developed a list of different theatrical props and shows:
1. Magic Lamp (Aladdin)
2. Rocking chain (Women in Black)
3. Broomstick (Harry Potter)
After a group discussion, we decided that we will move forward with developing the magic lamp because we felt this was a prop where we could showcase the most creativity and include more interaction using a combination of different actuators and sensors. We also planned out what sort of interactions we would want before attempting to code and prototype, this included sketches. 

LINK : https://www.youtube.com/watch?v=GI27mX1BHvk

We took inspiration from this scene in Aladdin, specifically from this clip, extracting the audio between 00:37 – 00:57 seconds in the video. This is the audio that will be saved onto the SD card and played from the speaker.

20/11/2023 – Prototyping Session 1: liyana + deepika

Parts:
+ Servo
+ Speaker
+ Blue LED
+ Buttons x2
+ Crocodile clips x2
+ Resistors x3
+ Wires
For our first prototype, we decided to test out the following interactions using different sensors and actuators:
1. Pressing on and off buttons to activate and deactivate the magic lamp.
2. Spinning a servo back and forth when the buttons are pressed to illustrate the genie escaping the lamp and then returning back inside.
3. An LED turns on when the lamp is activated to symbolise the genie’s escape.
4. Using a speaker to play notes when the lamp is activated and deactivated.
After experimenting with the different components on the breadboard, we made a rough 2D model of the magic lamp to understand the positioning of the servo.

The code:

Notes on the current code:
Currently, we have an on-and-off button that turns a blue LED on and off and also plays music when the LED is turned on. It also turns the servo from 0 – 150 when the on button is pressed and then turns it from 150-0 when the off button is pressed. 
Currently, we have two buttons that make the servo spin from 0 degrees to 150 degrees when one is pressed and then from 150 degrees to 0 degrees when the second button is pressed. As a result of the servo spinning to 150 degrees, the LED will switch on and when the servo spins back to 0 degrees, the LED will switch off. This motion will be used to signify that the magic lamp has been activated, and the genie is exiting the lamp. We have also included two different notes to indicate when the LED turns on and when it turns off. 
Our next steps are to figure out how to replace the buttons with a motion sensor as this will be easier to use when the Arduino is placed inside the magic lamp. A motion sensor will enable our lamp to be more user-interactive because it will replicate the ‘rubbing’ of the magic lamp to awaken the genie. We also need to figure out how to upload and use the interaction without connecting the Arduino board to a computer. Over the next few days, we must make a list of components that we need to order.
Things to order/do:
+ Lipo battery to avoid connecting the Arduino board to the computer (We realised that our interactions will not require a high voltage therefore it’ll be more appropriate to use a power bank and USB.)
+ A motion sensor
+ Small crocodile clips (It will be more efficient to solder the wires to the LEDs rather than use crocodile clips because they are less reliable and connections may be lost.)
+ An SD card 
+ An MP3 player

** Note: Before beginning to code, we researched pre-existing tutorials that demonstrate the wiring and primary code for using a motion sensor and SD card:

https://www.arduino.cc/reference/en/libraries/sd/

27/11/2023- Motion sensor testing:

Before coding, we researched which SD card + mp3 player is most suitable for our project.

Motion sensor attempt code:
When we first attempted the motion sensor interaction, the serial monitor would only print motion detected and not print motion stopped despite us stopping the motion ourselves. We identified that the motion sensor was far too sensitive for our project, and was responding to movement within a 3m radius of the sensor. Our interactions require far less sensitivity, with the sensor responding to motion only within a 10cm radius. Therefore, we decided to replace this sensor with an ultrasonic sensor that would allow us to activate the servo and LEDs to reinforce the activation of the magic lamp. 
New improved code based on the seen results:

29/12/2023 – LOW FIDELITY PROTOTYPE

This small scale 3D model was made to understand how the lamp should look as a prop. This will act as a reference for when we create our final product.

02/12/2023 – WORKING SD CARD CODE: deepika

Code that checks if SD CARD works and shoes what files are on the SD card on the serial monitor

SD CARD AND SPEAKER CODE

Simplified code that reads SD card adapter chip pin, identifies audio test.wav which is the required genie audio and plays it from speaker.

Although the SD card successfully transfers information to the MP3 player which then allows it to play an audio, the audio is quite quiet. We tried to figure out a way to amplify the audio but soon realised that there were too many components requiring more resistance which meant our audio was quieter.

03/12/2023- Combining the SD card and Ultrasonic Sensor

After getting the MP3 player to play the audio on the SD card, we combined the ultrasonic sensor code with the SD card code. This would mean that when the ultrasonic sensor is activated, the audio would play. In practice, this would initiate the sound effects and dialogue of the genie when the lamp is ‘rubbed’ by interacting with the ultrasonic sensor.

04/12/2023 – Separating components & soldering (liyana + deepika)

After adding the SD card and speaker to the breadboard, we decided that wiring all of our components onto just one breadboard was overcrowding it, therefore, we decided to split the code up into 2 breadboards. Today we individually tested out the servo being activated and deactivated by 2 buttons and then 6 LEDs lighting up one after the other to add the aesthetics of the magic lamp.

Serial Output
6 led animation code:
This code runs through an array of LEDs and turns them on one after another in a loop to create an animation that creates the illusion of the magic lamp being activated before the actor of the genie enters the stage. 
After testing the array of LEDs and the servo separately, we then combined both codes into one.
After that, LEDs were soldered to the wires to allow us to position them better in the lamp structure rather than having the LEDs in a row which does not create an exciting animation. If the LEDs are positioned all over the lamp rather than in a row in one area, everyone in the audience will be able to see that the magic lamp is activated, considering the audience is not always seated directly in front of the stage at theatre shows. 
Soldering

08/12/2023- Constructing the Lamp : deepika

Before making a 3D prototype, we sketched out what the lamp should look like and the different elements required in its structure and construction. By creating a 3D prototype using cardboard, we were also able to determine how users could access our interactions, for example, how they could use the ultrasonic sensor without the audience seeing it or without difficulty.

After creating a 3D prototype out of cardboard to understand where to place the 2 breadboards, we decided to create the final product out of a combination of recycled wood and cardboard.

Recycled scrap wood
Final product
Video showing how slider mechanism works – watch with full volume.
Backside of the prop
Genie fluff
Genie mechanism

Front of prop