Temperature-controlled RGB LED

Temperature-controlled RGB LED

A simple Arduino assembly that checks temperature and sets an RGB LED from blue to red.

  • 32,338 views
  • 9 comments
  • 46 respects

Components and supplies

About this project

About this project

This is my first Arduino project. I got inspired by Ray's "Hot yet" project. I'm thinking this could be used for knowing when your hot beverage is at a right temperature to be drunk, or warning when it's getting too cold. Could also work for drinks that are better served chilled!

Demo

Code

sketch.cC/C++
sketch.c
#define TEMP_PIN A0
#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11

int adc = 0;
int blue = 0, red = 0;

double ReadThermistor(int adc) {

  double resistance = ((1024.0/adc) - 1);    //calculate from voltage divider, for 10k resistor
  double Temp = log(resistance);

  // calculate the temperature, in K, using 4 thermistor model/material specific parameters A, B, C, D
  // here we use the values for the Sparkfun/Hactronics version of the Vishay 10k NTC thermistor
  Temp = 1 / (0.003354016 + 0.0002569850 * Temp + 0.000002620131 * Temp * Temp + 0.00000006383091 * Temp * Temp * Temp);
  Temp = Temp - 273.15;            // Convert Kelvin to Celsius
  return Temp;
}

void setLED(int blue, int red){
  analogWrite(BLUE_PIN, blue);
  analogWrite(RED_PIN, red);
}

void setup(){
  Serial.begin(9600);
  pinMode(BLUE_PIN, OUTPUT); 
  pinMode(RED_PIN, OUTPUT); 
  pinMode(GREEN_PIN, OUTPUT);  
  pinMode(TEMP_PIN, INPUT);
}

void loop(){
  adc = analogRead(TEMP_PIN);
  int temp = ReadThermistor(adc);
  Serial.println(temp);
  
  red = map(temp, 20, 40, 0, 255);
  blue = 255 - red;
  
  setLED(blue, red);
}

Schematics

Wiring
Img 20140427 114301

Comments

Similar projects you might like

LED Emergency Lights using WS2812 RGB LED Module

Project tutorial by bigboystoys13

  • 22,756 views
  • 10 comments
  • 42 respects

How to Use an RGB LED

by MisterBotBreak

  • 12,772 views
  • 5 comments
  • 26 respects

Motor Controlled with Arduino

by Benjamin Larralde

  • 37,663 views
  • 26 comments
  • 92 respects

Smooth RGB LED Transitions with Johnny-Five

by Iain

  • 29,977 views
  • 4 comments
  • 45 respects

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO

Project tutorial by Giovanni Gentile

  • 11,310 views
  • 1 comment
  • 19 respects

Programming 8x8 LED Matrix

by SAnwandter1

  • 363,518 views
  • 64 comments
  • 302 respects
Add projectSign up / Login