Category Archives: System

Summary

For this project I created an interactive map of my travel in New York City since I’ve arrived here. It uses location data taken from my phone that can be scrubbed through using a potentiometer.

Screenshot of Webpage


Programming

For the code I set out to challenge myself and overcome the wall I hit during one of our first projects when I was not able to set up and use the NodeJS server in conjuction with Johnny-Five to receive Arduino serial communications.

Logistically, this program has a local server sync data from the potentiometer in nearly real time, which updates a variable within the looping app.js server file. Every 50 milliseconds the client-side script.js file sends an AJAX GET request back to the server at [server address]/data, to which it receives a 1-element array of the last seen potentiometer value. This format can easily be expanded to include any sort of sensor readings from the Arduino. It needs to be in either an array or object form, as integers, floats, and the like are not able to be sent by the server. Once script.js gets the data, it loops through all days since the beginning of the data adding a transparent SVG for each day with that day’s location tracking data. It also then calculates where the bottom bar should be indicated and what date that would correspond to.

Full hardware setup

//Library requests and declarations
  var express = require('express');
  var path = require('path');
  var app = express();

//Open public directory to client side access
  app.use(express.static(__dirname + '/public'));

//GET request for index
  app.get('/', function(req, res){
    //Sends 'index.html' file in response
      res.sendFile('views/index.html', {root: __dirname });
  });

//GET request for Arduino data
  app.get('/data', function(req, res){
    //Sends potentiometer data in array
    //Can't send int,float,etc. Only string, obj, and array
      res.send([potentiometer.value]);
  });

//Declare Johnny-Five board
  var five = require("johnny-five"), board, potentiometer;
//Set new board
  board = new five.Board();
//When board is ready
  board.on("ready", function() {
    // Create a new `potentiometer` hardware instance.
      potentiometer = new five.Sensor({pin: "A2",freq: 250});
  });

app.listen(3000);
var months = ["Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec"];
var date;
var url;
var val;

