Interaction Lab: Lab 11- Drawing Machines (Daniel)

Lab Date: April 28, 2017

Instructor: Professor Daniel

Lab Partner: Andrew Huang, (Amy Mao, Kathy Wang)

Aim of Today’s Lab: Create a drawing machine using stepper motors

Materials Needed: Stepper Motor, Green Legs, Pins, Red Circulating Support, Arduino Kit, a Pen, Stepper Motor Holder

20170428_132459

Step 1- Creating the half of the machine

We started with creating the half of the machine. First, we built the circuit and the physical component of the machine. Creating the physical component of the machine was easy. We just connected the legs with pins and the motor. The motor was connected to the holder at the end as well.

20170428_134603

We followed the circuit diagram provided on the IMA Website.

bipolarStepperMotor-300x254

Creating a circuit was a bit challenging since we did not follow the right colors for the Jump Cables. When the circuit became complicated, it was hard to keep track since the colors were mixed up. However, we figured the circuit out at the end:

20170428_134557

Step 2- Potentiometer

A Potentiometer was added to the circuit to control the speed of the motor. The Middle leg was connected to A0, and the others were connected to ground and 5V. Also, the code for speed control was added from the library.

Step 3- Connection

The last step was connecting two parts together. We just connected the legs using a pin and put a pen in the middle:

Reflection:

It was a fun and a simple lab. The art piece that we created was truly beautiful. I learned that using the right color jump cable is very important.

 

Interaction Lab: Final Project Proposal (Daniel)

Final Project Due Date: May 19, 2017

Partner: Nathalia Lin

Instructor: Professor Daniel

Before taking Interaction Lab, I had never thought deeply about interaction. In fact, I’d thought that technology would only cause the lack of interaction among people. However, throughout the semester, I have learned that technology can actually increase the amount of interaction among people. For instance, I had many interactions with other students, professors and IMA fellows when I was preparing for and presenting my projects. These interactions not only helped me academically, but also let me build stronger relationships with other people. If there weren’t the projects, I would not have been able to have these priceless interactions.

After I realized that I had amazing interactions with others through the projects and started preparing for my final project, I started to think about what interaction really is. It was an important question that came into my mind since the final project for “Interaction Lab” is supposed to be “Interactive”. To build something Interactive, I had to know what interaction really means. Then, I started with searching the definition of the word. On the dictionary the definition of the word “Interaction” is written as “reciprocal action of influence”. To me, the keyword in that definition was “Reciprocal”. My experiences of interactions through my projects were “reciprocal” in that I learned many things from the users’ inputs and the users also enjoyed trying my projects. Interaction is something that happens both ways. I believe that if something happens only one way, it would not be an interaction. Therefore, my definition of interaction is an effect that happens both ways, not one way.

For the final project, I wanted to create something that is highly interactive with its users. I first thought about creating an interactive animation, an animation that reacts to users input (from the sensor). However, my partner suggested about creating a game, and that was a compelling idea to me since I thought game has more potential of interaction. Through a game, besides an interaction between the user and the game, competitive interactions among users were also possible. So, our idea for the final project is creating a 3D Tetris game with Arduino, Processing and Leap Motion. Arduino would be used for the reset button (also possibly joystick to change dimensions), processing would be used to design 3D objects, and leap motion would be used to move around the blocks with the users’ own hands.

There is a 3D Tetris created with leap motion: https://apps.leapmotion.com/apps/fragmental-3d/osx. This is the project where we got our idea from. As it seems, the project is very well built with excellent graphics. The game’s quality is high in that it has different difficulty settings, scoring power, speed and so on. Sound effects are also amazing. The game also has different background themes. In short the game is nearly perfect (even the details of it). But, I think it would allow more interaction among users if the game had online multiplayer option. Since the amount of time given to us is not too much, I believe it would be difficult for our group to create as perfect as this. My goal is to create as much interaction as possible through the project, although it might lack some details compared to the model project.

Interaction Lab: Lab 10-3D Modeling (Daniel)

Lab Date: April 21, 2017

