Star Trek Doorbell
I am, to many of my friend's dismay, a massive Star Trek fan, and after my 78 slide final project on the history of Star Trek that I submitted to my AP World History teacher, I decided that this year I am going to incorporate Star Trek into as many class assignments as possible. At the time of writing this, this will be number four. Disappointing I know. :( For this project I was tasked with making a home automation system, so with this goal in mind I decided to create a doorbell for my bedroom door inspired by various Star Trek bridges.
Downloads
Supplies
There are a few things you are going to need before you can start this project.
- A Particle Argon
- A breadboard (The one that comes with the Argon works fine)
- An LED strip, preferably cut to an even number of pixels
- An ultrasonic sensor, The model I used is the HC-SR04.
- A hall sensor
- A small magnet
- A phone
- You will need to download the PushCut app.
- A soldering iron
- Solder
- Wire
- Wire strippers
- An assortment of jump wires
Preparation
Aside from re-watching your favorite episodes of Star Trek or sobbing over the fact that Star Trek Strange New Worlds season two doesn't have a release date yet, The first thing you should do is make sure all of your programs are ready for use.
- Download PushCut
PushCut is free on the Apple AppStore and is what I used to trigger notifications on my phone. It can be ised with IFTTT and Apple Shortcuts if you want to get fancy with your notifications. pushcut.io has a full list of what PushCut is capable of and some tutorials for each of them.
- Including The Appropriate Libraries
There are two libraries you will need to include in your new app for the code to run properly. There are :
- neopixel
- HC_SR04
Note! There are two libraries for the HC-SR04 ultrasonic sensor. One is HC-SR04 and HC_SR04. HC-SR04 (dash no underscore) does not work. Make sure you select HC_SR04. (Underscore no dash)
Creating PushcCut Notifications
I found that PushCut notifications were pretty intuitive, so I had a bit of fun with them. One of my goals when starting this project was to have Majel Barrett announce everything to me as the computer voice like she did in the show, but my main problem was how I was going to achieve that. Thankfully I am not the only, mildly insane, Star Trek fan out there and TrekCore Has a library of virtually every sound in the Star Trek universe. I used Intruder Alert Deck 8, but edited the end, and Alert 09 for my notifications. Above is an example of how I laid out one of my notifications.
Webhooks
Particle has an integrated webhook function and PushCut provides a webhook like for every notification you create, making this process easy. The webhook like is going to be found in the PushCut notification maker, third section from the top.
I have included a screenshot if my particle webhook that I made on the Particle Console. The only text fields you need to edit are the name and the URL fields.
Note! My webhooks are named RedAlert and YellowAlert and the code I have written is made for those names. If you change your webhook names you will have to change it in the code. I have marked where you will need to do so.
Code
This is the code that I made for this project. The only thing you would need to change is the number of pixels you are using for your LED strip, I used 14, but a different size strip might fit better in your space, and the webhook names if you changed them.
int hallSensor = 3;
//Ultrasonic Sensor
#include <HC_SR04.h>
int trigPin = 5;
int echoPin = 4;
HC_SR04 sensor = HC_SR04(trigPin, echoPin);
//Libraries for LED
#include <neopixel.h>
#define PIXEL_COUNT 14 //Change number of pixels here :)
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
SYSTEM_MODE(AUTOMATIC);
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int numAlertRed = 0;
int numAlertYellow = 0;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
strip.begin();
pinMode(hallSensor, INPUT_PULLUP);
}
void loop()
{
int hallState = digitalRead(hallSensor);
digitalWrite(trigPin, LOW);
delay(2);
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
for(int i = 0; i < strip.numPixels()/2; i++)
{
Check();
if(hallState == HIGH)
{
RedAlert();
delay(1000);
numAlertRed ++;
}
if(hallState == LOW)
{
strip.setPixelColor(i, 255, 255, 255);
strip.setPixelColor(strip.numPixels() - i-1, 255, 255, 255);
strip.show();
delay(70);
numAlertRed = 0;
numAlertYellow = 0;
}
for(int i = 0; i < strip.numPixels()/2; i++)
{
strip.clear();
strip.show();
}
}
}
void Check()
{
int distance = sensor.getDistanceInch();
if(distance == 4 || distance == 3 || distance == 31 || distance == 32 || distance == 30 || distance == 29 || distance == 28 )
{
YellowAlert();
numAlertYellow ++;
}
}
void RedAlert()
{
if (numAlertRed == 0)
{
Particle.publish("RedAlert"); //change what is inside the quotes if your webhoot is named
//something different
}
for(int i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, 255, 0, 0);
//delay(200);
}
strip.show();
int hallState = digitalRead(hallSensor);
}
void YellowAlert()
{
if (numAlertYellow == 0)
{
Particle.publish("YellowAlert"); //change what is inside the quotes if your webhoot is named
//something different
}
for(int i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, 250, 239, 32);
}
strip.show();
delay(1000);
}
A really good tutorial that I used to write the code for the ultrasonic sensor is from How To Mechatronics. (They also have a really nice YouTube video).
Wiring
I made some schematics for the wiring process, but the software I used doesn't have an Argon or a Hall sensor, but the connections I made with the Arduino and on the PIR sensor correspond exactly with what you should connect on your Argon and hall sensor respectively. I used jump wires for everything except the LED Strip.
You will need to solder wire to the LED strip. I used solid core to make the connections easier in the breadboard. I learnt soldering in class, but there are many great soldering resources available on YouTube and beyond.
Attaching It to Your Door
This part happened to be the hardest part for me. The breadboard does come with adhesive on the back, but because I didn't want to *cough* wasn't allowed to *cough* make any permanent changes to my home I needed to figure out how to stick it to the wall. Command Strips and double sided tape didn't stick to the back of the breadboard because of the slick protective coating on the back on top of the adhesive, so I had to resort to bright orange masking tape. I hope if you are planing to add this to your home it is more permanent, and therefor much nicer to look at. Everything else, the hall sensor, magnet, LEDs, and ultrasonic sensor weren't that hard to attach. A mixture of tape and command strips has kept it stable for the past few weeks.
Done!
I sincerely hope that anyone who makes this in the future has had fun with it. Is it my best work? No, and I will probably continue to mess with it after I upload this tutorial, but it (temporarily) satisfied my urge to create as many Star Trek related projects as I can.
Happy Crafting!