Color-changing Lamp Via Temperature Input

Color-changing Lamp Via Temperature Input © GPL3+

This project detects changes in temperature based on your specifications, and then changes the color of a LED to the color of your choosing.

  • 2,740 views
  • 2 comments
  • 17 respects

Components and supplies

About this project

This project is a simple combination of Projects 3 and 4 from the starter kit. There is a note at the end of Project 4 asking us to think about different inputs to the color changing lamp's LED pins. I thought that lighting up different LED's in the Love-o-meter was pretty cool, but the same idea could be integrated into PWM for each pin with some "if" statements. If anyone has input on how to make the transition from color to color as the temperature rises more smooth, please comment! I would like to have this feature on possible future projects.

Anyways, I'm sure this project has been done before, but I thought it may be a good idea to practice sharing my projects as well.

In the main picture, use a shot glass with holes in it as the cover to the LED; they recommend a ping-pong ball with a hole in it to diffuse the light.

Enjoy!

Code

Temperature Incremental ChangesArduino
Change the if statements to change the color and what temperatures your light will change out.
const int greenLEDPin = 9;    // LED connected to digital pin 9
const int redLEDPin = 10;     // LED connected to digital pin 10
const int blueLEDPin = 11;    // LED connected to digital pin 11

// room temperature in Celcius
const float baselineTemp = 20.0;

const float baselineSens = 144;
const int TempSensor = A0;  // pin with the temp sensor

int redValue = 0; // value to write to the red LED
int greenValue = 0; // value to write to the green LED
int blueValue = 0; // value to write to the blue LED

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);

  // set the digital pins as outputs
  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop() {

  // read the value on AnalogIn pin 0
  // and store it in a variable
  int sensorVal = analogRead(TempSensor);
  delay(5);
  //Serial.println(sensorVal);
   // convert the ADC reading to voltage
   // convert temp sensor reading from 0-1024 to analogWrite value from 0-255 
  float voltage = (sensorVal / 1024.0) * 5.0;
 
  
    // Send the voltage level out the Serial port
  Serial.print("Volts: ");
  Serial.print(voltage);
  
  // convert the voltage to temperature in degrees C
  // the sensor changes 10 mV per degree
  // the datasheet says there's a 500 mV offset
  // ((volatge - 500mV) times 100)
  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  if (temperature < baselineTemp) {
  analogWrite(redLEDPin, 0);
  analogWrite(greenLEDPin, 127);
  analogWrite(blueLEDPin, 0);
  }else if (temperature >= baselineTemp && temperature < baselineTemp + 2) {
  analogWrite(redLEDPin, 0);
  analogWrite(greenLEDPin, 255);
  analogWrite(blueLEDPin, 0);
  } // if the temperature rises 2-4 degrees, turn an LED on
  else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
  analogWrite(redLEDPin, 0);
  analogWrite(greenLEDPin, 0);
  analogWrite(blueLEDPin, 255);
  } // if the temperature rises 4-6 degrees, turn a second LED on
  else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) {
  analogWrite(redLEDPin, 127);
  analogWrite(greenLEDPin, 0);
  analogWrite(blueLEDPin, 127);
  } // if the temperature rises more than 6 degrees, turn all LEDs on
  else if (temperature >= baselineTemp + 6) {
  analogWrite(redLEDPin, 255);
  analogWrite(greenLEDPin, 0);
  analogWrite(blueLEDPin, 0);
  }
  delay(1);


}

Schematics

Temperature Sensing LED
The idea is to have the temperature sensor outside (wherever you want to detect changes in temperature) and then have an indicator (LED) in a comfortable location
temp_sensor_2sFt7NQBDe.fzz

Comments

Author

Mattcurrentjr
mattcurrentjr
  • 1 project
  • 2 followers

Additional contributors

Published on

June 10, 2017

Members who respect this project

De69a62a2b35333cd5fa834c6f202b80 qq25e5259b25be25e72589258720160323205203 uugfypsuzuDefaultDefault10544347 818463551570151 3885757170575229219 n1797372 1984212661802910 2662297679677468856 nDefaultDefault

and 11 others

See similar projects
you might like

Similar projects you might like

Arduino Temperature - Humidity - Rain Sensor

Project showcase by Rick_Findus

  • 7,412 views
  • 6 comments
  • 13 respects

Portable Temperature Station

Project tutorial by Isaac100

  • 8,066 views
  • 8 comments
  • 35 respects

Temperature and Humidity Data Logger

Project tutorial by Wimpie van den Berg

  • 23,409 views
  • 2 comments
  • 22 respects

Temperature sensor

Project tutorial by Grant

  • 12,269 views
  • 6 comments
  • 30 respects

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 9,056 views
  • 1 comment
  • 17 respects
Add projectSign up / Login