Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Ghostbusters Trap Simulation with Arduino Mega and Adafruit Modules

View and Edit Project In Cirkit DesignerImage of Ghostbusters Trap Simulation with Arduino Mega and Adafruit Modules

Circuit Documentation

Summary

This circuit is designed to simulate a ghost trap from the movie Ghostbusters. It features a variety of components including servos, LEDs, a bargraph, a haptic motor, a DC motor, and a water pump to create an effect of a ghost being trapped and the trap experiencing an electrical failure. The sequence can be activated by a Bluetooth input or an encoder knob switch, which also controls the volume. The circuit is controlled by an Arduino Mega ADK microcontroller, which interfaces with various modules and actuators to create the desired effects.

Component List

Microcontrollers

Actuators

Power Management

Sensors and Input Devices

Communication Modules

Indicators

Power Regulation

Switches

Protection and Control

Wiring Details

Arduino Mega ADK (Rev3)

Servos

Vibration Motor

5v mini water pump

DC Motor

Speaker

Adafruit PowerBoost 1000C

Rotary Encoder

Adafruit Bluefruit LE UART Friend

Adafruit 16-Channel 12-bit PWM Servo Driver - I2C

Adafruit DRV2605L

Lamp Red

Adafruit Bi-Color 24-Bar Bargraph w/ I2C Backpack

LEDs

ams1117 3.3

Toggle Switch spst

Terminal Blocks

Mosfet

NPN Transistor (EBC)

Diode

Resistors

Documented Code

/*
 * Ghostbusters Trap Simulation
 * This code simulates a ghost trap from the movie Ghostbusters.
 * It controls servos, LEDs, a bargraph, a haptic motor, a DC motor,
 * and a water pump to create an effect of a ghost being trapped
 * and the trap experiencing an electrical failure.
 * The sequence can be activated by a Bluetooth input or the encoder knob switch.
 * The encoder knob also controls the volume.
 */

#include <Adafruit_PWMServoDriver.h>
#include <Adafruit_VS1053.h>
#include <Adafruit_LEDBackpack.h>
#include <Wire.h>
#include <Servo.h>
#include <SoftwareSerial.h>

#define LED_D26 26
#define LED_D27 27
#define LED_D22 22
#define LED_D23 23
#define LED_D25 25
#define SWITCH_PIN 31
#define HAPTIC_PIN 20
#define DC_MOTOR_PIN 29
#define PUMP_PIN 28
#define ENCODER_SW_PIN 48
#define ENCODER_CLK_PIN 49
#define ENCODER_DT_PIN 46
#define BLUETOOTH_RX 18
#define BLUETOOTH_TX 19

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer();
Adafruit_24bargraph bargraph = Adafruit_24bargraph();
Servo leftServo;
Servo rightServo;
SoftwareSerial bluetooth(BLUETOOTH_TX, BLUETOOTH_RX);

volatile int lastEncoded = 0;
volatile long encoderValue = 0;
long lastencoderValue = 0;
int lastMSB = 0;
int lastLSB = 0;

void setup() {
  pinMode(LED_D26, OUTPUT);
  pinMode(LED_D27, OUTPUT);
  pinMode(LED_D22, OUTPUT);
  pinMode(LED_D23, OUTPUT);
  pinMode(LED_D25, OUTPUT);
  pinMode(SWITCH_PIN, INPUT);
  pinMode(HAPTIC_PIN, OUTPUT);
  pinMode(DC_MOTOR_PIN, OUTPUT);
  pinMode(PUMP_PIN, OUTPUT);
  pinMode(ENCODER_SW_PIN, INPUT);
  pinMode(ENCODER_CLK_PIN, INPUT);
  pinMode(ENCODER_DT_PIN, INPUT);

  attachInterrupt(digitalPinToInterrupt(ENCODER_CLK_PIN), updateEncoder, CHANGE);
  attachInterrupt(digitalPinToInterrupt(ENCODER_DT_PIN), updateEncoder, CHANGE);

  pwm.begin();
  pwm.setPWMFreq(60);

  leftServo.attach(0);
  rightServo.attach(4);

  musicPlayer.begin();
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
  musicPlayer.setVolume(20, 20);

  bargraph.begin(0x70);

  bluetooth.begin(9600);

  playSound("turn_on.mp3");
}

void loop() {
  if (digitalRead(SWITCH_PIN) == HIGH || digitalRead(ENCODER_SW_PIN) == HIGH ||
      bluetooth.available()) {
    if (bluetooth.read() == 'A') {
      activateSequence();
    }
  }

  long newEncoderValue = encoderValue / 4;
  if (newEncoderValue != lastencoderValue) {
    int volume = map(newEncoderValue, 0, 1023, 0, 100);
    musicPlayer.setVolume(volume, volume);
    lastencoderValue = newEncoderValue;
  }
}

void playSound(const char *filename) {
  musicPlayer.startPlayingFile(filename);
}

void activateSequence() {
  playSound("Battery_Drained.mp3");
  digitalWrite(LED_D27, HIGH);
  digitalWrite(LED_D