#define RLOAD 2.0 //parameters of sensor calibration #define RZERO 546 #define PARA 116.6020682 #define PARB 2.769034857 #define ledRED 9 // blue, yellow and red Leds #define ledBLUE 8 #define ledYELLOW 7 int val = 0; #include int rx=4; // pins used to send data int tx=6; SoftwareSerial bluetoothSerial(rx,tx); int ppm = 0; void setup() { bluetoothSerial.begin(9600); // begin serial pinMode(rx,INPUT); pinMode(tx,OUTPUT); //leds as outputs pinMode(ledBLUE, OUTPUT); // leds as outputs pinMode(ledYELLOW, OUTPUT); pinMode(ledRED, OUTPUT); } void loop() { val = analogRead(2); // Read sensor analog pin 2 //ppm=val; // due to lack of memory the analog imput // can be sent and the math done in the APP! float val2 = (1023 / val * 5 - 1) * RLOAD; //some math ppm = PARA * (val2 / RZERO) * (val2 / RZERO); // Value in ppm if (ppm < 750) { // Blue led on digitalWrite(ledBLUE, HIGH); digitalWrite(ledYELLOW, LOW); digitalWrite(ledRED, LOW); } if (ppm >= 751 && ppm < 1300) { //Yellow led on digitalWrite(ledBLUE, LOW); digitalWrite(ledYELLOW, HIGH); digitalWrite(ledRED, LOW); } if (ppm >= 1301) { // Red led on digitalWrite(ledBLUE, LOW); digitalWrite(ledYELLOW, LOW); digitalWrite(ledRED, HIGH); } bluetoothSerial.print(ppm); // print value delay(400); // wait 400 ms }