$(document).ready(function(){
  window.setInterval(function(){
      //Send GET request to local server
        $.get('http://127.0.0.1:3000/data', {}, function(data){
          //Value received in 1-element array
          //Isolate data, map it from 0 to 686 range to 0 to 49 range
          //Round data down and convert it to integer for future calculations
            val =  Math.trunc(Math.floor(data[0]*(49/686)));
        }
      //Update background color on slider bar
        $("#dayRange").css('background-image',
                    '-webkit-gradient(linear, left top, right top, '
                    + 'color-stop(' + val/49 + ', #692DAA), '
                    + 'color-stop(' + val/49 + ', #C5C5C5)'
                    + ')'
                    );
    //Reset previous days
      $(".dayTravel").remove();
    //Loop through previous days
      for(i=0;i<=val+1;i++){
        //Reset base date to start of slider-1
          date = new Date(2018, 8, 13);
        //Set date to currently calculated date
          date.setDate(date.getDate() + parseInt(i));
        //Calculate new url for image
          url = (date.getFullYear()+"").substring(2)+"-"+(date.getMonth()+1)+"-"+date.getDate();
        //Append image to body
          $("body").append("<img src='days/" + url + ".png' class='dayTravel i"+i+"' id='" + url + "'>");
      }

    //Calculate and apply slider label movement
      let revisedVal = ((val/49)*(document.body.clientWidth/1.7))+(document.body.clientWidth*(18/100));
      $(".sliderAfter").css({"left":revisedVal});
    //Calculate and apply slider label text
      let revisedText = months[date.getMonth()]+" "+date.getDate();
      $(".sliderAfter").html(revisedText);

  }, 50);//End on input change
});//End on document ready
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>P5 Homework</title>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="http://nyu.ethanprintz.com/projects/script.js"></script>

  <link rel="stylesheet" href="http://nyu.ethanprintz.com/projects/style2.css">
</head>
<body>
  <div class="sliderSide sliderBefore">Sep 14</div>
  <div class="slideContainer">
    <input class="slider" id="dayRange" type="range" min="1" max="49" value="1">
  </div>
  <div class="sliderSide sliderAfter">Sep 14</div>
</body>
</html>

After hours of debugging and documentation checking, it finally all works! It’s a bit of a simple project outwardly, but inwardly the backbone created for this one can be very easily copied and ported to future projects, which opens up more possibilities for my final project.

GIF of project working

Emotion Detector

Based on the door switch, I wish to design a system that can detect people’s emotion when they open the door, by detecting the pressure on the wall when door hits the wall.

I’m sorry, I can’t insert my photos here….

 

Here is the final video. But, without a pressure sensor, I replace it with an analog.

Musical LED

To create something expressive, at first, I attempted to create something with a potentiometer. I was going to have it so that when it hit a certain frequency the LED would flash the tune of twinkle, twinkle which is a fun song that I really like because it was the first song I learned how to play on the cello.

 

Here is the soldering I did for the potentiometer:

soldering

I plugged in everything but I realized I could not get the potentiometer to work so I decided to scrap that idea and try with a button

 

Here are some of the wirings I tried with the button:

Wiring 1

Wiring 2

I’m not sure what went wrong because I tried a lot of troubleshooting but I could not get the LED to flash when I wanted it to. I was able to wire it so that the window showed me when I was pressing the button and display me changing the potentiometer. I’m still trying to see what I need to fix but here is the code that I implemented.

Code

Mr. Coffee (Kinda)

The dream was that I would hook up that coffee maker in the junk shelf to my Arduino. I wanted to make it so that the coffee maker would make either more or less coffee depending on someone’s energy level.  The energy level would be determined by the bend in a person’s neck, measured by a flex sensor. For the expressivity aspect, I also wanted to give this system a bit of personality, so I added an LCD display that said “I’m Mr. Coffee!” and displayed the “status” of the user. The whole idea didn’t quite convert to reality, for a couple reasons.

First off, I couldn’t get my hands on a PowerSwitch Tail over the weekend for the life of me. The coffee maker is still sitting in my locker, waiting for a PSSR, but for now, I’ve substituted it with a test LED.

jkldsajkl
Setup

Hgfhgfh

Second, all the tape in the world couldn’t secure the flex sensor to the back of my neck, so here’s me trying to give the effect of how it would work:

Kjrljskljdklgd
(Note: This started getting a little glitchy as the hours wore on, so the dimming/brightening wasn’t as smooth.)

I’ll be the first to say that this was kind of a failure. Except for the LCD display, which was my one good idea that worked out. Still, I stand by the Mr. Coffee concept, and I still think it’s feasible with more time.

Anyway, here’s the code and schematic. I’m hoping that I can return to this at one point, because that coffee maker calls to me.

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int flexPin = analogRead(A0);
int mrCoffee = 9;
int value;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("I'm Mr. Coffee!");
  pinMode(9, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0, 1);
  value = analogRead(flexPin);
  value = map(value, 700, 900, 0, 255);
  analogWrite(9, 0-value);

  if (value > 0 & value < 30)
  {
    lcd.print("status:thriving!");
    return;
  }
  if (value > 20b & value < 40)
  {
    lcd.print("status:alive-ish");
    return;
  }
  if (value > 40 & value < 60)
  {
    lcd.print("status:ughhhhhhh");
    return;
  }
  if (value > 60 & value < 80)
  {
    lcd.print("status:zzzz.....");
    return;
  }


}

Jkdsjnlkfd

And sources that I used:

https://www.arduino.cc/en/Tutorial/HelloWorld

https://www.instructables.com/id/How-to-use-a-Flex-Sensor-Arduino-Tutorial/

Lazy people’s led

My purpose is to make the led light up when the surroundings get dark so that people don’t need to turn on the lights themselves.

Video of the result–>  Lazy people’s led

And here is the code.

code

