# The Ghostly Frame

415

5

Posted

## Introduction: The Ghostly Frame

Welcome guys! I am sure that you are reading this with a small plan in your mind to do a prank on somebody. Well that is perfectly all right because I also made it with the same intension (it is a long story). Now you must be asking what this project is all about (well of course it is to scare someone). I use Arduino in this project to light a photo of a ghost when somebody comes close to it. This is an easy project which is best for beginners who are new to the world of Arduino. Please change the photo of the ghost if you find it less scary (I used it to scare a ten year old). Now let us check the thing you will need.

## Step 1: Stuff You Will Need :

• Arduino
• Jumper wires
• leds x 4 (or more)
• Ultrasonic sensor(I'm using HC -SR04, works well !)
• Resistors x 4(330 ohm)

## Step 2: The Connection

Now time to find out where the head goes and where the tail goes. But before going to that you need to know some basic things. First let us find out how an ultrasonic sensor works.

Now I will tell you briefly how an ultrasonic sensor (if it sounds boring please fell free to skip to the next paragraph). the trig pin sends an ultrasonic sound to an obstacle. When the sound hits an objects it reflects the sound back and it falls on the eco pin. A bat also uses the same principle to find its way in the dark. Then the sensor measures the amount of time take for the sounds to come back. then you can convert it into centimeters or inches using the code.

Time for connecting the things. The vcc pin of the ultrasonic sensor is connected to 5v pin in Arduino. The gnd pin of Arduino is connected the gnd pin of Arduino. The trigpin of ultrasonic sensor is connected to digital pin 8 of Arduino and the echo pin to digital pin 7. The positive terminal of the first led is connected to digital pin 2(the order doesn't matter). The second led is connected to digital pin 2. The third led is connected to digital pin 5. The fourth led is connected to digital pin 3. And also remember to connect 330 ohm resistors in between the leds. See the diagram for further details. Now for the framework.

## Step 3: The Framework

Now we need to build the frame. For that you will need a cardboard box in the size of your photo(or bigger). If you don't find a box of your need size just make a box using some cardboard and glue. Also make sure the color of your box is a dark color (because dark colors cant be seen at dark, so nobody will notice the box). Now follow the steps.

STEP 2: Cut a hole in your box in the required size.(picture 1)

STEP 3:Cut another hole in the back of the box, this will help you to do your works easily.

STEP 4:Cut one more hole for the ultrasonic sensor.(picture 1)

STEP 5: Attach your leds to the four corners of your box. Make sure the leds are pointed to the photo(picture 2).

STEP 6 Paste your photo in front of the hole.

STEP 7: Cut another small hole for the power cable of the Arduino to pass through(if you are using a battery you don't need this)(picture 5).

Now you need the Arduino to do the job of lighting the photo, right ? So on to the code.

## Step 4: The Scary Code

Please don't misunderstand the title (I gave it to make the title a little more interesting). The code is not at all hard. Now you need to know what the code does. The code says that when an object comes in front (less than or equal to 30 cm) of the ultrasonic sensor, the leds inside the frame should light up thus lighting the photo. Now read the code.

int trigpin = 8;
int ecopin = 7;

int ledpin1 = 2;

int ledpin2 = 4;

int ledpin3 = 5;

int ledpin4 = 3;

int distance, duration;

void setup() {

// put your setup code here, to run once:

pinMode(ledpin1, OUTPUT);

pinMode(ledpin2, OUTPUT);

pinMode(ledpin3, OUTPUT);

pinMode(ledpin4, OUTPUT);

pinMode(trigpin, OUTPUT);

pinMode(ecopin, INPUT);

}

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(trigpin, LOW);

delayMicroseconds(2000);

digitalWrite(trigpin, HIGH);

delayMicroseconds(15);

digitalWrite(trigpin, LOW);

delayMicroseconds(10);

duration = pulseIn(ecopin, HIGH);

distance = (duration/2)/29.1;

if (distance <=30)

{

digitalWrite(ledpin1, HIGH);

digitalWrite(ledpin2, HIGH);

digitalWrite(ledpin3, HIGH);

digitalWrite(ledpin4, HIGH);

}

else

{

digitalWrite(ledpin1, LOW);

digitalWrite(ledpin2, LOW);

digitalWrite(ledpin3, LOW);

digitalWrite(ledpin4, LOW);

}

}

So that is for the code. Just upload it into your arduino and it is done. Then wire all the things up and place it in a dark room and poof ! You have just made a ghostly frame. And also it would be better if you power your arduino with a battery or a AC to DC adapter after uploading to the arduino because you do not want a message like "Hey, Joshua you have one new notification" to pop up from the computer while you are trying to scare someone. So best of luck making this instructable. Please do vote if you like it !

## Recommendations

• ### Arduino Class

68,903 Enrolled

• ### Microcontroller Contest

We have a be nice policy.