(This may be based on other question)
Well, I'm working on my first project, A temperature controlled RGB LED (Will be covered with a ping pong ball or as a tree or as a mushroom..etc).
Anyway, I got a problem in programming the RGB with the temperature sensor..
I know how to use a 5mm RGB LED and using it codes (using adafruit's tutorials code) and how to use serial monitor with the temperature sensor (Link of the temperature sensor, here).
So all i want..
Green = between 18 and 24 degrees C
Orange = higher than 24 degrees C and fade to red when more higher
Cyan = fall below 18 degrees C and fade to blue when more colder
Sadly, I'm noob in coding using C/C++.So this is my first project (Because it's more simple than other projects i was thinking about). Also if there is any tips or guides with code i will be thankful.
I can recall someone asking this on the forum a few days before...
But my tip: start!
Get an Arduino Uno, a temperature sensor and start with the LED on the uno...
The best way of learning stuff, is to do it. When you eventually don't know what to do next, ask it here. But I (and a lot of us here) ain't going to give plug-and-pray solutions...
If you was to stick to the colour sequence used in a HSV colour wheel but only use the range between 0 degrees (red) to 240 degrees (blue) you could map the temperature reading to the HSV angle to determine your RGB LED colour.
Google for "arduino hsv to rgb code" to find code to convert HSV to RGB.
@C-F-K Well, I know about the sensor and the LED(Checking it and testing it), just all i need is how mix both sketches (replacing the serial monitor with the RGB LED). @Riva O.O I didn't think that i will enter to HSV colour wheel..Here is a simple code of the LED (by adafruit) Overview | Arduino Lesson 3. RGB LEDs | Adafruit Learning System
Well I don't see anything about a temperature input in your code.
When you have a temperature input it shouldn't be to hard to have it outputted to the RGB led. The map() function does most of the work.
int Temperature = //Fill your temperature in here...
int value;
if(Temperature <= 18)
{
value = map(Temperature, 18, 0, 255, 0);
setColor(0, value, 255); //18 degrees is cyan, below it it becomes more blue
}else if(Temperature <= 24)
{
setColor(0, 255, 0); //green
}else{
value = map(Temperature, 24, 50, 102, 0);
setColor(255, value, 0); //24 is orange, from 24 to 50 becomes red
}
Well, I checked the code, i didn't understand the first line (int Temperature), what you mean with filling the temperature?
About the temperature sensor..
Here is a tutorial that i'm using..But with some editing (The code in the tutorial is containing, when the temperature goes to a number..A LED lights up..So i remove that piece, also some variables are in Portuguese, so i will change them to English) http://www.andredrobotics.com/en/tutorials/arduino-lm35-temperature-sensor/
float Temperature = CheckTemp();
int value;
if(Temperature <= 18)
{
value = map(Temperature, 18, 0, 255, 0);
setColor(0, value, 255); //18 degrees is cyan, below it it becomes more blue
}else if(Temperature <= 24)
{
setColor(0, 255, 0); //green
}else{
value = map(Temperature, 24, 50, 102, 0);
setColor(255, value, 0); //24 is orange, from 24 to 50 becomes red
}
Inside of the map() function the float will return as an int, but that won't matter because the analogWrite() function only takes integers.
Well,i finally understood the code in reply #8 after reading it.
Just another questions in the code because i didn't use the IDE very much..
First, i think that i must put the pins variables in the first (int redpin..etc) right or wrong?
Second, must i put any codes from the temperature sensor tutorial (Serial.begin parts..etc)?
Third and final, where can i put the code that you made in reply #8? (of course after the variables..Ok but if there is any others?)
EDIT: I've found a project doing the same as i wanted.. Link: itp.nyu.edu/~bms415/blog/2011/10/stupid-pet-trick/ But using another sensor and lots of RGB LEDs..So can someone help me in changing the code?