Category Archives: Master Atoms and Bits

Window-Based Smart Home Trigger (With NodeJS/Johnny-Five Integration)

Introduction

This week I wanted to turn the “theoretical hook-in to a smart home system” that I referenced in the conclusion for my last assignment into more of a concrete reality. This included slightly rewiring the breadboard and fully reprogramming the assignment in Javascript. I still haven’t made it all the way to this goal, but this project is a large step in the direction. The three systems used for this assignment were Arduino, NodeJS, and Johnny-Five.

Logos Used


Hardware

The wiring of the previously used circuit was slightly changed to accommodate the required digital output pin in addition to the original digital input pin.  The LED output was added to digital pin 3 and the input continues to be on digital pin 5. The wiring diagram can be found below. The switch continues to be based on copper tape lining a window that is opened or closed.

Arduino Wiring Diagram


Software

Many of the changes for this iteration lie in the software. Instead of using a simple serial log and a hand-wavy gesture towards a ‘smart home system’, this is a more advanced method.

First, the setup process for the system. I started by uploading the ‘StandardFirmataPlus’ code found under File>Examples>Firmata in the Arduino IDE. By uploading this code to the Arduino, I can communicate with the hardware in real time over the serial port rather than uploading C code through the IDE. I then installed the Johnny-Five libraries over command line npm (this step requires NodeJS to already be installed).

npm i johnny-five express socket.io -g --save

Next is the actual programming of the system. The original test program I created shown below was a trial to make sure the system works with the pre-existing wiring and pins. This program blinks the LED when the window is closed.

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  //Pin Declaration
    var led = new five.Led(3);
    var button = new five.Button(5);

  //Main Program
    button.on("down", function() {
      console.log("down");
      led.blink();
    });

});

This code can be directly copied into the app.js file of a NodeJS server, which when combined with a socket.io instance allows direct communication between the server and the hardware. At this point the project is about 2/3 of the way to full internet of things integration.

 

Door Switch

In the first step of my project, I designed the switch by using door. Then, I added this program to enable the door to indicate the number of people in the room. For the first three times of lighting, it is slow and indicates that there are few people get inside. For the later ones, the frequency increases, indicating that there are more people inside the room.

Here is the coding for the program.

Arduino code

Here is the video to test and show how the light works.

This is the door switch!

 

 

Software Driven Switch

I probably struggled the most with this assignment by far. In reflection I need to work on my schematic reading skills, and digital i/o skills.

I began by making the regular button work with the LED. I don’t have any pictures of that but, that itself took me a while. Upon making the circuit for that work, I realized that my LED would stay on until I clicked on the button – which was one of my main issues with this assignment. I later made the switch with the two pieces of metal. Again, the light would turn off when I would touch the two pieces of metal together.

Animated GIF - Find & Share on GIPHY

Thus I began to begin my code – where I struggled with most. I used the template from class for the setup, but I had figure out how to have the light to flash when the circuit was complete.  I had a lot of help from the ITP floor. There were three revisions to the code until I landed on this one. And as you can tell by the title of the code, I was struggling. Arduino Screenshot

The code works. It took a lot of time. But here’s the outcome:

Animated GIF - Find & Share on GIPHY

To apply this to a different body part, I taped one metal piece on the bottom of my shoe and stepped on the other plate. There could be different applications to this, a subway card integrated into your shoe or to alert you if you’re standing to close to an edge. The possibilities are endless.

Animated GIF - Find & Share on GIPHY

Hands Free Switch, Again: A Christmas Story

Diagram

This is my schematic diagram for my conditional switch.

Board

This is my schematic diagram turned into a real life circuit.

Proto 

My hands free switch was a lever made up of cardboard and aluminum foil. When stepped on the switch connects the circuit and the LEDs will light up. A more detailed description can be seen under The Rest of You tag.

code

This was my code for my conditional switch. What this code means is that my LED will be turned on faster than it is off . After a while, the time in between will increase and the light will still turn on quick but will be off for a longer time in-between.

