Hi friends
I have a project that uses the arduino uno, a relay module, AD8495 K type amplifier and a lcd.
I worked for some time with lm35 sensor and it works fair....now I would replace it with AD8495 for use k type thermocouple.
My problem is during the calibration I use the 5 / 1023 and get the voltages, I take 3 points of temp and calculate the calibration rule and it gives a good R value, but after input the calib equation, the readings are very far from the real value.
Then I upload a simple program with INT function to read the A0 and after the same process I get about 1 degree of error.
I suspect the FLOAT function, but I use it to get more decimal places.
Please help me to correct this code seems the var "temp" and "tempPin" can be resumed to one
The original code is
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
//source: http://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/
int row = 16; // <<----- My LCD was 16x2
int column = 2; // <<----- My LCD was 16x2
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, BACKLIGHT_PIN, POSITIVE);
float tempPin = A0; // the output pin of K thermocouple
float temp;
int led = 8; // led pin
float templaw=5; // the law ramp
void setup() {
lcd.begin (row,column); // initialize lcd and turn on backlight
lcd.home (); // go home
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
Serial.begin(9600);
}
void loop() {
temp = readTemp(); // get the temperature
if (temp < templaw - 1) {
templaw = templaw + 0;
} else {
templaw = templaw + 0.083; //1seg em 1seg verifica
}
if(temp > templaw) { // if temp is higher than tempMax
digitalWrite(led, LOW); // turn on led
} else { // else turn of led
digitalWrite(led, HIGH);
}
Serial.print("TEMP: ");
Serial.println(temp, 4); // display the temperature
lcd.setCursor(1, 0); // Set LCD cursor position (column, row)
lcd.print("TEMP: "); // Print text to LCD
lcd.print (temp, 4);
lcd.setCursor(1, 1); // Set LCD cursor position (column,row)
lcd.print("TEMPLAW: "); // Print text to LCD
lcd.print (templaw);
Serial.print("TEMPLAW: ");
Serial.println(templaw);
delay(1000);
}
float readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return (temp * (5.0 / 1023.0)) * 196.8 - 248.6;//calib dez2018
}
The simple analog read program is (i only use the A0)
/*
ReadAnalogVoltage
Reads an analog input on pin 0 to 3, converts it to voltage,
and prints the result to the serial monitor.cpalha 04dez2017
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);
int sensorValue3 = analogRead(A3);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage0 = sensorValue0 * (5.0 / 1023.0) * 192.2 - 251.42;//calib ago2018
float voltage1 = sensorValue1 * (5.0 / 1023.0);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
float voltage3 = sensorValue3 * (5.0 / 1023.0);
// print out the value you read:
Serial.print(voltage0, 1);
Serial.print(" ");
Serial.print(voltage1, 4);
Serial.print(" ");
Serial.print(voltage2, 4);
Serial.print(" ");
Serial.println(voltage3, 4);
delay(10000);
}