Okay first off I'm new to this whole thing like less then a week old, but willing to learn.
I have made a setup with 2 thermistors and a DHT11. One thermistor is on a mini board and covered by a small Tupperware bowl to keep the moving air from ceasing big jumps. The other is on the main big board with the 16*2 LCD that one is not covered. The DHT11 is plugged strait into the Mega 2650 pins both data and the power.
Be that as it may it works very well. What I would like is if some of you could look at my code and help me get it organized better.
The 2nd thing is to see if you could help show me how to make it work with the millis() function and help me understand how it works and why it works so that I can better use it from here on in.
3rd I wanted to see if it's possible to make a custom library that hold a lot of the stuff in this code that really should be function calls like in a real app would do. If so could you please point me to some good places to start reading on how to go about doing that?
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal.h>
int tim = 50; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13); // set the pins for the LCD
byte customChar[] = { //this is where I put my hand made deg symbol I made
B00100,
B01010,
B01010,
B00100,
B00000,
B00000,
B00000,
B00000
};
void getTemp(float * t)
{
// Converts input from a thermistor voltage divider to a temperature value.
// The voltage divider consists of thermistor Rt and series resistor R0.
// The value of R0 is equal to the thermistor resistance at T0.
// You must set the following constants:
// adcMax ( ADC full range value )
// analogPin (Arduino analog input pin)
// invBeta (inverse of the thermistor Beta value supplied by manufacturer).
// Use Arduino's default reference voltage (5V or 3.3V) with this module.
//
const int analogPin = A0; // analog pin for fist thermistor
const int analogPin2 = A1; //analog pin for 2nd thermistor
const float invBeta = 1.00 / 3470; // This is what my datasheat for my thermistor's says what it's beta is
const float adcMax = 1024.00; // I know that most say that 1023 is the right setting for this but in the Arduino ref says "The default analogRead() resolution for these boards is 10 bits" so that is why I used the 1024 here
const float invT0 = 1.00 / 298.15; // room temp in Kelvin
int adcVal, i, numSamples = 50; // sets how many reading to get from the thermistor before AVG it to stop big jumps
float K, C, F;
int adcVal2, x, numSamples2 = 50; // sets how many reading to get from the thermistor before AVG it to stop big jumps
float K2, C2, F2;
adcVal = 0;
adcVal2 = 0;
for (i = 0; i < numSamples; i++)
{
adcVal = adcVal + analogRead(analogPin);
delay(100);
}
for (x = 0; x < numSamples; x++)
{
adcVal2 = adcVal2 + analogRead(analogPin2);
delay(100);
}
adcVal = adcVal / 50;
adcVal2 = adcVal2 / 50;
K = 1.00 / (invT0 + invBeta * (log ( adcMax / (float) adcVal - 1.00)));
K2 = 1.00 / (invT0 + invBeta * (log ( adcMax / (float) adcVal2 - 1.00)));
// C = K - 273.15; // convert to Celsius
// F = ((9.0 * C) / 5.00) + 32.00; // convert to Fahrenheit
F = (K - 273.15) * 9.00 / 5.00 + 32.00; // Just coverted from Kelvin to Farenheit. I don't need Celsius
F2 = (K2 - 273.15) * 9.00 / 5.00 + 32.00; // Just coverted from Kelvin to Farenheit. I don't need Celsius
t[2] = (F + F2) / 2.00; // Doing avg on the two thermistors
t[2] = F2; // Storing the avg in a new varable
return;
}
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.createChar(0, customChar); // Making the custum Charator I made
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
analogReference(DEFAULT); // used for the thermistors
Serial.begin(9600);
dht.begin(); // To get the DHT11 up and going
}
void loop()
{
float temp[3];
getTemp(temp);
float h = dht.readHumidity(); // Reads the DHT11's Humidity
float t = dht.readTemperature(true); // Reads the DHT's Temp in Farenheit
float f = (temp[2] + t) / 2; // set a new varable of f to hold the AVG of the AVG of the thermistors and the DHT11's Temp
float hi = dht.computeHeatIndex(f, h); // have the DHT libary take the varable t and the varable h to get the Feels like or Heat Index
lcd.setCursor(2, 0); // set the cursor to column 2, line 0
lcd.print("Temp: "); // prints "Temp: " to the LCD
lcd.print(f, 1); // prints varable "f" with one point ie 75.5 where the varable may hold 75.53 to LCD
lcd.write((byte)0); // prints the custum Charator I made to LCD
lcd.print("F"); // Prints "F" to LCD
lcd.setCursor(0, 1); // set the to column 0, line 1
lcd.print("RH: "); // Prints "RH: " to LCD
lcd.print(h, 0); // Prints varable "h" with not point as the number never has any point numbers to LCD
lcd.print("%"); // Prints "%" to LCD
lcd.print(" HI: "); //Prints " HI: " to LCD
lcd.print(hi, 1); //Prints varable hi with a 1 point res to LCD
// Serial output so that it can be logged to a text file on deasktop and then be goton over http to use with tasker on my andriod tablet
Serial.print(f, 1); // prints varable "f" with 1 point place ie 75.54 now shows as 75.5
Serial.print(","); // prints a "," betwen outputs on the same line
// Serial.println(t, 1); // just here for trouble shooting
Serial.print(h, 0); // prints varable "h" with a whole number no point places ie 44.00 now it just 44
Serial.print(","); // prints a "," betwen outputs on the same line
Serial.println(hi, 1); // prints vabale "hi" with one point place ie 75.54 now it just 75.5
delay(1500); // to give the DHT11 time to get it's next reading before relooping
return;
}
Thank you for your time and patience with me as I learn and you all teach me.