Instructor: Professor Dan

Aim of Today’s Lab: Create a 3D Model (wearable device, game controller, etc) using Tinkercad.

My choice was to create a game controller that uses an accelerometer.

-Materials needed: Accelerometer, Tinkercad, Caliper

I started with the basic design of the controller. I created a box in the middle and then created two handles by putting two torus ,and attached them to the parallel sides of the box. I made sure that the size of the handles were big enough to be held by measuring my own fingers and comparing them to the size of the torus that were sticking out from the box.

My next concern was creating a space for the accelerometer. First, I made a box shaped hole in the middle of the controller. I made the hole to be 25 mm for width and length since the length and width of the accelerometer were both 20 mm. I made the depth to be slightly deeper than the height of the acclerometer (since this data was not provided on the data sheet, I had to measure it using caliper) so that it would not stick out from the controller.

The last step I took was to create spaces for the screws to hold the accelerometer. I made holes using two cylinders with the radius of 1.1 mm. I picked the size after looking at the data sheet of accelerometer and figuring out the radius of holes for the screws. This activity was a bit challenging since I had a hard time aligning everything perfectly. Also, it was difficult for me to get the space between the holes right ( I measured using a ruler).

Conclusion: I realized how fun 3D designing can be. I also noticed how difficult it could be since I had to pay attention to minor details. I learned how to use Tinkercad and understood 3D designing better.

Bodacious Leelo

 

Interaction Lab: Lab 9_ Making My Own Stamp and AutoDesk Field Trip (Daniel)

Class Date: April 11, 2017

Instructor: Professor Daniel

Aim of the Lab: Design your stamp to be laser cut using Adobe Illustrator.

Materials to be prepared: Adobe Illustrator

I started approaching the project by thinking about the design of the stamp. I decided to put my last name in Chinese character in the middle and my first name with English on top of the stamp. I came up with the following design:

20170411_191806

Then, I watched the provided tutorial video to learn how to use Adobe illustrator.

Link: https://vimeo.com/212333844

Following the tutorial I created the basic design first using a square and a circle. Then, I typed my last name in the middle. After that, I used a ‘Type on a path tool’ to put my first name following the circle.

Picture Link: stamp

Then I had to adjust the stamp to the real scale. When I tried adjusting the first time, the stroke size was too big.

Picture Link: stamp.2

Finally, I adjusted the stroke size and reflected the design vertically since the stamp would be vertically flipped, following the tutorial. Here is the completed design.

Picture Link: stamp.3

Conclusion and Reflection: It was exciting for me that I started learning how to laser cut. The tutorial provided was very detailed and easy to follow, so this project was not too challenging. I felt that I would have to play around with AI a lot more to be comfortable with it.

An Auto desk field trip was a great experience in that I got to know about the company better. I learned about their products, goal, and strategy. Also, it was impressive to see their 3D printed creations.

20170414_140206 20170414_140227 20170414_140255 20170414_140304 20170414_140737

 

 

Interaction Lab Midterm Project: Draw Your Life

Project Presentation Date: March 30, 2017

Instructor: Professor Daniel

Project Partner: Nathalia Lin

Project Title: Draw Your Life

  • A painting tool that lets users paint in a color from real life

Description

“Draw Your Life” is a painting tool that can detect color from real life and lets its users paint in that color. The color sensor detects color from many different objects, and users can paint on their computer screens with the detected color. Users can also adjust the size of the stroke by pressing arrow buttons (left and right) on the keyboard. In addition, users can erase what they painted by pressing ‘e’ button on the keyboard and clicking and dragging the mouse.

Demo of the Project (Video)

Below is the completed version of the project:

 

Below is the picture of the completed physical component of the project (Arduino circuit covered with box):

20170331_135510

 

Conceptual Development

Ideation:

The motivation for the project for me was when my friend told me that she would be happy if a photo editing tool could get a color that you like from the physical life (hair color specifically) and let you edit your photo with that color. So I thought it would be a cool idea to start working on a color-sensing paint tool.