There’s a meaning behind it all. Think of Christmas. Thus, the red and green LED light. On Christmas Day, you are full of excitement, joy, and greed. You can not wait to receive all the gifts you have asked for. You made a list of everything you wanted and gave it to all your relatives. The switch turning on represents the present one receives and is excited to open. This is why the LED lights blink very quickly and sporadically. Then, the gift is open and it turns out that your great aunt has given you a candle. Your excitement fades and your fake appreciation face is in full effect. The LED light slows down and lights up for longer in order to represent your new mood.

Hands Free coffee switch

For this assignment I designed a coffee bottle that has a LED which indicates when the cap is sealed tightly by flashing. I believe this could be useful especially to people like me who tend to spill coffee on themselves frequently. Although at the surface this may not seem hands free you can use your mouth or elbow to open the bottle, which I will demonstrate in my video.

schematic

Here is the schematic of my coffee cap switchcap

I attached my wire to the coffee cap by adding aluminum foil and drilling a hole, similarly I added a hole to the side of the bottle and attached it to the neck of the bottle using aluminum foil as well, these would serve as the two sides of my switch.

setup

The wiring was nearly identical to what I did last time except for the fact that this time I had to program the LED to flash when the connection was made

 

viewcode

My code ^

coffee

Here’s my video

A Step Peddle that Plays a Rhythm

Using the same switch as last time, I was able to create a blinking pattern for when I hit the switch. Now the switch blinks to the tune of “Hot Cross Buns”

 

So, I started with the same switch as shown below

My Spring

Then I plugged it in so that when the piece of copper touched each other, the circuit was complete and the LED lit up.

 

Working Switch #1

Working Switch #2

Here is some of the code that I used to create the sequence. Because the song is so basic, it was easy to make the LED blink to the rhythm of the song by just turning it on and off for each note.

 

Code

 

And here is a video of my final product!

 

Blinking Hands-Free Switch

Code:

void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(7, OUTPUT);
}

void loop() {
// to make the LEDs blink

int state = digitalRead (2);
Serial.println (state);

if (state == 1){
digitalWrite (7, HIGH);
delay(50);
digitalWrite (7, LOW);
delay(50);

}

else {
digitalWrite (7, LOW);
}
}

 

I used my same hands-free switch from the prior assignment, but this time around I had user input incorporated to when the LED blinks rapidly. I had to wire things a bit differently of course, but everything remained the same. First, I connected wires from the 5V and GROUND ports to the breadboard’s positive and negative rails. I used port 2 as INPUT and port 7 as OUTPUT so the LED could shine. I hooked up a wire from port 2 to the breadboard and within that same row I connected a black wire to the negative side of my switch and also placed a resistor on that row connecting the negative rail. As for the LED, I of course used 7 as an OUTPUT and had a resistor side on the same row as the OUTPUT and place the positive side of the LED on the same row as the opposite side of the resistor. The LED’s negative side was on the rail. I also then connected a wire from the positive rail to the positive side of my switch. I got a hairtie and wrapped a copper board onto my shoe. When my foot touches the other copper board, the LED blinks rapidly, but when it doesn’t, the LED is off.

Unlock the Blinking Lights

Adding on to my previous “Unlock the Light” switch, I coded a conditional if statement to control the light of the LED to differentiate between when the door lock is open and when it is closed. When the door lock is open, the LED will be lit. But when the door lock is closed, the LED will blink.

This is the code I used.

Code

void setup(){

pinMode(4,INPUT);
pinMode(2,INPUT);
pinMode(7,OUTPUT);
}

void loop(){

if (digitalRead(4) == HIGH){
digitalWrite(7,HIGH);
delay(1000);
digitalWrite(7,LOW);
delay(1000);
}else{
digitalWrite(2,HIGH);,
}

}

I had originally planned on just having the door lock hit the wire itself to initiate the blinking, but realized it was too unreliable because they wouldn’t always come in contact enough. Luckily, my neighbors had just given us some cupcakes, so I used the cupcake liner to expand the surface area of conductivity by taping it to the wire.

cupcake

n