I classify the value of sensorReading as 5 levels of brightness in order to tell the Arduino that it should turn on the light when the brightness detected by the photocell is at, or lower than, level 3(which is a little bit dark but not completely dark).

 

Heal the Bay Patch

I made a wearable technology product that is a patch with blinking LEDs. To make this, I used an Arduino Lilypad, felt fabric, LEDs, and conductive thread. I decided to make a patch dedicated for a cause. In this case, I made it for the nonprofit organization “Heal the Bay.”

CODE:

// set pin numbers:
const int switch1 = 9; // the number of the switch pin
const int ledPin = 10; // the number of the LED pin
const int ledPin2 = 11;
const int fastBlink = 30;
const int slowBlink = 500;

// variables will change:
int switchState = 0; // variable for reading the switch status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);

// initialize the pushbutton pin as an input:
pinMode(switch1, INPUT_PULLUP);

// start the serial monitor
Serial.begin(9600);
}

void loop() {
// read the state of the switch value:
switchState = digitalRead(switch1);

// print it to the serial monitor
Serial.println(switchState);

// check if the switch is pressed.
// if it is, the switchState is HIGH:
if (switchState == HIGH) {

// blink the first LED
digitalWrite(ledPin, HIGH);
delay(fastBlink);
digitalWrite(ledPin, LOW);
delay(fastBlink);

digitalWrite(ledPin2, HIGH);
delay(fastBlink);
digitalWrite(ledPin2, LOW);
delay(fastBlink);

}
else {

// blink the second LED
digitalWrite(ledPin2, HIGH);
delay(slowBlink); //
digitalWrite(ledPin2, LOW);
delay(slowBlink);

digitalWrite(ledPin, HIGH);
delay(slowBlink); //
digitalWrite(ledPin, LOW);
delay(slowBlink);

}
}

 

Sound Indicator

Initially, I wanted to make a car-stereo-like knob that turned up the value of a static synth. But yet again, my skill lacked. I settled for a sound detector. This can be used to for deaf people and can flash a light for when someone is talking to them (by mistake and they’re turned around). It can be tied to a certain frequency so that it only picks up the most common range of frequencies that vocal chords produce. For example, a deaf person forgets something in their uber and leaves and the driver yells from behind them to tell them they forgot their, let’s say, jacket. The deaf person will get alerted. My model simple turns on when light is inputed. Details below.

code

Happy Holidays!

In honor of Saturday being the first day of fall, I felt it was only appropriate to start getting in the holiday spirit. For my project, I created a “piano” that would play 5 notes: C, D, E, F, G. I only had five buttons to make this and luckily “Jingle Bells” only requires 5 notes. Coincidence? I think not.

Components: Arduino UNO R3, jumper wires, buzzer, breadboard, 300 ohm resistor

I first drew a schematic to plan out the piano.

schematic

Then I coded the board. I used google to find out the frequencies of the five keys. I had originally used the if else statement, but changed it to the for loop after finding online that it solved problems similar to mine. The if else statements would sometimes interfere with each other causing only certain keys to work.

j

a

Explanation of Code:

I used #define to set my variables (keyC, keyD, keyE, keyF, keyG) equal to their corresponding frequencies in Hertz (523, 587, 659, 698, 784). Next, I defined the music notes (C, D, E, F, G) I used as my integers and set them equal to their corresponding pin (2, 4, 6, 7, 9). Pin 11 was connected to a buzzer with a 300 Ohm resistor. I also set my integer duration to 150 milliseconds to give the sound enough time to be heard, but not too long as to be slowing down the natural rhythm of the song.

Under void setup, I chose input_pullup instead of input so I wouldn’t have a floating voltage without connecting the pin to an external circuit.

Under void loop, I gave each key an if statement, for loop, and tone. The code is boolean so 0 = off/no and 1 = on/yes. The if statement states that “if the (key) is off….” Then the for loop is activated. The for loop is defined as for(statement,question,reaction). In my code, it states that a key is off. It answers yes or no to the question “Is the key still off?” If the answer is no, the loop repeats. If the answer is yes, then the tone is activated. Tone is defined as tone(pin number of the item that is playing the sound, frequency in hertz, duration).

