Evan Rust
Published © GPL3+

Pranked! Moving Tissue Box | Circuito.io

When someone goes for a quick facial tissue, the box moves away unexpectedly!

BeginnerFull instructions provided2 hours11,272

Things used in this project

Hardware components

Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
DC motor (generic)
×2
Wheel
I used a Lego one
×2
Arduino UNO
Arduino UNO
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Facial Tissue Box
×1

Software apps and online services

Arduino IDE
Arduino IDE
circuito.io
circuito.io

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Knife
For cutting the box

Story

Read more

Schematics

Schematic

Just attach as-is. You could also use circuito.io's wiring walk-through as well.

Code

Arduino Code

C/C++
Copy and paste it into the Arduino IDE and upload it.
#define THRESH 4 //How many inches away their hand must be to activate it
const int FL = 2; //Pin numbers + corresponding directions
const int BL = 3; 
const int FR = 4; 
const int BR = 5; 
const int trig_pin = 6; //HC-SR04 pins
const int echo_pin = 7; 
bool dir_flag = false; //If going forwards or backwards (It alternates)
long duration = 0; 
void setup() { 
 // put your setup code here, to run once: 
pinMode(FL,OUTPUT); //Initialize pins
pinMode(BL,OUTPUT); 
pinMode(FR,OUTPUT); 
pinMode(BR,OUTPUT); 
pinMode(trig_pin,OUTPUT); 
pinMode(echo_pin,INPUT); 
digitalWrite(FL,LOW); 
digitalWrite(BL,LOW); 
digitalWrite(FR,LOW); 
digitalWrite(BR,LOW); 
forwards(250); //Give a "ready" signal
delay(3000); 
backwards(250); 
delay(3000); 
} 
void loop() { 
 // put your main code here, to run repeatedly: 
long distance = Ping(); //Check distance
long lengths = microsecondstoinches(distance); //Convert from duration to inches
if(lengths < THRESH){ //Check if hand in range
 if(!dir_flag){ //If dir_flag is false, go forwards
   forwards(3000); 
   dir_flag = !dir_flag; //Set it to go backwards next
 } 
 else if(dir_flag){ //If dir_flag is true, go backwards
   backwards(3000); 
   dir_flag = !dir_flag; //Set it to go forwards next
 } 
 delay(2000); //Give it a 2 sec buffer time if triggered
 } 
 delay(10); //10 ms debounce
} 
void allOff(){ //Stop moving
 digitalWrite(FL,LOW); 
digitalWrite(BL,LOW); 
digitalWrite(FR,LOW); 
digitalWrite(BR,LOW); 
} 
void forwards(int duration){ //Go forwards
 digitalWrite(FL,HIGH); 
 digitalWrite(BL,LOW); 
 digitalWrite(FR,HIGH); 
 digitalWrite(BR,LOW); 
 delay(duration); 
 allOff(); 
} 
void backwards(int duration){ //Go backwards
 digitalWrite(FL,LOW); 
digitalWrite(BL,HIGH); 
digitalWrite(FR,LOW); 
digitalWrite(BR,HIGH); 
delay(duration); 
allOff(); 
} 
long Ping(){ //Send out a pulse and record the time it takes to come back
 digitalWrite(trig_pin,LOW); 
 delayMicroseconds(2); 
 digitalWrite(trig_pin,HIGH); 
 delayMicroseconds(5); 
 digitalWrite(trig_pin,LOW); 
 duration = pulseIn(echo_pin,HIGH); 
 return duration; 
} 
long microsecondstoinches(long microseconds){ //Convert duration to inches
 return microseconds / 74 / 2; 
} 

Credits

Evan Rust

Evan Rust

122 projects • 1087 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments