I am trying to make an incubator controller for exotic chicken eggs, so far the code I have done works great. However when I ajust the max and min temp with the pot, I can only adjust to whole numbers, I need some help getting it to be able to adjust in decimel like: 94.1, 94.2, 94.3 ect ect. right now I can only adjust like this: 94, 95, 96, 97 ect ect?
//-------Import needed libraries
#include <OneWire.h> //-------Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <DallasTemperature.h> //-------Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <Wire.h> //-------comes with arduino IDE
#include <LCD.h> //-------Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <LiquidCrystal_I2C.h> //-------Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <DHT.h>
#include <Time.h>
time_t elapsedTime;
//-------Declare Constants and Pin Numbers
#define ONE_WIRE_BUS 2 //-------Data wire is plugged into port 2 on the Arduino (can be changed)
#define I2C_ADDR 0x27 //-------Define I2C Address for the 20x4 i2c lcd
#define DHTPIN 3 //-------goes to data pin on dht22 sensor
#define DHTTYPE DHT22
#define HEAT 7 //-------goes to 4ch relay board pin 7 for fan and heat
#define EXTRA 8 // extra pin for relay board, future expansion
const int sensorPin = A0; //-------analog pin reading from potentiometer
//-------Declare objects
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass address of our oneWire instance to Dallas Temperature.
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Start the LCD display library
//-------Declare Variables
int sensorValue = 0; // variable to store the value coming from the sensor
int settempMax = 105; // variable to store temp desired
int settempMin = 95; // variable to store temp desired
const int switchPin = 4; // To switch between min and max
int switchReading;
//-------Assign the addresses of your 1-Wire temp sensors, See the tutorial on how to obtain these addresses: http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress Probe01 = { 0x28, 0x40, 0x45, 0x7E, 0x06, 0x00, 0x00, 0x3C };
DeviceAddress Probe02 = { 0x28, 0xEC, 0x5E, 0x7E, 0x06, 0x00, 0x00, 0x11 };
float tempC, tempF;
DHT dht(DHTPIN, DHTTYPE); //-------Initialize DHT sensor for normal 16mhz Arduino
void getTemperature(DeviceAddress deviceAddress)
{
sensors.requestTemperatures();
tempC = sensors.getTempC(deviceAddress);
tempF = DallasTemperature::toFahrenheit(tempC);
}
//-------setup only runs once
void setup()
{
//-------Initialize the pins
pinMode(HEAT, OUTPUT);
digitalWrite(HEAT, HIGH);
pinMode(switchPin,INPUT);
pinMode(EXTRA, OUTPUT);
digitalWrite(switchPin, HIGH);
digitalWrite(EXTRA, HIGH);
//-------Initialize the Temperature measurement library
sensors.begin();
sensors.setResolution(Probe01, 9); //-------set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Probe02, 9); //-------set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
dht.begin(); //-------initialize the dht sensor
//-------Initialize the lcd, display startup message
lcd.begin (20,4); //-------begin lcd for a 20 characters, 4 line display
lcd.setCursor(6,0); //-------Start at character 6 on line 0
lcd.print("Welcome");
delay(1000);
lcd.setCursor(9,1);
lcd.print("To");
delay(1000);
lcd.setCursor(6,2);
lcd.print("CHUCK'S");
delay(1000);
lcd.setCursor(0,3);
lcd.print("Incubator Controler");
delay(2000);
//-------setup static display for temp probe data
lcd.clear();
lcd.setCursor(0,0);
lcd.print("EGG");
lcd.setCursor(0,1);
lcd.print("AIR");
lcd.setCursor(0,2);
lcd.print("Rh%");
lcd.setCursor(0,3);
lcd.print("OUT");
lcd.setCursor(11,0);
lcd.print("SetM");
lcd.setCursor(11,1);
lcd.print("Setm");
}
//-------end setup
//-------LOOP: RUNS CONSTANTLY
void loop()
{
elapsedTime = now();
lcd.setCursor (11,3);
lcd.print("DAYS "); // elapsed days
lcd.print(elapsedTime / SECS_PER_DAY);
lcd.setCursor(4,0); //-------Start at character 0 on line 0
displayTemperature(Probe01); //-------print temp from probe 1 on lcd (inside incubator temp)
lcd.setCursor(4,3); //-------Start at character 0 on line 1
displayTemperature(Probe02); //-------print temp from probe 2 on lcd (outside temp out)
int sensorValue = analogRead(sensorPin);
switchReading = digitalRead(switchPin);// represents digitalRead(SwitchPin);
if (switchReading == LOW)
{
settempMax = map(sensorValue, 0, 1023.0, 95, 104);
lcd.setCursor(17,0);
lcd.print(settempMax);
}
else
{
settempMin = map(sensorValue, 0, 1023, 95, 104);
lcd.setCursor(17,1);
lcd.print(settempMin);
}
if (settempMax < 100)
{
lcd.setCursor(19,0);
lcd.print(".");
}
if (settempMin < 100)
{
lcd.setCursor(19,1);
lcd.print(".");
}
getTemperature(Probe01);
{
if (tempF < settempMin) // IF TEMP ON SENSOR0 (probe01) IS less THAN settempm (reading from potentiometer) turn on heat
{
digitalWrite(HEAT, LOW);
lcd.setCursor(11,2);
lcd.print("Heat ON.");
}
else if (tempF > settempMax) // if temp on sensor 0 probe 01 is greater then settempM (reading from potentiometer) turn off heat
{
digitalWrite(HEAT,HIGH);
lcd.setCursor(11,2);
lcd.print("Heat OFF ");
}
}
int h = dht.readHumidity(); //-------read dht sensor humidity
int f = dht.readTemperature(true); // Read dht temperature as Fahrenheit
if (isnan(h) || isnan(f))
{
lcd.setCursor(13,2);
lcd.print("");
lcd.setCursor(13,3);
lcd.print("");
}
//-------indoor temp display from dht22
lcd.setCursor(4,1);
lcd.print(f);
//-------indoor relative humidity display from dht22
lcd.setCursor(4,2);
lcd.print(h);
}
//-------end main loop
//-------Declare User-written Functions
void displayTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) // Measurement failed or no device found
{
lcd.setCursor(13,2);
lcd.print(""); //-------print temp err on the lcd
lcd.setCursor(13,3);
lcd.print("");
}
else
{
lcd.print(DallasTemperature::toFahrenheit(tempC)); // Convert to F
}
}// End printTemperature
//*********( THE END )***********