Now the chance of the metal door lock coming in contact with the wire is much higher. When the door lock hits the tin foil, it causes the LED to blink. I taped it to the back of my laptop because it was the closest stable surface.

This is the finished product!

(The LED is on when the door lock in unlocked. It just wasn’t picking up well on camera.)

Some real world applications for this switch could be to alert someone if they left their fridge open, easily accessible light for if someone wakes up in the middles of the night, or a quiet way to alert the outside if someone is in danger.

 

 

Booty Bumper Upgrade

For my conditional switch project, I incorporated the old switch I made, the booty bumper, and upgraded it! So what I did , is I used a rgb LED and coded it so it would change colors every 4 seconds as long as the circuit was held closed.

^^ This is the code I used to create my conditional switch. Some of the concepts, to get the rgb LED to change colors was taken from the Adafruit website. Specifically, this link: <https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/arduino-sketch>.

^^ This was attempt #1 to test out my code to see if it would change from the colors pink to purple every 2 seconds. It worked, but the colors pink and purple were too similar and the interval of 2 seconds was too short, so I decided to adjust.

So I adjusted the colors to 3 instead of 2, and decided to use red, blue, and yellow. I also changed the time interval to 4 seconds instead of 2.

^^ This is my breadboard setup. I used pins 4, 5, and 6 fro the 3 tongs of my rgb LED.

^^ This is the booty bumper in action!!

^^ This video shows all the components of the booty bumper. As you can see, I reused the idea of soldering on the wires to copper tape to close the circuit and allow the conditional switch to work.

Real World Application:

The Bumper Bumper could be used in the future for hip rehabilitation. For those needing to go to physical therapy for their hips, the Booty Bumper could be used as training to reaching a goal  on a hip mobility scale. The second person in this experiment could be replaced with a bar or inanimate object to create a base for that patient to have to reach with their hips. The goal for the booty bumper upgrade is to reach a mobility where the patient can hold their hips at the bar or other object for four seconds of longer to have the reward of seeing the LED change to a different color.

Special Thanks!!!

@ Sophie for helping me turn my concept into a reality, and helping me wire and code my board for this project to work!!

liquid trigger advance

Comparing with the last version in witch the liquid trigger and light bulb were in series, this time they are separated and the light bulb is controlled by code instead of physical connection.

There’s two challenge I faced making this one. The first one is totally handless. At the end I picked a straw to do that. Another challenge is how to turn off the bulb immediately after the switch is triggered. At the beginning, I was using delay to let the led blink. But that means even if you triggered the switch during the light period, it would not turns into dark immediately due to the delay. In that case, I used millis which would count who long it took already from the beginning. I set a variable which usually are fixed but when the differences between it and millis are over 500, makes it equal to millis and ask the light bulb to switch its status. I used unsigned long instead of int to avoid overflow.

This is the code while testing with normal button. I think it’s actually more complex comparing to the liquid switch one since  int this one the clicking the button change the status. In liquid one, the trigger is the status it self.

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(13,HIGH);
pinMode(7,INPUT);
}
boolean s1=true; //timer
boolean s2=true; //button
unsigned long t1=millis();
void loop() {

while(s2==true) //on status
{
if(millis()-t1>=500) //time reset;
{
s1-=1;
t1=millis();
}
if(s1==true){digitalWrite(13,HIGH);}
else{digitalWrite(13,LOW);}
if(digitalRead(7)==1) //button pressed
{
while(digitalRead(7)==1){} //you can hold button now
s2=false;
digitalWrite(13,LOW);

}
}
while(s2==false) //off status
{
if(digitalRead(7)==1) //button pressed
{
while(digitalRead(7)==1){} //you can hold button now
s2=true;
t1=millis();

}
}
}

liquid one:

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
pinMode(7,INPUT);
}
boolean s1=true; //timer
boolean s2=true; //button
unsigned long t1=millis();
void loop() {

while(digitalRead(7)==1) //on status
{
if(millis()-t1>=500) //time reset;
{
s1-=1;
t1=millis();
}
if(s1==true){digitalWrite(13,HIGH);}
else{digitalWrite(13,LOW);}
}
while(digitalRead(7)==0) //off status
{
digitalWrite(13,LOW);
}
}

