UpCycle IT – R2I INDEX:
|
Blog #11 - BackONTrack
Ah good times! Sometimes you can be stuck on a single problem for days and days, other times you can be so lucky as to come across a simple fix that has you back working in just a few hours!
Today was one of the good days.
In my last blog I was feeling a little down because while I had success with the Temperature sensor, the LCD RGB Backlight didn't work and I was concerned it would take some modifying to get it doing what it should.
Instead some more research showed me that I had not been as aware of the features of the Base Shield as I should have been.
In the yellow circle you will see a little switch for going from 3.3 V to 5V. By default it was set for 3.3V. This allowed my Temperature Sensor to function (although due to the math being based on 5v it was not correct) but my LCD would not. Switching this over to 5V quickly changed the situation to R2I being Back On Track!
Okay, let's try that Hello World example again!
I have to agree with Mr. Powers on this one!!!
Okay, so we have our LCD working! But Hello World really isn't going to do much for the R2I project, so time to modify a little of that example code and come up with something better for this purpose!
/* Hello World and Grove Temperature Sensor sketches modified for use
in displaying temperature to lcd.
*/
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 255; //BLUE
const int pinTemp = A0; //Temp
const int B = 3975; //Temp
void setup()
{
Serial.begin(9600); //Temp
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("E14-R2I Project");
delay(1000);
}
void loop()
{
int val = analogRead(pinTemp);
float resistance = (float)(1023-val)*10000/val;
float temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15;
float ftemp = temperature * (9.0/5.0) + 32.0;
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(ftemp); //TEMP
delay(100);
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
Combining elements from the Temperature sketch and the Hello World sketch and changing Hello World to blue E14-R2I Project brings the LCD to a much nicer look for what I want.
I used Green to highlight the key spots, there are a few more changes not displayed due to size of picture, but it is the main part.
So let's see what this Sketch will give us now!
Yes I definitely like this better! I had turned on my space heater as well so the combination of the heater right below my work area as well as using the correct voltage brings a tad more understandable temperatures into view.
Deciding to play with a little more code and the Grove LED option, I added a section that would check and see if the temperature was between a certain range and turn on the LED if it is.
The idea with this was a quick way to display how the temperature sensor will pickup changes and the LED will display a range of interest.
This can later be applied with the Relay and the heat element to keep the incubator at a programmed temperature and not too cold or too hot.
Here is my Temp2LCD2LED Sketch:
/* Hello World and Grove Temperature Sensor sketches modified for use
in displaying temperature to lcd. LED activated if TEMP is in a
range to simulate heat element for R2I project
*/
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 255; //BLUE
const int pinTemp = A0; //Temp
const int B = 3975; //Temp
const int pinLed = 3; //LED
void setup()
{
Serial.begin(9600); //Temp
pinMode(pinLed, OUTPUT); //LED
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("E14-R2I Project");
delay(1000);
}
void loop()
{
int val = analogRead(pinTemp); //Temp
float resistance = (float)(1023-val)*10000/val; //Temp
float temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15; //Temp
float ftemp = temperature * (9.0/5.0) + 32.0; //Temp
if ((ftemp > 79) and (ftemp < 90)) digitalWrite(pinLed, HIGH); //LED
if ((ftemp < 80) or (ftemp > 89)) digitalWrite(pinLed, LOW); //LED
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(ftemp);
delay(100);
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
So key parts now are we are watching for Temp to be less than 80 and the LED is unlit. More than 89 and the LED is unlit. But if the temp is between 80 & 89 the LED will illuminate. Easily allowing us to imagine where instead I would require the heat to come on if the temperature is too low and shut off at a certain point. That is a simpler piece of logic but I wanted to show the Sensor off with the LED. :-)
Here we can see the temperature is below 80 so the LED is unlit. Yes I know, in the incubator now I would actually want to be applying heat, but this is for demonstration purposes.
Now the temperature is greater than 80 and the LED is illuminating.
And here we have exceeded the 89 degree limit and the LED has went to an unlit state.
What I will end up doing later is implementing the LED as an external display of when the heat is on or off.
So far so good! More to come!
Top Comments