Below is the brainstorm sketch that I made in the beginning (it says “Use Color Sensor?/ RGB/ Processing/ Then Paint? (What to be added?)”):

20170401_175229

Research:

When we first started our project, we did not even know that a color sensor existed. So, I went and asked about a sensor that can detect color to the IMA fellows and found out that there are. The first sensor that I checked out was “TCS3200 Color Sensor”.  After following the tutorials provided on “How To Echatronics” I realized that the RGB values that I would receive were not realistic (I received negative numbers). The problem continued even after several IMA fellows and a professor helped us. Therefore, we decided to use a different color sensor, Grove 12C Color sensor.

The link for both TCS3200 Color Sensor and Grove 12C Color sensor are provided below:

http://wiki.seeed.cc/Grove-I2C_Color_Sensor/

Arduino Color Sensing Tutorial – TCS230 TCS3200 Color Sensor

The fist aim for the project was detecting the right RGB Values, and the 12C color sensor allowed us to get reasonable RGB values, so we decided to keep using it.

Technical Development

As I mentioned earlier, our group started with getting the right RGB Values. First we built the Arduino Circuit by connecting VCC to 5V, GND to GND, SDA to SDA, and SCL to SCL (which are A4 and A5 pins).

20170323_171505

Then we used the sample code provided from the lecture about multiple serial communication to send values from Arduino to Processing. And the result was successful (getting reasonable values for different colors on Processing):

The next step was creating a painting tool inside processing. Here is a brief brainstorming about what functions were to be added to the drawing tool:

20170401_181029

We started with an ellipse that would follow the mouse by setting it up as mouse x and mouse y. We also set up a function to make sure that the sensor is not always reading the value. We set up a void mouse click function to read the value only when the mouse is clicked.

After that we decided to make the painting done by strokes instead of ellipses. We set an if statement to not make the stroke negative (if stroke is less than 0, it equals 1).  Then, we set up our mouse pressed for left to draw and mouse clicked for right to read sensor value.

Since we decided to set up our background as white, we could make our erase as another stroke that would paint white. We set up an eraser tool by painting white when ‘e’ key is pressed and the left mouse button is pressed. But then, the problem emerged- the tool would draw and erase at the same time. At this point, I kept working on processing to fix this problem, and my partner decided to work on the physical component of the project. I could solve this problem by making a new function ( I named it void erase). My partner covered the sensor and the circuit with some card boards, making the project look much neater.

Lessons Learned

I believe the user test was very successful. Most of the users thought the idea of the project was brilliant. The shortcoming of the project would be that the sensor’s being inaccurate. Often times the sensor read the color as a different color (e.g. skin is read as red). To avoid this type of failure, users should try to attach the sensor as close to the object as possible. Also, the user should use a non shiny surface to be detected.

 

 

Arduino 

#include <Wire.h>
//#include <math.h>
#include <GroveColorSensor.h>

void setup()
{
	Serial.begin(9600);
	Wire.begin();
}

void loop()
{
	int red, green, blue;
	GroveColorSensor colorSensor;
	colorSensor.ledStatus = 1;							// When turn on the color sensor LED, ledStatus = 1; When turn off the color sensor LED, ledStatus = 0.
	while(1)
	{
		colorSensor.readRGB(&red, &green, &blue);		//Read RGB values to variables.
		delay(300);
      Serial.print (red);
        Serial.print(",");
        Serial.print(green);
        Serial.print(",");
        Serial.print (blue);
        Serial.println ();
		colorSensor.clearInterrupt();
	}
}


Processing

int erase = 0;
import processing.serial.*;
int red, green, blue;
String myString = null;
Serial myPort;
int myMouseButton;

int NUM_OF_VALUES = 3;   /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int[] sensorValues;      /** this array stores values from Arduino **/
int x= 2;

void setup() {
  size(500, 500);
  background(255);

  setupSerial();
}


