Archive forphysical computing

Week7- pcomp lab

To control the DC motor, I used the H-bridge which have six transistors-two for switches, four for inner circuit. If pin 1 and 3 are open, pin 3 and 4 are closed. In other words, one is high, the other is low.

Four pins(4,5,12,13) in the middle of the H-bridge are for the ground. 1 and 9 pins are enable pins. 3 and 6 are for one motor. 11 and 14 are the other motor(H-bridge can control two motors. 2 and 7 is for the Arduino pin to control each H-bridge leg. Depending on the switch’s mode, the motor’s direction can be changed.

When I supplied the 12V power, I could smell something burning. One of the classmate said this was because of turning the direction quickly. Later I found that the motor’s power is for 6V based on the data instruction. According to the instruction, I used too much power.

<Transistor>

Transistos => electronic devices that control a large current from a smaller current. There are three connections referred as the base, the collector, and the emitter. By putting a small voltage and current on the base of a transistor, you allow a larger current to flow from the collector to the emitter. They function as amplifiers. There are two type of bipolar transistors : One is NPN, the other is PNP type. The NPN is equivalent a normally open switch and PNP is equivalent to a normally closed switch.   <from “Physical Computing”>

Program the microcontroller to run the motor through the H-bridge:

int switchPin = 2;    // switch input
int motor1Pin = 3;    // H-bridge leg 1
int motor2Pin = 4;    // H-bridge leg 2
int speedPin = 9;     // H-bridge enable pin
int ledPin = 13;      //LED 

void setup() {
  // set the switch as an input:
  pinMode(switchPin, INPUT); 

  // set all the other pins you're using as outputs:
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(speedPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  // set speedPin high so that motor can turn on:
  digitalWrite(speedPin, HIGH); 

  // blink the LED 3 times. This should happen only once.
  // if you see the LED blink three times, it means that the module
  // reset itself,. probably because the motor caused a brownout
  // or a short.
  blink(ledPin, 3, 100);
}

void loop() {
  // if the switch is high, motor will turn on one direction:
  if (digitalRead(switchPin) == HIGH) {
    digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  }
  // if the switch is low, motor will turn in the other direction:
  else {
    digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
    digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
  }
}

/*
  blinks an LED
 */
void blink(int whatPin, int howManyTimes, int milliSecs) {
  int i = 0;
  for ( i = 0; i < howManyTimes; i++) {
    digitalWrite(whatPin, HIGH);
    delay(milliSecs/2);
    digitalWrite(whatPin, LOW);
    delay(milliSecs/2);
  }
}

Comments

Thermo Shoes - PROJECT

<< Final shoe work>>

When you change the speed like walking and running, people around the shoes can see the color changes. The principle of the shoes mechanism is that movement goes up the voltage and voltage heat the heater and then heater finally change the color outside of the shoes.

circuit with piezo sensor

circuit on the perfboard perfboard.jpgperfboardfront.jpg

<<Circuit>>

circuit2.jpg circuitwithleds.jpg

A heater needs at least 12V and lots of amperage. Therefore, we tried to use a transistor or relay(just making an experiment). Transistor can allow 5V to amplify 12V. ( similarly, a relay is an electrical switch that opens and closes under the of another electrical circuit using magnet)

<<materials>>

battery.jpg colorwith-magnet.jpg lilypad.jpg

We want to put all stuffs inside of the shoe but we need enough amperage for heater(left). So, we purchased 0.8amp battery. And, to facilitate attaching changing part to a shoe, we came up the idea of using magnet (middle). Lilypad is beautiful but when we connected all wires with conductive threads, we got loosened connection. That was a really problem!!

<< Thermochromic Paints>>

paint.jpg ink.jpg greentoyellow.jpg circuit1.jpg

Thermochromic paint is color paints that can make color changes when heat add. We contact the one of the company, MATSUI( www.matsui-color.com), and we asked 35(disappear minimum 36 degree Celsius) and 37 (disappear minimum degree 41 degree Celsius) paints to the company. For showing beautiful color, we mixed with acrylic paints.

<<Sensor experiments>>

sensorgraph.jpg We, Alex and I, had a problem in that we use the piezo buzzer sensor. It has a kind of own capacitor. So, whenever making one step, it makes a pick and slowly goes down. How we can check one step not the bunch of steps? Thus, we made a threshold between current step and last step to discard useless value.

code

const int piezoSensor = 0; // Analog pin connected to piezo sensor.
const int swooshHeatOutput = 8; //PWM pin used to regulate temperature of heating pad.
const int runningIndicatorLED = 7;
const int footstepValueThreshold = 175; //Minimum voltage signal spike to required to count as a footsep.
const int footstepTimeThreshold = 200; //Minimum footspeed (in millis) required to count as a footstep.
const int minimumRunSpeed = 450;

long currentPiezoSensorValue[2];
long lastPiezoSensorValue[2];
int currentFootstepValue;
int lastFootstepValue;
long currentFootstepTime;
long lastFootstepTime;
float averageFootSpeed;
long cummulativeFootSpeed;
long currentFootSpeed;
int footstepCount;
int running;

void setup() {
Serial.begin(9600);
lastPiezoSensorValue[0] = lastFootstepValue = currentPiezoSensorValue[0] = currentFootstepValue = analogRead(piezoSensor);
lastPiezoSensorValue[1] = lastFootstepTime = currentPiezoSensorValue[1] = currentFootstepTime = millis();
cummulativeFootSpeed = footstepCount = 0;
currentFootSpeed = averageFootSpeed = 3000;
pinMode(swooshHeatOutput, OUTPUT);
}

void loop() {

if (currentPiezoSensorValue[1] % 3000 == 0) {
averageFootSpeed = 2000;
cummulativeFootSpeed = 0;
footstepCount = 0;
}

lastPiezoSensorValue[0] = currentPiezoSensorValue[0];
lastPiezoSensorValue[1] = currentPiezoSensorValue[1];
currentPiezoSensorValue[0] = analogRead(piezoSensor);
currentPiezoSensorValue[1] = millis();

//running = constrain(averageFootSpeed, minimumRunSpeed, maximumRunSpeed);
if (averageFootSpeed <= minimumRunSpeed ) {
digitalWrite(swooshHeatOutput, HIGH);
digitalWrite(runningIndicatorLED, HIGH);
}
else {
digitalWrite(swooshHeatOutput, LOW);
digitalWrite(runningIndicatorLED, LOW);
}

/*if (averageFootSpeed > minimumRunSpeed) {
analogWrite(swooshHeatOutput, 0);
}
else if (averageFootSpeed <= minimumRunSpeed && averageFootSpeed > mediumRunSpeed ){
analogWrite(swooshHeatOutput, 85);
}
else if (averageFootSpeed <= mediumRunSpeed && averageFootSpeed > maximumRunSpeed ){
analogWrite(swooshHeatOutput, 128);
}
else if (averageFootSpeed <= maximumRunSpeed) {
analogWrite(swooshHeatOutput, 255);
}*/

if ( (currentPiezoSensorValue[0] - lastPiezoSensorValue[0]) > footstepValueThreshold) {
//Serial.println(currentPiezoSensorValue[0] - lastPiezoSensorValue[0]);
if ( (currentPiezoSensorValue[1] - lastFootstepTime) > footstepTimeThreshold) {
//Serial.println(currentPiezoSensorValue[1] - lastFootstepTime);

lastFootstepValue = currentFootstepValue;
lastFootstepTime = currentFootstepTime;
currentFootstepValue = currentPiezoSensorValue[0];
currentFootstepTime = currentPiezoSensorValue[1];
currentFootSpeed = currentFootstepTime - lastFootstepTime;

if (currentFootSpeed > footstepTimeThreshold) {
footstepCount += 1;
cummulativeFootSpeed = cummulativeFootSpeed + currentFootSpeed;
averageFootSpeed = cummulativeFootSpeed / footstepCount;
Serial.print(”Step: “);
Serial.print(footstepCount);
Serial.print(” “);
Serial.print(”Current Step: “);
Serial.print(currentFootstepValue);
Serial.print(” “);
Serial.print(”Last Step: “);
Serial.print(lastFootstepValue);
Serial.print(” “);
Serial.print(”Current Time: “);
Serial.print(currentFootstepTime);
Serial.print(” “);
Serial.print(”Last Time: “);
Serial.print(lastFootstepTime);
Serial.print(” “);
Serial.print(”Current Foot Speed: “);
Serial.print(currentFootSpeed);
Serial.print(” “);
Serial.print(”Average Foot Speed: “);
Serial.println(averageFootSpeed, DEC);
//Serial.print(currentPiezoSensorValue, DEC);
//Serial.println(”,”);
}
}
}
}
<<

<< Piezo sensor>>

After an experiment of an accelerometer sensor, we recognized that it is not easy because we had to make a standard which value is walking and which value is running based on acceleration. So, we decided to change a accelerometer sensor into piezo sensor.

What is the piezo sensor?

piezo-buzzer.jpg piezo.jpg A piezoelectric sensor is a device that uses the piezoelectric effect to measure pressure, acceleration, strain or force by converting them to an electrical signal.

It’s a charge amplifier as well. It’s an electronic amplifier which convert an input charge( stored on a capacitor, or significantly capacitive transducer) to a voltage output. -wikipedia

Comments

Datalogger Code by Tom Igoe

———This is the code making gragh based on analog data. When you want to see the data as a visualised way, this is very useful method.
I think understanding serial with this code might be useful as well. —————

Processing Code:

import peocessing.serial.*; // call the serial library

Serial myPort; // the serial port

// initial varialbles
int [] sensorValue = new int[3];
int hposition = 0;

void setup(){
// size
size(400,300);
// list all the avilable serial ports
println(Serial.list());
// open whatever port you are using
myPort = new Serial(this, Serial.list[1], 9600);
myPort.bufferUntil(’\r’);

// set initial background
background(0);
}

void draw(){
// gragh fuction call with if statement
if(sensotValues[0] >=0 && sensorValues[1]>=0 && sensorValues[3] >=0){
gragh(sensorValues[1]);
}
}

void serialEvent(Serial myPort){
Srting serialString = myPort.readStringUntil(’\n’);
if(serialString != null){
String[] numbers = split(serialString,”,”);

// put in the array using split fuction
for(int i=0; i< numbers.length; i++){
sensorValues[i] = int (numbers[i]);
print(sensorValues[i] + “\t”);
}
println();
}
}

void gragh(int numberToGraph){
// draw the line
stroke(0,255,0);
line(hPosition, height, hPosition, height-numberToGraph);

// at the ecge of screen, go back to the beginning
if(hPosition >= width){
hPosition =0;
background(0);
}
else{
hPosition++;
}
}

Arduino code:

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

void loop(){
int x = analogRead(3);
delay(10);
int y = analogRead(4);
delay(10);
int z = analogRead(5);

Serial.print(x, DEC);
Serial.print(”, “);
Serial.print(y,DEC);
Serial.print(”, “);
Serial.print(z, DEC);

}

Comments

Week5 -physcomp lab

The circuit that consists of the two analog sensor pins 0 and 1 and one digital pin2

# flex sensor is not sensitive to range. so, I changed flex sensor to second potentiameter.

Through the Hyperterminal, any bytes I typed was shown in the serial moniter. The BYTE sent the raw binary value of the byte, the DEC sent the decimal vlaue that an ASCII-encoded.

< Arduino Code>

int firstSensor = 0;    // first analog sensor
int secondSensor = 0;   // second analog sensor
int thirdSensor = 0;    // digital sensor
int inByte = 0;         // incoming serial byte

void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  pinMode(thirdSensor, INPUT);
}

void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
     Serial.print("I received");
     Serial.println(inByte,DEC);
               -> “” and decimal value that I type is printed
    // read first analog input, divide by 4 to make the range 0-255:
    firstSensor = analogRead(0)/4;
    // delay 10ms to let the ADC recover:
    delay(10);
    // read second analog input, divide by 4 to make the range 0-255:
    secondSensor = analogRead(1)/4;
    // read  switch, multiply by 255
    // so that you're sending 0 or 255:
    thirdSensor = 255 * digitalRead(2);
    // send sensor values:
    Serial.print(firstSensor, BYTE);
    Serial.print(secondSensor, BYTE);
    Serial.print(thirdSensor, BYTE);
  }
}

