There is an issue with the addition of analog_value. The addition always results in 0. You can observe this by printing out analog_value in the loop. Not sure why this is though. The work-around is to declare analog_value as a global variable as shown in the Sketch below: /* * Program to measure the value of R0 for a know RL at fresh air condition * Program by: B.Aswinth Raj * Website: www.circuitdigest.com * Dated: 28-12-2017 */ //This program works best at a fresh air room with temperaure Temp: 20℃, Humidity: 65%, O2 concentration 21% and when the value of Rl is 47K #define RL 47 //The value of resistor RL is 47K void setup() //Runs only once { Serial.begin(115200); //Initialise serial COM for displaying the value } float analog_value; void loop() { // static float analog_value; float VRL; float Rs; float Ro; Serial.println("Test cycle:"); for(int test_cycle = 1 ; test_cycle <= 500 ; test_cycle++) //Read the analog output of the sensor for 200 times { analog_value = analog_value + analogRead(27);; //add the values for 200 Serial.println(analog_value); } analog_value = analog_value/500.0; //Take average VRL = analog_value*(5.0/1023.0); //Convert analog value to voltage //RS = ((Vc/VRL)-1)*RL is the formulae we obtained from datasheet Rs = ((5.0/VRL)-1) * RL; //RS/RO is 3.6 as we obtained from graph of datasheet Ro = Rs/3.6; Serial.print("Ro at fresh air = "); Serial.println(Ro); //Display calculated Ro delay(1000); //delay of 1sec }
↧