void draw() {
  updateSerial();
  erase ();
  printArray(sensorValues);

  // use the values like this!
  // sensorValues[0] 

  //red=sensorValues[0];
  //green=sensorValues[1];
  //blue=sensorValues[2];
  if (mousePressed && (mouseButton == LEFT)&&erase==0) {
    stroke(red, green, blue);
    if (x<0) {
      x=1;
    } //stroke weight should not be negative

    strokeWeight (x);
    line(pmouseX, pmouseY, mouseX, mouseY); //draw if left mouse button is clicked
  }
}


void erase() {
  if (keyPressed) { 
    if (key=='e'&&mousePressed) { // eraser if 'e' is pressed
      erase =1;
      stroke (255);
      line (pmouseX, pmouseY, mouseX, mouseY);
    } else {
      erase = 0;
    }
    if (x<0) {
      x=1;
    } //stroke weight should not be negative
    strokeWeight (x);
  }
}

void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.

  myPort.clear();
  // Throw out the first reading,
  // in case we started reading in the middle of a string from the sender.
  myString = myPort.readStringUntil( 10 );  // 10 = 'n'  Linefeed in ASCII
  myString = null;

  sensorValues = new int[NUM_OF_VALUES];
}

void updateSerial() {
  while (myPort.available() > 0) {
    myString = myPort.readStringUntil( 10 ); // 10 = 'n'  Linefeed in ASCII
    if (myString != null) {
      String[] serialInArray = split(trim(myString), ",");
      if (serialInArray.length == NUM_OF_VALUES) {
        for (int i=0; i<serialInArray.length; i++) {
          sensorValues[i] = int(serialInArray[i]);
        }
      }
    }
  }
}
//read values only when the mouse's right button is clicked
void mouseClicked() {
  if ( myMouseButton == 1) {
    red=sensorValues[0];
    green=sensorValues[1];
    blue=sensorValues[2];
  }
}
//draw when LEFT Button of Mouse is clicked
void mousePressed () {
  if (mouseButton == LEFT) {
    myMouseButton=0;
  } else {
    myMouseButton=1;
  }
}
void keyPressed() {
  if (key == CODED) {
    if (keyCode == RIGHT) {    //Make Stroke thicker when right arrow is pressed
      x=x+3;
    } else if (keyCode == LEFT) {     //Make Stroke thinner when left arrow is pressed
      x=x-3;
    }
  }
}

Interaction Lab: Lab 6_ Serial Communication by Jung Hwan

Lab Date: March 17, 2017

Instructor: Professor Daniel

Lab Partner: Andrew Huang

Aim of Today’s Lab: Make Arduino and Processing talk to each other using serial communication.

 

Exercise 1- Ring the Buzzer by clicking the mouse (Processing to Arduino)

Materials Used: Buzzer, Bread Board, Arduino, Jump Wires

We built the circuit first, connecting the buzzer to digital pin 13 and ground of the Arduino. For the code, we set up the buzzer to ring at the tone of 1200 when the mouse is clicked (running the processing code). We did not struggle that much for this exercise since we had the example code (for LED) from the last class. Below is the result:

 

Exercise 2- Changing the color of the Square on Processing by pressing the Button (Arduino to Processing)

Materials Used: Jump Wires, Arduino, 10k Resistor, Button, Bread Board

This exercise was a bit more challenging for us, since we could not figure out the code for a while. With the help of some IMA fellows we could complete the project. It turned that our delay was too low and the circuit had a minor problem (ground jump wire was connected on a wrong spot). As we approached our first exercise, we built the circuits first by connecting the button to  ground and pin 13 through the 10k resistor; another leg was connected to 5V. And then we connected the Arduino and ran the code.

Conclusion and Reflection: I learned how to connect Arduino and Processing to communicate with each other. I completed 2 exercises; sending data from Processing to Arduino (by clicking) and the other way around (by pressing the button). I recognized that serial communication between these two languages could be more challenging than the earlier exercises that we’ve done since we have to work with both of the languages. I felt that we should always double check the circuit when using Arduino and double check the port when we establish communication between different languages.

Buzzer Code: 

Processing:

import processing.serial.*;
Serial myPort;
int val;

void setup(){
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[2], 9600);
}