* Because of Serial.available(), data is sent only when I type the value.

*int Serial.read() : reads incoming serial data

an int, the first byte of incoming serial data abailable(or -1 if no data is available)

*int Serial.available() : get the number of bytes (characters) available for reading over the serial port.

the number of bytes are available to read in the serial buffer, or 0 is none are avilable. If any date has come in, Serial.avilable() will be greater than 0. The serial buffer can hold up to 128 bytes.

<< Processing Code>>

import processing.serial.*;

int bgcolor;			     // Background color
int fgcolor;			     // Fill color
Serial port;                         // The serial port
int[] serialInArray = new int[3];    // Where we'll put what we receive
int serialCount = 0;                 // A count of how many bytes we receive
int xpos, ypos;		     // Starting position of the ball
boolean firstContact = false;        // Whether we've heard from the microcontroller

void setup() {
  size(256, 256);  // Stage size
  noStroke();      // No border on the next thing drawn

  // Set the starting position of the ball (middle of the stage)
  xpos = width/2;
  ypos = height/2;

  // Print a list of the serial ports, for debugging purposes:
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Keyspan adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  port = new Serial(this, Serial.list()[1], 9600);
        -> since Port number is 1, I have to change the number 0 to 1.
  port.write(65);    // Send a capital A to start the microcontroller sending
}

void draw() {
  background(bgcolor);
     -> Defalt value is 0.So,background is black. changing value make circle to be shown
  fill(fgcolor);
  // Draw the shape
  ellipse(xpos, ypos, 20, 20);

  // If no serial data has beeen received, send again until we get some.
  // (in case you tend to start Processing before you start your
  // external device):
  if (firstContact == false) {
    delay(300);
    port.write(65);
  }
}

void serialEvent(Serial port) {
  // if this is the first byte received,
  // take note of that fact:
  if (firstContact == false) {
    firstContact = true;
  }
  // Add the latest byte from the serial port to array:
  serialInArray[serialCount] = port.read();
  serialCount++;

  // If we have 3 bytes:
  if (serialCount > 2 ) {
    xpos = serialInArray[0];
    ypos = serialInArray[1];
    fgcolor = serialInArray[2];

    // print the values (for debugging purposes only):
    println(xpos + "t" + ypos + "t" + fgcolor);

    // Send a capital A to request new sensor readings:
    port.write(65);
    // Reset serialCount:
    serialCount = 0;
  }
}

Comments

week4- physcomp lab

The lab is about servo motor based on analog output concept. Unlike digital output, analog output makes the data range. Lighting dimmer and motor controllers are common examples.

microcontrollers can only produce a high voltage(5V) or low voltage(0V). Thus, we use PWM( pulse width modulation) which is from regular intervals instead. If the length of high time is half total time, the duty cycle(the ratio of length of high time) is 50% which is the half of the total voltage.

(The pulsewidth - usually a very small time, on the order of a few microseconds or milliseconds at most.

Sercomotors - motors with a combination of gears and an embedded potentiometer that allows you to set their position fairly precisely within a 180-degree range. There are three wires(power, ground, control). connect the +5V directly to a 5V power source that can supply at least one amp of current (don’t try to power the motor from the microcontroller, it hasn’t got enough power) Ground it to the same ground as the microcontroller. And attach the control pin to a pin on the microcontroller. Then you need to send a series of pulses to the control pin to set the angle. The longer the pulse, the greater the angle. -from Tom’s pcomp page-)
To move motor automatically from 0 to 180,

int servoPin =2; //펄스 넣어주는 곳
int minPulse = 500; // 최소한의 펄스
int maxPulse = 2500; // 최대펄스
int pulse = 0; // 펄스 핀 0

long lastPulse = 0; //
int refreshTime = 20;

int analogValue = 0;
int analogPin = 0;

void setup(){
pinMode(servoPin, OUTPUT);
pulse = minPulse;
Serial.begin(9600);
}

void loop(){
if (pulse <=minPUlse) {
// start increasing the pulse pulseChange = 1;
}
if (pulse >= maxPulse) {
// start decreasing the pulse
pulseChange = -1;
}
pulse = pulse + pulseChange;

// Serial.println(analogValue);

//millis()의 개념 ,처음에는 0, 1초가 되면 1000, 그래서 라스트 펄스도 처음에는 0, 시간에 지나고
// 20보다 크면 실행하고 20보다 큰수를 넣어준다.

if(millis() - lastPulse >= refreshTime){

//이 서보모터는 20의 시간이 필요하다

digitalWrite(servoPin, HIGH);
delayMicroseconds(pulse);

digitalWrite(servoPin,LOW);
lastPulse = millis();
}

}

