Making Furniture Interactive

September 11, 2007

[Dan D.W. Kang] Assignment Two: Part One

Filed under: Dong Woo Kang,Exercise 2: Add a Switch — dwkang @ 3:45 pm

Part One:

 * Description:

For the first part of this assignment, I created a system that detects an approaching object and responds by turning on three different colors of LED; red, blue and green. The green LED is on when there is nothing in front of the sensor. As an object starts approaching towards the sensor, the green LED will switch off and the blue LED will switch on instantly. The blue LED will remain switched on for a while until the object gets very close to the sensor. This time, the blue LED will switch off and then you will see the light from the red LED. You can watch the video below to see how it works.

* Configuration:

The three wires from the sensor are connected to Analog pin0, Power GND, and 5V on Arduino board. Three LEDs are laid out almost exactly the same as the first assignment (Assignment Zero); the shorter leg (-) of each LED is placed on the same row and is connected to GND pin on Arduino board. The longer leg (+) of the red LED is connected to pin 11 on Arduino board, the blue LED to pin 10, and the green LED to pin 9. Each LED uses a resistor to prevent the burn-out.

 dscn0587.jpg  dscn0588.jpg  




 dscn0581.jpg  dscn0579.jpg dscn0584.jpg   * Code:

To have each LED respond at the different distances, analogValue of less than 200 (the object is farther) was assigned for the green LED to switch on. If the analogValue gets higher than 200 (which means the object is closer), “digitalWrite(green, LOW)” is programmed. Same goes for the blue and red LEDs, with different number of analogValue assigned to each one, depending on the distance of the object to the sensor. Serial.begin(9600) / Serialprint (“Raw Sensor value: “) also had to be included to have my laptop read the values from the sensor.

int analogValue0 = 0;


int analogPin0 = 0;


int red = 11;

int blue = 10;

int green = 9;


void setup() {

  pinMode(analogPin0, INPUT);




    Serial.begin(9600); // Set up the serial communication.


void loop() {

  analogValue0 = analogRead(analogPin0);

  Serial.print(“Raw Sensor value: “);



  if (analogValue0 < 200) {

    digitalWrite(green, HIGH);


  if (analogValue0 > 200) {

    digitalWrite(green, LOW);



  if (analogValue0 > 200) {

    digitalWrite(blue, HIGH);


  if (analogValue0 < 200) {

    digitalWrite(blue, LOW);


  if (analogValue0 > 500) {

    digitalWrite(blue, LOW);



  if (analogValue0 > 500) {

    digitalWrite(red, HIGH);


    if (analogValue0 < 500) {

    digitalWrite(red, LOW);




Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: