Dear all from several tests i managed to have a range of adc values, having different equations in order to achieve accurate results....
My code is this:
#include <LiquidCrystal.h>
//#include <math.h>
#define powf
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
const int analogInPin = A0;
int count = 300;
double pow (double __x, double __y);
void setup()
{
lcd.begin(16,2); //initialise LCD
Serial.begin(9600);
setupA();
}
void loop()
{
}
void setupA()
{
lcd.print("TESTING"); //display on lcd
delay(2000);
digitalWrite(13,LOW); //RELAY CLOSED
read_average_analog(250);
}
/* Sample analog in pin a given number of times and
* return the floating point mean of the samples.
* The summing of samples is done using a long, which
* is subject to overflow for very large counts.
*/
double read_average_analog(int count)
{
int i;
long sum = 0;
float average;
float voltage;
float conversiontogas;
int gas;
float calibration;
sum = 0;
for (i = 0; i < count; i++)
{
sum += analogRead(analogInPin);
Serial.print(sum, 3);
Serial.print("\n");
}
average = ((sum)/(count));
int conv_average = average;
//voltage = average*(0.00469592);
Serial.print("A");
Serial.println(average, 3);
//Serial.println(voltage, 3);
//calibration = ((average)*(21.8115942) - (611.1594203));
if((conv_average >= 380) && (conv_average <= 685) )
{
calibration = ((conv_average)*(21.438) - (583.2));
}
else if((conv_average <= 684) && (conv_average <= 900))
{
double test = pow(conv_average, 1.0308);
//calibration = ((5783)*(double exp(double (conv_average)*(0.0013))));
}
//calibration = ((average)*(21.277) - (501.47)); IDEAL
//conversiontogas = ((4621.2)*(voltage) - 607.96);
gas = conversiontogas;
Serial.println(calibration);
//Serial.println(gas);
return gas;
}
Since i dont have the library math.h i tried to define it and a function but of no use...
All i need is this
from range ADC12BIT - 381 - 684 ; y = 21.438x - 583.2 (SOLVED)
684 - 899; y = 16.841x^1.0308
899 - 1023; y = 5.484x^1.10161
I JUST NEED TO KNOW HOW TO USE POWER OF in code....
tnx