void draw(){
  if (mousePressed){
    myPort.write('H');
//when the mouse is pressed, send the high value 
  } else {
    myPort.write('L');
  }
}

Arduino:

int val;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  

}

void loop() {
  while (Serial.available()){
    val = Serial.read();
  }
  if (val =='H'){
    tone(13, 1200, 20);
//when the value is high, ring the buzzer
  } else if (val == 'L'){
  }
  delay(10);
}

_________________________________

Button Code:

Processing:

import processing.serial.*;
Serial myPort;
int val, value;

void setup(){
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[2], 9600);
}

void draw(){
  if ( myPort.available() > 0) {
  value = myPort.read();
  println(value);
  }
  rect(0, 1, 50, 50);
  if (value == 1){
    fill(0, 0, 0);
//if the button is pressed (value is 1) change the square color
  } else {
    fill(255, 255, 255);
//if the button is unpressed turn back the square color
  }
}

Arduino:

int val;

void setup() {
  Serial.begin(9600);
  pinMode(13, INPUT);
  }

void loop() {
  int read = digitalRead(13);
  if (read == 1){
    Serial.write(1);
  //if the button is pressed send the value 1 
} 
else {
    Serial.write(0);
  }
  delay(100);
}

Interaction Lab: Stupid Pet Trick Documentation by Jung Hwan (Daniel)

Project Presentation Date: Mar. 10, 2017

Instructor: Professor Daniel

Aim of the Project: Make the Arduino do something interactive and stupid. My idea was to create a sweaty hand detector with a moisture sensor. I wanted to detect how sweaty the hand is when it touches the sensor and turn the servo to put up the “Sweaty Hand!!” sign and buzz the buzzer when the sensor value is high (which means the hand is sweaty).  Below is the simple sketch that I drew:

20170309_140154

Materials Used: glove, arduino, servo, bread board, buzzer, jumper cables, moisture sensor, card boards, electrical tape

Stage 1- Building the Circuit

I started building the project with the circuit. I followed the diagrams provided in our arduino toolkit. I connected the positive side of the buzzer to pin 8 and negative side to the ground. I also connected the servo to ground, 5V and pin 10. In addition, I connected the moisture sensor to ground, analog pin and 5V. A bread board had to be used since there was not enough space on the aruduino itself.  Below is a picture of the circuit:

20170308_162355

Stage 2- The physical component

I cut some cardboard to put under the servo to turn it without being disturbed. I cut some other smaller pieces to attach it to the wing of the servo to put the “Sweaty Hand!!” sign on it. I also attached the moisture sensor on the glove using electrical tape (I used regular tape in the beginning, but Professor Anthonius notified me later that it would work better with electrical tape).

20170308_162434                      20170308_175435

Stage 3- Coding

This is the stage that I struggled the most. I tried coding servo and buzzer output with moisture sensor input. I looked at the codes that we learned from our lab (temperature alarm) session and the arduino library (for servo).  With the help of Professor Anthonius I could code for the servo turn output and buzzer ring output according to the moisture sensor input.

Completed Project:

Note: I changed the tape from normal to electrical at the end- below is the picture of the final project with electrical tape:

20170308_182152

Conclusion and Reflection: I had so much fun building something that I designed for the first time. The most difficult part for me was coding. I felt that I would have to study coding more. I’ll have to remember what professor Daniel told me; just Copy and Pasting” would not work.

 

#include <Servo.h>

int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int pos = 0; 
Servo myservo;
void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT); // output for the servo
  myservo.attach(10);
  pinMode(8, OUTPUT); // output for buzzer
}
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);
  delay(10);
  if (sensorValue > 150) {
    myservo.write(95);
     //if the sensor is greater than 150, turn the servo to 95 degrees
    tone(8,1047,20);
    //if the sensor value is greater than 150, ring the buzzer
  }
  else {
    myservo.write(5);
  //if the sensor value is less than 150,return the servo to 5 degrees
  }
}

Interaction Lab: Lab 4-Sensors

Lab Date: March 3, 2017

Instructor: Professor Daniel

Documented by: Jung Hwan Park

