Tuesday, May 27, 2008

Lab 3

This one was an exercise in using analog inputs, and ended up being a sort of squeeze meter. I used a Force Sensor Resistor at first to control the fading of a LED. With a series of "if" statements, I used values taken from the resistor to control a familiar-looking meter. Check out the videos, the meter's code is below. I think there's a more concise way to do it, but it works and was simple to quickly implement.


video


video

int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int led = 11; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
int pin2 = 2; // high-low pins for the meter
int pin3 = 3; // high-low pins for the meter
int pin4 = 4; // high-low pins for the meter
int pin5 = 5; // high-low pins for the meter
int pin6 = 6; // high-low pins for the meter
int pin7 = 7; // high-low pins for the meter
int pin8 = 8; // high-low pins for the meter
int pin9 = 9; // high-low pins for the meter
int pin10 = 10; // high-low pins for the meter

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);

}

void loop() {
potValue = analogRead(potPin); // read the pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println(potValue); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop
if (potValue == 0){
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue >= 1 && potValue <= 99){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue > 99 && potValue <= 199){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, LOW);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);


}

else if (potValue > 199 && potValue <= 299){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, LOW);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);


}
else if (potValue > 299 && potValue <= 399){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, LOW);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue > 399 && potValue <= 499){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, LOW);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue > 499 && potValue <= 599){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, LOW);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue > 599 && potValue <= 699){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, HIGH);
digitalWrite(pin9, LOW);
digitalWrite(pin10, LOW);

}
else if (potValue > 699 && potValue <= 799){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, HIGH);
digitalWrite(pin9, HIGH);
digitalWrite(pin10, LOW);

}
else if (potValue >= 799){
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, HIGH);
digitalWrite(pin9, HIGH);
digitalWrite(pin10, HIGH);

}

}

Lab 2

This lab was to create a "combination lock" using the Arduino to trigger the final switch. We were to create a homemade switch from junk. I tried various things, but ended up using two pair of chopsticks. At each narrow end, I attached aluminum foil; when the correct pairs came in contact, the unlocker should also use the pressure switch to trigger the access to the "treasure," in this case, a yellow LED.


It was a simple design, but was interesting as a lock; it was very difficult to actually hold the chopsticks together and simultaneously press the trigger, which I left dangling. Notice the tape on the chopsticks above. If someone had help, it would be easy. Use it to open a big, heavy door to add danger. Here's code:

// declare variables:
int switch1 = 2; // digital input pin for a switch
int switch2 = 3; // digital input pin for a switch
int switch3 = 4; // digital input pin for a switch
int ledPin = 13; // digital output pin for an LED
int switchState1 = 0; // the state of the switch
int switchState2 = 0; // the state of the switch
int switchState3 = 0; // the state of the switch

void setup() {
pinMode(switch1, INPUT); // set the switch pin to be an input
pinMode(switch2, INPUT); // set the switch pin to be an input
pinMode(switch3, INPUT); // set the switch pin to be an input
pinMode(ledPin, OUTPUT); // set the yellow LED pin to be an output
}

void loop() {
// read the switch input:
switchState1 = digitalRead(switch1);
switchState2 = digitalRead(switch2);
switchState3 = digitalRead(switch3);

if (switchState1 == 1 && switchState2 == 1 && switchState3 == 1) {
// if the switch is closed:
digitalWrite(ledPin, HIGH); // turn on the yellow LED

}
else {
// if the switch is open:
digitalWrite(ledPin, LOW); // turn off the yellow LED

}
}





Friday, May 23, 2008

Lab 1

The first lab is an exercise in simple circuit design.

The first part involved adding the power supply, which in this case was 12 V that got converted to 5 V through a voltage regulator. This was verified by a multimeter at just under, at 4.97 V.


The second part was the addition of an LED. In this case, I used a 220-ohm resistor immediately preceding it, with a switch before that.


Parts three and four are short studies in arranging components in serial and in parallel. In the first photo the LEDs light; they should have the same voltage between them, but in this case there was a 0.2 difference between them (2.6 in the first, 2.4 in the second). The third LED lowered their voltages too low to light the LED but with three in parallel they worked fine, with about 3.85 V across each.




In the last part I inserted a potentiometer to control the LED's brightness. The blue line is the pot's output, which goes through the same resistor as above before the LED.

Wednesday, May 21, 2008

INTRO

This blog is for the Intro to Physical Computing class at NYU. Soon I'll put up details of some projects, like photos, circuit designs and descriptions, etc.