In short, this is the basic logic that’s followed:

The button is not pressed. If the button is not pressed, the code will keep checking if it is pressed. If it is pressed, the tone will be activated.

Here’s the result!

This is the music I used for “Jingle Bells.”

music

Other than just having the Arduino play sounds, I had two other ideas. I wanted to add green and red LED lights to correspond when a key was pressed, but could only get for either the sound to come out when the button was pressed or for the LED to light up when the button was pressed. Whenever I combined the codes, it would cause the later codes not to work or none of them would work at all. I am still trying to figure out the correct sequence for setting up this code. Another idea was to use the LCD to have the tell the player the next key (C,D,E,F,G) in the song. Sadly, my Arduino refused to recognize the Liquid Crystal library.

Some websites that really helped me were:

https://programmingelectronics.com

https://create.arduino.cc

https://instructables.com

 

Expressivity System

This is my schematic diagram for my circuit.

diagram

I wanted to create a circuit that communicated the excitement of a marriage proposal. I used a red LED, which represents love and passion. I wanted the LED to fade as it blinked on and off to show the  fluttering feeling of love and to make the subject aware of the button they are able to push. When the button is pushed, the pulsating stops. This shows how everything in the moment stops when such a situation as a marriage proposal happens. Then, the program makes the out the phrase “MARRY ME!” on the monitor. Right after it finishes typing, the LED light begins to blink very fast to demonstrate the joy and excitement.

This is the code I used :

int reading;
int previousReading = 0;
int button = 2;
int ledPin = 7;
int brightness= 0;
int fadeAmount =2000;