Aim of Today’s Lab: Connect a sensor to the Arduino using it as input for some kind of output.

I decided to work with a moisture sensor to light up an LED light.

Step 1: Input

Materials: Moisture sensor, Jump Wires, Arduino, Wet sponge

I connected the moisture sensor to the Arduino with Jump wires, then uploaded the code. With some help from professor Daniel, I could check the humidity was changing when the sensor was in contact with a wet sponge.

 

Step 2: Output

Materials: 220R resistor, LED light, Jump wires, Arduino, Bread board, Wet Sponge, Moisture Sensor

I wanted to light up an LED light with the humidity input. With the help of Professor Antonius, I connected the LED light to a bread board, eventually connecting it to the Arduino going through the resistor. By creating  conditionals (light up when it is humid) I could successfully light the LED light up.

Conclusion and Reflection: It was generally a fun lab. I learned how to work with a moisture sensor. I practiced how to create conditionals as well. I also gained basic understandings of input and output.

// Test code for Grove - Moisture Sensor 
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor7

void setup() {
    // declare the ledPin as an OUTPUT:
    Serial.begin(9600);
}
void loop() {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    Serial.print("sensor = " );
    Serial.println(sensorValue);
    delay(1000);
}


//code for the added LED light 
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor7

void setup() {
    // declare the ledPin as an OUTPUT:
    Serial.begin(9600);
    pinMode(13,OUTPUT);
}
void loop() {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    Serial.println(sensorValue);
    delay(10);
    //if the sensor is greater than 500 then turn on the LED
    if (sensorValue>500){
      digitalWrite(13,HIGH);
    }else {
      digitalWrite(13,LOW);
    }
}

Interaction Lab: Lab 3- Animation in Processing

Lab Date: Feb. 24, 2017

Instructor: Professor Daniel

Name: Jung Hwan Park

Aim of today’s Lab: Create basic animations using processing.

Exercise 1- Rotating Square

Since I did not know what to create in the beginning, I decided to mimic the sample of rotating square shown in the beginning of the Lab. It was easy for me to draw a square in the middle, but I had some trouble making is constantly rotate. I could not the make the square constantly rotate on my first try since I forgot to put the pop matrix. With the help of professor Marcela, I found out what was wrong and succeeded to make the square rotate.

Exercise 2- Face Falling off

My second exercise was to draw a human face and make it fall down. I had some trouble drawing an arc for the nose (since I couldn’t figure out the angles), but one of the IMA fellows taught me how to set up a starting and an ending angle. By setting up the integer Y and making all the y parts increase by 1 (y++) gave me a successful result.

Conclusion: I learned how to create simple 2D animations with processing. My mistakes are generally caused by my lack of knowledge. I felt that I should study how to code more. Also, I felt that it is important not to forget minor tasks such as putting a semi-colon when I code.

Reflection

  1. Ask for help if you are confused.
  2. Double check your code for minor omissions/error.
  3. Practice Processing more often.

 

Face Falling Off

int y=0;

void setup(){
  size(500,500);
}
void draw(){
  y++; // increase y by 1
  background(0,255,255);
  fill(255,255,0);
  ellipse(250,y,200,200);

fill(0);
ellipse(225,y,20,20);
ellipse(275,y,20,20);
fill(255);
arc(250,y,40,40,radians(90),radians(270));
}



Rotating Square

void setup(){
  size(500,500);
  rectMode(CENTER);  //draw the rectangle in the center
}
void draw(){
  background(255,0,255);
  pushMatrix();
  translate(width/2, height/2);
  rotate(radians(frameCount));  // Rotate the rectangle
  rect(0,0,100,100);
  popMatrix();
}

Lab 2: Arduino Basics

Date: Feb. 17 2017

Instructor: Daniel

Name: Jung Hwan Park

Partner: Eric Zhang

Objective: This lab’s objective was to build some projects using the materials from the arduino toolkit. The projects that I chose were traffic light and temperature alarm.

Exercise 1- Traffic Light

