#include "arduino.h"
#include <LiquidCrystal.h> #include <sstream>
#include <string> #include <iostream>
using namespace std;
float concentration(float x) { const float A[] = {
result = A[0]*x+A[1]*B[0]+A[2]*B[1]+A[3]*B[2]+A[4]*B[3]; return result;
char messages[5][16] = {
"Heating sensor", "64 seconds", "Autozero", "Ready!", "ppm"};
int L; float x; float x0[5]; float x_initial;
LiquidCrystal lcd(12, 11,10, 9, 8,7,6); // Wiring microcontroller - LCD:
//const int pushbutton = 8; // Pushbutton (normally open). Stops initial heating time when it is pressed. .
const int analogPin = A0; // Reads sensor voltage as a float int the interval (0-1) corresponding to (0 - 3.3V).
float sensor_value_AnalogIn = 7; // Analog output to a multimeter or datalogger (1V = 1000 ppm).
void text_screen( char messages[], int colum, int row) { lcd.setCursor( colum, row);
void setup() { lcd.begin(16,2); Serial.begin(9600); lcd.clear();
text_screen(messages[0], 0, 0); text_screen(messages[1], 0, 1); delay(2000);
for (int j = 0; j<4; j++) {
lcd.clear(); // Heating sensor 4x16 = 64 seconds text_screen(messages[0], 0, 0);
/* for (int i = 0; i<16; i++){
if (pushbutton == 1){ // Pressing pushbutton stops initial heating and enters in measuring mode.
break; }
delay(1000); }*/
}
lcd.clear();
text_screen(messages[2], 0, 0); delay(1000);
float sensor_value_AnalogIn = 7; // Analog output to a multimeter or datalogger (1V = 1000 ppm).
for (int i=0; i<5; i++) {
x0[i]= analogRead(analogPin);
delay(2000);
}
lcd.clear();
text_screen(messages[3], 0, 0); delay(2000);
}
void loop() {
x = analogRead(analogPin); Serial.println(x);
x = (x-x_initial)*3.3; // Calculate real voltage. float sensor_value_AnalogIn = x/1000;
if(x<0) x = 0;
x = concentration(x);
delayMicroseconds(100);
char buffer[10];
dtostrf(x, 10, 3, buffer);
lcd.clear();
for (int i=0; i<strlen(buffer); i+=1) {
lcd.setCursor(i,0); lcd.write(buffer[i]);
}
text_screen(messages[4], 10, 0);
}
delay(2000); }