Comments

3rd Lab - A

-Fading a LED by using PWM-

Comments

3rd Lab - B

- the video of fading the leds -

This is the third step of practcing analog I/O. Analog has the duty cycle between 0 to 255(pwm). By using this cycle, for statements, and delay time, I can make the fading line leds from middle to outer led.

Fading five leds Using of analog output (pwm) one after the other

int pinOut11 = 11; // set pinOut11 to pin number 11
int pinOut10 = 10; //set pinOut10 to pin number 10
int pinOut9 = 9; //set pinOut9 to pin number 9
int val = 0; // variable to keep potetiameter value
int analIn = 0; // set analogIn to analog pin number 0
int fadeVal = 0; // variable to keep the pwm value

void setup(){
Serial.begin(9600);
pinMode(pinOut9,OUTPUT); // declare the pinOut9 as an OPUT
pinMode(pinOut10,OUTPUT); // declare the pinOut10 as an output
pinMode(pinOut11,OUTPUT); // declare the pinOut11 as an output
}

void loop(){

// val = analogRead(analIn); read the value from the potentiameter

Serial.println(val,DEC);
for(val =0 ; val<=255 ; val +=5){ // fade in (from min to max)
analogWrite(pinOut11,val);
delay(10); // wait 30mili seconds to see the dimmer
}
for(val = 255 ; val >=0; val -=5){
analogWrite(pinOut11, val);
delay (10);
}
for(val =0 ; val<=255 ; val +=5){
analogWrite(pinOut11,val);
analogWrite(pinOut10,val);
delay(10);
}
for(val = 255 ; val >=0; val -=5){
analogWrite(pinOut10, val);
analogWrite(pinOut11, val);
delay (10);
}
for(val =0 ; val<=255 ; val +=5){
analogWrite(pinOut11,val);
analogWrite(pinOut10,val);
analogWrite(pinOut9,val);
delay(10);
}
for(val = 255 ; val >=0; val -=5){
analogWrite(pinOut10, val);
analogWrite(pinOut11, val);
analogWrite(pinOut9, val);
delay (10);
}
}

Comments

2nd LAB

- the video of making the LOOP-

int timer = 100;
int pins[] = {2,3,4,5,6,7};
int num_pins = 6;

void setup(){
int i;
for(i=0; i< num_pins ; i++)
pinMode(pins[i], OUTPUT);
}