The project was built using three different colors of LEDs (Red, Green and Yellow). Resistors (10k and 220), switch and the LEDs were connected to a breadboard which was connected to the arduino (As shown in the diagram).

20170217_215402

It did not work the first time since I could not upload the code to my the arduino software on my computer. With the help of the IMA staffs, I found out that the arduino is broken. The project worked fine with the new arduino.

Exercise 2- Temperature Alarm

The second exercise was simpler than the first. I followed the diagram below to build the project.

400px-7_Temperature_Alarm

The project did not work on the first try and I found out the reason is that I did not connect the ground of the buzzer to the ground of the arduino. The alarm rang when I connected them and held the sensor to change its temperature.

Conclusion and Reflection: It was amazing to build projects using both the arduino software and hardware. I realized it is important to double check if I connected everything that is provided in the diagram.

Traffic Light

int carRed = 12; //assign the car lights
int carYellow = 11;
int carGreen = 10;
int button = 9; //button pin
int pedRed = 8; //assign the pedestrian lights
int pedGreen = 7;
int crossTime =5000; //time for pedestrian to cross
unsigned long changeTime;//time since button pressed

void setup() {
  	pinMode(carRed, OUTPUT);
  	pinMode(carYellow, OUTPUT);
  	pinMode(carGreen, OUTPUT);
  	pinMode(pedRed, OUTPUT);
        pinMode(pedGreen, OUTPUT);
        pinMode(button, INPUT); 
        digitalWrite(carGreen, HIGH); //turn on the green lights
	digitalWrite(pedRed, HIGH); 
}

void loop() {
	int state = digitalRead(button);
        //check if button is pressed and it is over 5 seconds since last button press
        if(state == HIGH && (millis() - changeTime)> 5000){
               //call the function to change the lights
               changeLights();
        }
}

void changeLights() {
	digitalWrite(carGreen, LOW); //green off
	digitalWrite(carYellow, HIGH); //yellow on
	delay(2000); //wait 2 seconds
		
	digitalWrite(carYellow, LOW); //yellow off
	digitalWrite(carRed, HIGH); //red on
        delay(1000); //wait 1 second till its safe
		
	digitalWrite(pedRed, LOW); //ped red off
	digitalWrite(pedGreen, HIGH); //ped green on

	delay(crossTime); //wait for preset time period
		
	//flash the ped green
        for (int x=0; x<10; x++) {
	        digitalWrite(pedGreen, HIGH);
		delay(250);
		digitalWrite(pedGreen, LOW);
		delay(250);
         }
 	  			
        digitalWrite(pedRed, HIGH);//turn ped red on
	delay(500);

	digitalWrite(carRed, LOW); //red off
	digitalWrite(carYellow, HIGH); //yellow on	
	delay(1000);
	digitalWrite(carYellow, LOW); //yellow off
        digitalWrite(carGreen, HIGH); 

	changeTime = millis(); //record the time since last change of lights
	//then return to the main program loop
} 
The traffic light code is comparatively long since it has many commands. 




Temperature Alarm

float sinVal;            
int toneVal;
unsigned long tepTimer ;    

void setup(){ 
    pinMode(8, OUTPUT);        
    Serial.begin(9600);        
}

void loop(){ 
    int val;               
    double data;          
    val=analogRead(0);  
    data = (double) val * (5/10.24);  // convert the voltage to temperture
     
    if(data>27){        // If the temperture is over 27 degree, buzzer will alarm.  
          for(int x=0; x<180; x++){
            sinVal = (sin(x*(3.1412/180)));
            toneVal = 2000+(int(sinVal*1000));
            tone(8, toneVal);
            delay(2); 
     }   
    } else {    // If the temperturn is below 27 degree, buzzer will not alarm  
           noTone(8);           
    }
     
    if(millis() - tepTimer > 500){     // output the temperture value per 500ms
             tepTimer = millis();
             Serial.print("temperature: ");     
             Serial.print(data);              
             Serial.println("C");              
       } 
}
The code for temperature alarm is relatively simple. Important thing to remember was that I could change the temperature that would turn the alarm on.