void setup() {
Serial.begin(9600);
pinMode(button, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {

analogWrite(ledPin, brightness);
brightness = brightness +fadeAmount;

if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;

delay (1000);
}

reading = digitalRead(button);
if (reading == 1){
{

}

Serial.print(“M”);
delay(500);
Serial.print(“A”);
delay(500);
Serial.print(“R”);
delay(500);
Serial.print(“R”);
delay(500);
Serial.print(“Y”);
delay(500);
Serial.print(” “);
delay(100);
Serial.print(“M”);
delay(500);
Serial.print(“E”);
delay(500);
Serial.println(“!”);

digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(300);
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(85);
digitalWrite(ledPin, HIGH);
delay(75);
digitalWrite(ledPin, LOW);
delay(75);
digitalWrite(ledPin, HIGH);
delay(75);
digitalWrite(ledPin, LOW);
delay(75);
digitalWrite(ledPin, HIGH);
delay(75);
digitalWrite(ledPin, LOW);
delay(75);
digitalWrite(ledPin, HIGH);
delay(75);
digitalWrite(ledPin, LOW);
delay(50);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
} }

Here is a video:

 

Indicator for Your Friends who just can’t stop tapping their legs

I dont know about you, but I hate it when my friends cant calm down, and keep tapping their foot. It makes me anxious and makes me start tapping my foot.

Merge Records Lionheart GIF by H.C. McEntire - Find & Share on GIPHY

And most of the time these people don’t notice what they are doing. So I decided to make an indicator to tell them to stop.

This is how it was going to work

sketch

There was going to be one side of the switch underneath my sneaker and the other side on a pad.  And the code was basically going to say if the counter is greater than 40 in 30 seconds the led turns on.

code

Above is the code with just the counter sketch and no time.

code code

Above is code with time.

The code basically says if the switch is pressed more than 5 times in 2 seconds, then the led turns on.

Animated GIF - Find & Share on GIPHY

Then I tried to make the pad where the tapping was going to take place.

ml

But the shop didn’t have copper tape so I improvised and used my laces.

jo

But it didn’t work.

Animated GIF - Find & Share on GIPHY

Because my aluminium foil and gaffer tape just wasn’t cutting it. But the basic idea is there so when I have the right resources I’ll properly make the pad.

electronic piano

I want to make a piano with only three keys, once I press the button(switch), there will be different voices.

123qewe

qweqew

Here is the coding part. I looked up some references and change some essential data to make it work. However, the forth key doesn’t work whatever I change the data…

qwewqwe

I want to add some LED light, and let them light up while I am pressing the buttons. However only one of the LED lights up, and some of them even makes a short circuit. I try to figure out why the forth key doesn’t work, I think this was probably because the power is not enough, since I can make the forth sound by changing the data for the third button.

video20180923_180215~2

I tried to have a disco but I failed

I began this week’s assignment with a vision to create a disco ball. My plan was to attach a RGB LED to a light sensor and when it would be dark (the light sensor would be covered), the RGB Led would light up and change colors, alternating between green, red, and blue.

I began by first creating a system in which a regular LED would turn on when it is dark (or when the light sensor is covered). With help from sources online, specifically https://www.instructables.com/id/Arduino-LDR-With-LED/, I was able to create the required code.

I was fortunately successful in developing this simple dark activated LED. Here is a video of my LED working!

(Just realized how terrible this documentation is and I have learned my lesson! My hand is creating like a “cup” to cover the light sensor)

Confident, I decided to create my little disco ball!

I added a RGB LED, rewiring my board so that each prong had a resistor and was attached to an individual output on the Arduino. I then added to my code, establishing the RGB and stating that when the light sensor detects that is dark, the RGB LED will light up red, then delay, green, then delay, and then blue. I thought this would create a disco ball effect.

Here is a photo of the new set up (up close).

setup

Here is the code I made! I was inspired by Sama’s code! So thank you Sama!

badcode

However, when I plugged in my Arduino, the RGB LED light up for a brief moment and then did not light up again. It was then that I discovered I had accidentally shorted my RGB LED.

Without another RGB LED, I realized my disco dreams had to come to an end for now. I will try again later this week and hopefully have more success! Nevertheless, I was able to properly incorporate digital and analog I/O, which is a bit of a victory.

rip

Expressivity: Distance

For my task to code expressivity, I decided on expressing distance.

Things I used:

Arduino Uno R3

Breadboard

Ultrasonic Sensor

10K Ohm Potentiometer

LCD 1602 Module (with pin header)

Female to Male Dupont Wires

Jumper wires (generic)

Wiring:

Wiring    Wiring2 

Wiring3

^^Wiring of the LCD Display and Potentiometer

Code:

Code

^^The code had a few components we hadn’t gone over in class because of the LCD display and the fact that I used 12 out of the 16 pins. To make the centimeters and inches display on the screen I had to use a formula that I got from the sources below.

The goal for this project was to use the ultrasonic sensor to read the distance of an object blocking its waves and use the LCD Display to display the distance of that object from the sensor. I used the potentiometer to control the brightness of the screen of the LCD display, to make sure that I can see the numbers that will appear after coding my Arduino.

^^My sensor was not working at this point, which I fixed later, but I needed to make sure I could see what was expressed on the screen, so this is the test of the potentiometer on the LCD Display.

^^The reason my sensor was not working was because the wire that was supposed to connect to GND on the breadboard was actually plugged in the same row as the echo connection, which made the sensor unable to read the distance. So it was stuck at 0 centimeters  and 0 inches.

After I fixed the wiring, my sensor started working! And everything came to completion!

ATTRIBUTIONS!

For help with wiring and coding the sensor, LCD display, and potentiometer, I give credit to these sources!

Ultrasonic Sensor HC-SR04 and Arduino Tutorial

http://mertarduinotutorial.blogspot.com/2016/11/arduino-tutorial-15-ultrasonic-sensor.html

Real World Application:

I’m pretty sure this exact type of invention is used in cars nowadays. Cars have sensors that allow you to see on a trunk camera how far you are from another object/human being. My expressive device is the bare essentials of this exact technology. I think it’s super cool that I built my own from scratch and actually understand how it works.

LED base dodge game

GAME PLAY

This is a LED base dodge game.

In this game, you are controlling the green light at the button with the joystick. 003

 

You have to avoid the red light at the top.002

It would be fine if they are still light. But when they dimmed, that means they are attacking. So dodge before the LED dim.

 

The game would become faster as you avoid more attacks.

If you get hit, your LED would become dimmer at the first time and game over for the second hit.

004 

If the games over, all game play LED would be turned off. And a yellow LED would be turned on.

001

Press up to try again.

Unfortunately, no score recording at this moment.

https://youtu.be/qpFWHdmYs3s (Second game play)

Process

I used digital write pin for the Red LED

analog write for the green so I can control the brightness.

code:

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(8,OUTPUT);
pinMode(2,INPUT);
digitalWrite(2,HIGH);
}
boolean s1=true; //start of the variables
boolean s2=false;
int x1=analogRead(0);
int y1=analogRead(1);
int xy2=0; // the input of joystick
int xy1;
const int led1=8;
const int led2=12;
const int led3=13;
const int ledu[]={led1,led2,led3};
const int led4=3;
const int led5=5;
const int led6=6;
const int ledd[]={led4,led5,led6};
int hp=255;
int safe;
int ledn;
int ledp=led6;
int hard=1000;
unsigned long t1=millis();// end of the variables