void loop(){
int i;
for(i=0 ; i< num_pins ; i++){
digitalWrite(pins[i], HIGH);
delay(timer);
digitalWrite(pins[i], LOW);
}
for(i = num_pins -1 ; i>=0; i–){
digitalWrite(i, HIGH);
delay(timer);
digitalWrite(i, LOW);
}
}

In this case, I make the 13 pin as an output. Depending on delay time,  led blinks  by repeating High voltage(5V) and Low voltage(0V)

Digital I/O

digitalRead(pin) -> reads the value from the pin I want to read, it will be either HIGH or LOW.

digitalWrite(pin, value) -> outputs either HIGH orLOW at the pin what i want to write

// declare variables:
int switchPin = 2; // digital input pin for a switch
int yellowLedPin = 3; // digital output pin for an LED
int redLedPin = 4; // digital output pin for an LED
int switchState = 0; // the state of the switch

void setup() {
pinMode(switchPin, INPUT); // set the switch pin to be an input
pinMode(yellowLedPin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLedPin, OUTPUT); // set the red LED pin to be an output
}

void loop() {
// read the switch input:
switchState = digitalRead(switchPin);

if (switchState == 1) {
// if the switch is closed:
digitalWrite(yellowLedPin, HIGH); // turn on the yellow LED
digitalWrite(redLedPin, LOW); // turn off the red LED
}
else {
// if the switch is open:
digitalWrite(yellowLedPin, LOW); // turn off the yellow LED
digitalWrite(redLedPin, HIGH); // turn on the red LED
}
}

Comments

Observation Assignment

 

The observation of using everyday technology seems to be tough for me because even though I always observe person’s behavior and what they are doing, I had to be invloved in people’s private spaces by looking at them closely instead of glancing at them. Here is my observation.

On the subway, there was a young man who had a moblie phone. He was sitting alone and took the phone from his pocket, opened the folder, pushed the menu button, and chose the music. The music made a loud sound. At first, I thought he just wanted to listen to the electronical music. however, while listening to the music, he was rapping the side of the phone to make a sound like beat box. He was trying to be a DJ.

A few seconds later, he was trying to listen to the music actively, but he seemed to become bored quickly. At this point, I think there was a problem of interaction between him and his device in that the mobile phone is a device for calling and a substitute for a real beat box. that is, it is the only way to enjoy being a DJ with mobile phone for him is just rapping on this small side button. I saw several times he nearly dropped his phone while playing as well. This means the phone limits his behavior and space to enjoy his music. Finally, he just listened to the music rather than used play function of the phone.

Comments

1st LAB

soldered dc power and switch

To protect Arduino, I had to make a soldered dc power jack & switch

lab1-21.JPG lab1-5.JPG

Through  the 7805 regulator,  about 16V from AC power can be converted into about 5V DC power.

lab1-8.JPG lab1-9.JPG

This is the first circuit that I made

lab1-14.JPG  The components of this circuit are all in series.

  lab1-12.JPG lab1-13.JPG  

Measuring Voltage

-  all components in series have same current.  the resistance and led of the circuit have different resistance and voltage because of  V =  I  x  R  . Therefore,  5V is the sum of  each voltage of resistor( led is a kind of resistor).

lab1-20.JPG This is the parallel circuit.

 The same voltage across the whole citcuit. but, The current is split into each led.

lab1-6.JPG  

This is variable resistors called potentiometer that play role in resisting the flow of electricity to varying degrees.

lab1-26.JPGlab1-25.JPG

What I ‘ve known by experimenting potentiometer is that i’ve got the brighter led when turning the knob of resistor to the right. It means the circuit has the least resistance in this case.

<NOTE> 

1.”All the electrical energy in a circuit must be used.”

2.” Electricity always favors the path of least resistance to ground “    

3. Ohm’s Law   

    Voltage = Current   x   Resistance

 4. Wattage, electrical power

     Watts  =  volts  x  amps

Comments