Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Technovation
Published © GPL3+

Arduino Darkness Activated Ghost

Ever wondered if you could build a device to scare your friends? Well here you have transform your room into a haunted house.

AdvancedFull instructions provided2 hours6,837

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V Battery Clip
9V Battery Clip
×1
RobotGeek Light Sensor
RobotGeek Light Sensor
We used a photo resistor, also know as a LDR ( Light Dependent Resistor ), i would recommend this as its cheaper and serves the purpose.
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
circuito.io
circuito.io

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

circuitio schematics

Code

arduino_scare_pank.ino

C/C++
Now upload the code onto the system. Basically the program goes as per the light intensity if it is dark the ghost audio clip starts playing, and if the light turns on it stops.
#include <Servo.h>
Servo servo1;
Servo servo2;
int pos1 = 0;
int pos2 = 0;

int ldr = A0;
int sensor_value = 0;
int thresh = 150;
bool state = false;

void play(){
   for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
   while(true);
}

void next_clip(){
   for (pos2 = 0; pos2 <= 180; pos2 += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos2 = 180; pos2 >= 0; pos2 -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
   while(true);
}

void setup() {
  // put your setup code here, to run once:
servo1.attach(7);
servo2.attach(8);
Serial.begin(9600);     //for debugging only

}

void loop() {
  // put your main code here, to run repeatedly:
sensor_value = analogRead(ldr);

//the moment lights go off the first clip starts to play
if (sensor_value < thresh){
  play();
  state = true;
  
}

//once the victim is scared and tries to turn on the lights. play next clip
else if(sensor_value > thresh && state == true){
  next_clip();
  play();
  state = false;
}

//do nothing
}

Credits

Technovation

Technovation

7 projects • 92 followers
We are two young inventors, Kousheek and Satya .We like making robots and tech related things. Our projects focus on simplicity utility.

Comments