testing the input from the trigger001

Stimulating when the liquid is very conductive

002

in water

003

the test

https://youtu.be/Yu9xsA6rqrU

final

https://youtu.be/qsFPrTaDrEE

 

 

A Switch that Raises Eyebrows (in a good way)

I wanted to challenge myself to create a new “no hands” switch so I put my switch design from last week aside. My goal this week to create a switch that I knew could directly serve a meaningful purpose. I began by brainstorming contexts in which a user would need to turn on a blinking LED without their hands.

I realized that those that are paralyzed may want to indicate they need assistance to their nurses but are unable to since they cannot move their hands to press the assistance button that patients typically press. Many patients that are experiencing paralysis can move some of their facial muscles. Thus, I set out to create a switch that a user could turn on by raising their eyebrows.

I attached a copper rectangular piece to one wire (wire A). I then created a cross of two copper strips onto my forehead and attached another wire to my head (wire B). I attached the wire A to my eyebrow. When I raise my eyebrow the copper rectangle attached to the wire A touches the copper “X” on my head, thus, closing the switch and turning on the LED. I coded the LED to flash so that it could get the nurse’s attention. In future iterations of this, I would want to offer the option for the LED to only blink once, so that those with paralysis could communicate with morse code through the LED.

I followed the schematic we used in lab but replaced the button switch we applied with the eyebrows switch I created.

The only struggle that I had was that I did not have medical tape that could secure the wire to my head. I was very warm (embarrassingly enough) and regular tape was not properly securing the output wire down. As a result, I had to hold down the wire with my hand, but the switch itself did not require any hands, this was simply the result of not having medical tape, which has the proper adhesive to stick things to skin.

Here is a video of my switch!

Unfortunately, the faces I make while raising my eyebrows are extremely embarrassing so I did not want to post the video on youtube and as a result, to access the video, you need to download it. I am sorry!

Movie on 9-14-18 at 2.49 PM

 

Here is my code!

image

Humidity Switch v.2

I wanted to make some improvements to the humidity switch so that it was more obvious when the humidity was too low, just right, or too high. I decided to add another light to the circuit, and to specify the colors of the LEDs: green and red. These colors have pretty universal meanings, so I figured that they would be the most practical. In this newer version, the red light blinks to signal to the owner that their pet’s cage is in need of misting, or the humidifier needs to be turned on. When the correct level of humidity is reached (still 80%-90% for now), the red light turns off, and the green light turns on. If the humidity gets too high, the green light turns off again, and the red light turns on. I think this make the switch much easier to understand and use.

Green LED + red LED + DHT11
Updated schematic

Screenshots of the code

I touched a wet tissue to the module this time so that I wouldn’t break the thing again by spraying water into it.

Here’s a short video of the switch doing its thing.

Also, some other stuff that I didn’t put in my first post:

https://github.com/adafruit/DHT-sensor-library (DHT library and tester code)

https://www.instructables.com/id/Arduino-Automatic-Temperature-Humidity-Controller-/ (This guy made something similar but for hamsters and much more elaborate, w/ automated humidifiers and heaters.)

Breathing Exercises

Breathing Exercise

Video Above^

For this week’s assignment, I expanded on my idea from last week with the blow-powered light. As a trumpet player a good exercise involves breathing in as much air as possible and blowing out a constant air flow as long as possible. It helps the lungs warm up if you’re going to play something hard.

Here is a picture of the planning, and code. For this I made sure for that when the coin is blown on, it starts a countdown for 5 seconds (it can be adjusted for however long the user would want), when reaching the goal, the light will blink twice indicating you reached your goal, AKA blowing constant air for 5, 10, etc… seconds straight.

I had to use a new metal, and use adhesive to connect the coin to an extent that would need to be blown on to connect. In a more practical case, a mechanism would need to be made so someone can simply blow onto it and the light would go off. But for the time being this is it’s concept.

(A picture of the entire set-up)

Until next time

-Josh