void loop() {
// put your main code here, to run repeatedly:
int x2=analogRead(0);// start of the input
int y2=analogRead(1);
if(x2<350)
{
if(y2<350){xy2=7;}
else if(y2>650){xy2=1;}
else {xy2=4;}
}
else if(x2>650)
{
if(y2<350){xy2=9;}
else if(y2>650){xy2=3;}
else {xy2=6;}
}
else
{
if(y2<350){xy2=8;}
else if(y2>650){xy2=2;}
else {xy2=5;}
} //end the input

if (hp<0){hp=0;}//start of the gameplay;
if (hp!=0)
{
if(millis()-t1>=hard)//start of the red light loop
{
if(s1== true)
{
for(int i=0;i<3;i++)
{
digitalWrite(ledu[i],HIGH);
}
s1=false;
safe=(int)(random(0,3));
digitalWrite(ledu[safe],LOW);
}
else if(s1==false )
{
for(int i=0;i<3;i++)
{
digitalWrite(ledu[i],LOW);
}
s1=true;
if((xy2-4)!=safe)
{
hp=hp-230;
}
else
{
if(hard>350)
{
hard=hard-50;
}
}
}
t1=millis();
}// end if the red light loop

if(xy2==4){ledn=led4;}// start of the output
else if(xy2==5){ledn=led5;}// there would be a very intersting bug if I use the array here
else if(xy2==6){ledn=led6;}
analogWrite(ledn,hp);
if(ledn!=ledp){analogWrite(ledp,0);}
ledp=ledn;// end of ouput
}//if game not end
else
{
for(int i=0;i<3;i++)
{
digitalWrite(ledu[i],LOW);
}
for(int i=0;i<3;i++)
{
analogWrite(ledd[i],0);
}
analogWrite(9,255);
if(xy2==8)
{
analogWrite(9,0);
hp=255;
s1=true;
t1=millis;
hard=1000;
}//if the games end

}

x1=x2;
y1=y2; // store this term’s input
xy1=xy2;
}

Calm Down!

Calm Down Video

VIDEO^^^

So for this week’s project, I decided to make a light that “freaks out” after a little while, and when this happens you need to press it to make it calm down for a bit. I coded it so it would slow down the light blinking dramatically after being pressed, but after a little bit, it goes back to flickering, or “freaking out”. For fun, I used two LEDs, although requiring an additional resistor.

Calm Down SketchCDPcodde