Perancangan Alat Ukur Kualitas Udara Berbasis Arduino Mini Menggunakan Sensor MQ-135

62

LAMPIRAN

Universitas Sumatera Utara

63

#include "arduino.h"
#include
#include
#include
#include

using namespace std;

float concentration(float x) {
const float A[] = {
2.71494E+02, -3.10999E+02, 6.85051E+02, -3.47587E+02, 7.47499E+01
};
float result;

float B[4];
B[0] = x*x;
B[1] = B[0]*x;
B[2] = B[1]*x;
B[3] = B[2]*x;

result = A[0]*x+A[1]*B[0]+A[2]*B[1]+A[3]*B[2]+A[4]*B[3];
return result;
}

Universitas Sumatera Utara

64

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);
lcd.print(messages);
}

Universitas Sumatera Utara

65


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