Hi everyone, I would like to create a cup which shows the temperature by the means of 3 LEDs. The idea is to use 3 LEDs and temperature sensor (LM 35 or DS18B20, do not know which must be used) to show if the drink inside the cup is hot or not. The red LED should be on if the temperature is above 70 degrees of celcius, green - if between 45 and 70 degrees and blue if between 30 and 45. Where should I start and how to write a program? I have read at official arduino page, but I am not sure how to start writing program.
How to know that sensor to use and what is meaning of (voltage - 0.5) * 100? Is this program correct?
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ;
if (temperatureC > 70){
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, LOW);
digitalWrite(LEDpin2, LOW);
}
if (temperatureC > 45){
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, HIGH);
digitalWrite(LEDpin2, LOW);
}
if (temperatureC > 30){
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, LOW);
digitalWrite(LEDpin2, HIGH);
}
I would limit the range of each:
if (temperatureC < 30){ // all LED off
if (temperatureC >= 30 && temperature <45){
if (temperatureC >= 45 && temperature <70){
if (temperatureC > 70){
so that only 1 can be true and not all 3:
Example 95 is >30, is >45, is >70
so the last one to be tested is the one that will be true
Thanks, do I have to write any conditions before starting all "ifs"? And how about the type of thermistor? Sorry for dumb questions, this is may first time trying arduino
KristinaRan:
Thanks, do I have to write any conditions before starting all "ifs"? And how about the type of thermistor? Sorry for dumb questions, this is may first time trying arduino
You will need to read the temperature sensor, and how you do that depends entirely on the sensor itself.
You will then need to loop, reading the sensor, and selecting something to do with your if statements. To save power, you'll probably want to read the sensor and act upon it somewhat more slowly than if you just read/set, over and over.
After reading many instructions I have to write something:
int redPin = 10;
int greenPin = 9;
int bluePin=8;
int temperaturePin = 0;
void setup ()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(temperaturePin, INPUT);
Serial.begin(9600);
}
void loop ()
{
if (temperatureC < 30){
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
if (temperatureC >= 30 && temperature <45){
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
}
if (temperatureC >= 45 && temperature <70){
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
if (temperatureC > 70){
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
}
I am not sure is it right or wrong. Also, what should i write in order to save the energy of battery? Do I need to add something else? Thanks in advance.
If I want to recalculate values after 5 seconds, should I add delay(5000) at the end of code, or should I write it after every if statement?
-
Add Code tags, its makes your code infinitely more readable.
-
In terms of using a delay, ideally you don't, and you follow Blink without Delay example. However, if you are looking for the quick answer, you just would let it happen once per loop, probably at the end. Each time the program encounters the delay() function, it will delay for that much time, doing absolutely nothing.
Another thing you can do is get an RGB LED which is all 3 colors in one, and that way you can get some cool color fading effects as you learn more.
To save power, you'll probably want to read the sensor and act upon it somewhat more slowly than if you just read/set, over and over.
[/quote]
So how should I do this? I am sorry for such questions, but I am not an engineer, I try to do some project for myself.
And what is code tag? Is it explanation of the line meaning in the programme?
If I am using LM35 as temperature sensor, do I have to insert:
value = analogRead(temperaturePin);
temperatureC = (5value100/1024); //to convert analog input into temperature
Serial.print (temperatureC);
or is it enough to write “analogRead (LM35)" and it takes data from the library?
I have modified my code, could anyone tell me if it is any good?
int redPin = 10; //Red LED = Pin 10
int greenPin = 9; //Green LED = Pin 9
int bluePin=8; //Blue LED = Pin 8
int temperaturePin = 0; //LM35 is connected to analog Pin 0
float temperatureC = 0.0; //Value which will be calculated in process
int value=0; //Variable to store sensor’s values
void setup () {
pinMode(redPin, OUTPUT); //Digital OUTPUT Pin for Red LED
pinMode(greenPin, OUTPUT); //Digital OUTPUT Pin for Green LED
pinMode(bluePin, OUTPUT); //Digital OUTPUT Pin for Blue LED
pinMode(temperaturePin, INPUT); //Analog INPUT Pin for LM35
Serial.begin(9600); /Baud rate
}
void loop (){ //For looping the process bellow
value = analogRead(temperaturePin); //For reading the value from sensor LM35
temperatureC = (5*value*100/1024); //Converting voltage to temperature
Serial.printIn (temperatureC); //Printing temperature value on serial screen
if (temperatureC < 30){ //Checking if temperature is bellow 30 degrees
digitalWrite(redPin, LOW); //If yes – all LEDs of
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
if (temperatureC >= 30 && temperature <45){ //If conditions are satisfied, then...
digitalWrite(redPin, LOW); //Red LED of
digitalWrite(greenPin, LOW); //Green LED of
digitalWrite(bluePin, HIGH); //Blue LED on
}
if (temperatureC >= 45 && temperature <70){
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
if (temperatureC > 70){
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
delay(5000); //Wait for 5 seconds
}
Code for mug.pdf (182 KB)
KristinaRan:
Hi everyone, I would like to create a cup which shows the temperature by the means of 3 LEDs. The idea is to use 3 LEDs and temperature sensor (LM 35 or DS18B20, do not know which must be used) to show if the drink inside the cup is hot or not. The red LED should be on if the temperature is above 70 degrees of celcius, green - if between 45 and 70 degrees and blue if between 30 and 45. Where should I start and how to write a program? I have read at official arduino page, but I am not sure how to start writing program.
I somewhat do this in my tiny85 program, showing the LEDs only if there is a change from sleep to wake-up. Anyway, rip out anything useful to you!
http://www.hackster.io/rayburne/hot-yet
Ray