ITP NYU Physical Computing

Physical Computing: Week 2 Analog In

I worked with my classmate Meredith for the Analog In lab in week 2 of Intro to Physical Computing @ ITP.

First, we reconstructed the potentiometer and LED breadboard & Arduino setup according to the lab documentation.  After getting familiar with the hardware last week, this week was much easier, and we were able to get the everything to work right very quickly.  The LED gets brighter or dimmer depending on the position of the potentiometer.

Then we decided to do a riff on the theme.  We replaced the pot with a photocell, which required an extra resistor to work correctly, since the photocell only has 2 prongs, while the pot has 3 connections.  We then tweaked the Arduino program by adding an if-else statement to create a kind of nightlight.  When there is a light shining on the photocell, the LED turns off.  When the lamp is turned off, the LED turns on.  The aluminum foil around the red LED is just for aesthetic effect.

Here is the code we used:

int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9

void setup() {
// initialize serial communications at 9600 bps:

void loop() {
potValue = analogRead(potPin); // read the pot value
Serial.println(potValue); // print the pot value back to the debugger pane
analogWrite(led, potValue); // PWM the LED with the pot value
analogWrite(led, 0); // this turns the LED off
//delay(10); // wait 10 milliseconds before the next loop

%d bloggers like this: