RGB leds and LM35 problem
hello. bought arduino uno , start testing it. tried lm35 , lcd screen , work fine. stable readings , accurate. connected rgb led have problem unstable readind +/- 2 degrees. if comment out rgb outputs works ok . tested solution separate gnd lm35, capacitor @ both power supplies,rc filter lm35 etc.
anyone idea?
http://www.ledlumo.co.za/led-module-3-leds-samsung-powered-rgb-range/ led!
anyone idea?
http://www.ledlumo.co.za/led-module-3-leds-samsung-powered-rgb-range/ led!
code: [select]
#include <liquidcrystal.h>
// initialize library numbers of interface pins
liquidcrystal lcd(12, 11, 5, 4, 3, 2);
int analogread=0; //set pin a0 analog
float tempc;
int redpin= 6;
int greenpin= 9;
int bluepin= 10;
int bluetemp= 0; int greentemp= 0; int redtemp= 0; int celsius=0;
void setup() {
// set lcd's number of columns , rows:
lcd.begin(16, 2);
pinmode(redpin,output);
pinmode(greenpin,output);
pinmode(bluepin,output);
pinmode(analogread,input);
// print message lcd.
lcd.setcursor(2,0);
lcd.print("temps test 1");
lcd.setcursor(6,1);
lcd.print("lm35");
delay(2000);
}
void loop() {
analogwrite(bluepin,0);
analogwrite(greenpin,0);
analogwrite(redpin,0);
float atemp=analogread(analogread);
float milivolts=(atemp/1023)*5000; // timi apo sensor / 1023 bit * 5000mv
celsius=(milivolts/10);
tempc=celsius;
if(tempc<0){
analogwrite(bluepin, 255);}
else if(tempc>0&&tempc<=24){
bluetemp= map(tempc, 0, 24, 255, 0);
analogwrite(bluepin, bluetemp);}
else if(tempc>24){
analogwrite(bluepin, 0);}
if(tempc<15){
analogwrite(greenpin, 0);}
else if(tempc>15&&tempc<=30){
greentemp = map(tempc, 15, 30, 1, 254);
analogwrite(greenpin, greentemp);}
else if(tempc>30&&tempc<=40){
greentemp = map(tempc, 30, 40, 255, 0);
analogwrite(greenpin, greentemp);}
else if(tempc>40){
analogwrite(greenpin, 0);}
if(tempc<30){
analogwrite(redpin, 0);}
else if(tempc>=30){
redtemp= map(tempc, 30, 60, 1, 255);
analogwrite(redpin, redtemp);}
else if(tempc>60){
analogwrite(redpin, 255);}
lcd.setcursor(0,0);
lcd.print("temp:");
lcd.print(celsius);
lcd.print((char)223);
lcd.print("c");
lcd.setcursor(0,1);
lcd.print(" mv:");
lcd.print(milivolts);
delay(500);
lcd.clear();
}
the lm 35 sensitive reference voltage (more precisely, calculation use is).
the 5000 in formula refers 5v (5000 mv). if voltage supply not 5v errors. adding in rgb led may drop voltage sufficiently cause error of few deg c.
you can around calibrating sensor using internal arduino reference voltage rather nominal 5v in formula. have code in lm35 library (link libraries in footer below) can use template, or use library.
code: [select]
milivolts=(atemp/1023)*5000;
the 5000 in formula refers 5v (5000 mv). if voltage supply not 5v errors. adding in rgb led may drop voltage sufficiently cause error of few deg c.
you can around calibrating sensor using internal arduino reference voltage rather nominal 5v in formula. have code in lm35 library (link libraries in footer below) can use template, or use library.
Arduino Forum > Using Arduino > Sensors > RGB leds and LM35 problem
arduino
Comments
Post a Comment