The lamp has a total of four I/R sensors, each at a different location of the lamp. Three LEDs (red, green, blue) are designated for each sensor, and will respond to the level of activity that the sensor detects. Once the sensor detects anyone within its range, the LED for the corresponding sensor will emit different colors of light depending on the distance between him and the table. The farther the occupant is away from the table, the LED will emit "cool" colors such as blue. The closer the occupant is to the table, the LED will emit warm colors such as red, yellow, etc (figure 2).
Since the lamp has twelve LEDs responding to four sensors, the table can thus have up to four different shades at the same time. In a room with dynamic movements of occupants, the lamp will constantly change its colors. Conversely, in a room with rather static movements of occupants, the colors of the lamp will be much more constant. Figures 3 and 4 show how the table will look like depending on the locations of occupants.
Remove these ads by
Signing UpStep 1Programming
The project requires the codes that can interpret the distance value received from I/R sensor. Then it tells each LED to generate appropriate color for the distance data it received. Once one "prototype" of coding is complete, you can simply replicate those codes for three other sets of I/R sensor and LEDs.
The code is written so that the value received at each I/R sensor directly translates into the color of the lamp. Thus, the lower the distance value for each I/R sensor (i.e., when the object is further away from the lamp), the birighter blue light gets. Likewise, the higher the distance value for each I/R sensor (i.e., when the object is closer to the lamp), the brigher the red light gets. The code also allows "blending" of colors in between the colors of light. In other words, when the occupant slowly approaches the lamp, the table does not abrubtly change from complete blue to complete green to complete red. Instead, it will gradually change from strong blue to light blue to turquois to green to yellow to orange to red. Please refer back to <figure 2> of "concept studeis" section of this page for color schemes.
The code is written in Arduino software. See below for coding details.
int distance = 0;
int distance2 = 0;
int analogPin0 = 0;
int analogPin2 = 1;
int red = 11;
int blue = 10;
int green = 9;
int blue2 = 5;
int red2 = 6;
int green2 = 3;
float redVal = 0.;
float blueVal = 0.;
float greenVal = 0.;
float red2Val = 0.;
float blue2Val = 0.;
float green2Val = 0.;
void setup() {
pinMode(analogPin0, INPUT);
pinMode(analogPin2, INPUT);
pinMode(red,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);
pinMode(red2,OUTPUT);
pinMode(blue2,OUTPUT);
pinMode(green2,OUTPUT);
Serial.begin(9600); // Set up the serial communication.
}
void loop() {
distance = analogRead(analogPin0);
distance2 = analogRead(analogPin2);
Serial.print("distance value: ");
Serial.print("distnace value 2: ");
Serial.println(distance);
Serial.println(distance2);
int redInt = 0;
int blueInt = 0;
int greenInt = 0;
int red2Int = 0;
int blue2Int = 0;
int green2Int = 0;
int fadevalue = 0;
if (distance <=350 && distance >=0) {
blueVal = (350 - distance) * (255/350.);
blueInt = (int) blueVal;
}
else {
digitalWrite(blue,LOW);
}
if (distance <= 300 && distance >=50) {
greenVal = (distance - 50.) * (255/250.);
greenInt = (int) greenVal;
}
else if (distance > 300 && distance <=500){
greenVal = (500 - distance) * (255/200.);
greenInt = (int) greenVal;
}
else {
digitalWrite (green, LOW);
}
if (distance <=650 && distance >=300) {
redVal = (distance - 300.) * (255/350.);
redInt = (int) redVal;
}
else {
digitalWrite (red, LOW);
}
if (distance2 <=350 && distance2 >=0) {
blue2Val = (350 - distance2) * (255/350.);
blue2Int = (int) blue2Val;
}
else {
digitalWrite(blue2,LOW);
}
if (distance2 <= 300 && distance2 >=50) {
green2Val = (distance2 - 50.) * (255/250.);
green2Int = (int) green2Val;
}
else if (distance2 > 300 && distance2 <=500){
green2Val = (500 - distance2) * (255/200.);
green2Int = (int) green2Val;
}
else {
digitalWrite (green2, LOW);
}
if (distance2 <=650 && distance2 >=300) {
red2Val = (distance2 - 300.) * (255/350.);
red2Int = (int) red2Val;
}
else {
digitalWrite (red2, LOW);
}
analogWrite(red, redInt);
analogWrite(blue, blueInt);
analogWrite(green, greenInt);
analogWrite(red2, red2Int);
analogWrite(blue2, blue2Int);
analogWrite(green2, green2Int);
}
| « Previous Step | Download PDFView All Steps | Next Step » |











































You've got a nondescript crowd shot. Change it to a photo of the lamp--you'll get many more views.