Project Title and Description

The Trick or Treat Box

The Trick or Treat Box is a fun and interactive way to take trick-or-treating to the next level!

The Trick or Treat Box is used for collecting candy from houses in the neighborhood on Halloween as a trick-or-treater. Rather than carrying around a pillowcase to hold all your candy, the Trick or Treat Box senses when anyone tries to put candy in your box, and immediately opens itself up with a Servo motor, revealing an opening to allow someone to put the candy inside. The Trick or Treat Box’s red eyes, made of 10 millimeter LEDs, also light up when it feels (through an ultrasonic sensor) that someone is reaching over it to give it candy, since it is so excited to receive more! Upon receiving a piece of candy, the Trick or Treat Box will immediately close itself back up and its lights turn off, since it now is protecting the candy it received.

IMG_3715.jpg

Circuit Diagram

Screen Shot 2022-10-14 at 4.28.25 PM.png

Arduino Code

#include <Servo.h>
#define trigPin 3 
#define echoPin 2 
#define low_led 11
#define high_led 11

int redPin = 11;
int redPin2 = 10;
Servo servo;
int sound = 250;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(4); // Digital PIN 4 of nano
servo.write(0);
pinMode(redPin, OUTPUT); 
pinMode(redPin2, OUTPUT);
}
void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 10) {
  Serial.println("the distance is less than 5");
  servo.write(90);
  delay(100);
  //led code
  digitalWrite(redPin, HIGH);
  digitalWrite(redPin2, HIGH);
  delay(1000);
  digitalWrite(redPin, LOW);
  digitalWrite(redPin2, LOW);
  servo.write(0);
}
if (distance > 60 || distance <= 0){
Serial.println("The distance is more than 60");
Serial.println ("Nobody Is Infront Of the Sensor");
}
else {
Serial.print(distance);
Serial.println(" cm");
Serial.println ("Someone Is Infront Of the Sensor");
}
delay(500);
}

Process

Originally, we started by using this larger version of the Servo motor. The motor worked properly when triggered by the Ultrasonic sensor, but was a bit too bulky for what we needed. An arm and cover for the hole were made to be attached to the motor.

Screen Shot 2022-10-14 at 4.41.43 PM.png

However, the gap between the hole and and its holder was too large. You can see it in the video below:

IMG_3389.MOV

The black motor was too big, so we switched it out for a smaller Servo motor, which fit much better. Unfortunately, shop did not have one that is why I had to borrow it from one of the ITP graduate students. Shoutout to her hehe 🙂 ðŸ’˜

Screen Shot 2022-10-14 at 4.57.36 PM.png

Then we added 10 mm LEDs to the Arduino code and to the circuit.

IMG_3474 2.mov

Happy moments / Challenges

Throughout the assembly process of the circuit, we kept facing an issue where the Arduino code would not upload because it said the port was not connected, even though it was. We found that this problem would occur when we tried adding a speaker- the speaker worked itself, but would not work when connected to the other components. We think there was just too much going on within one circuit, so after a lot of frustration and attempts at rigging it differently, we decided the sensor, LEDs, and servo were enough.