hello everyone.
i am using TFT screen to read and display the value of analog pins.
the analog pins are connected with some gas sensors.
when i uploaded the code, i could not get the right readings.
could u help me plz
#include <stdint.h>
#include <TFTv2.h>
#include <SPI.h>
int pin22 = 22;
int pin24 = 24;
int pin26 = 26;
int pin28 = 28;
int MQ5 = A8; // must checked
int MQ2 = A9;
int MQ3 = A10;
int MQ7 = A11;
int sensorValue8 = 0;
int sensorValue9 = 0;
int sensorValue10 = 0;
int sensorValue11 = 0;
void setup()
{
//
pinMode(pin22, OUTPUT);
pinMode(pin24, OUTPUT);
pinMode(pin26, OUTPUT);
pinMode(pin28, OUTPUT);
/pinMode(sensor8, INPUT);
pinMode(sensor9, INPUT);
pinMode(sensor10, INPUT);
pinMode(sensor11, INPUT);/
//
//Serial connection.
Serial.begin(9600);
}
void loop()
{
// Read the input on analog pin 8 (named 'sensor')
sensorValue8 = analogRead(MQ5);
Serial.println("MQ5 is ");
Serial.println(sensorValue8); // print bytes to serial
Serial.println("...................... ");
delay(100);
// Print out the value you read
//Serial.println(sensorValue8, DEC);
// If sensorValue is greater than 500
if (sensorValue8 > 500) {
// Activate digital output pin 22 - the LED will light up
digitalWrite(pin22, HIGH);
}
else {
// Deactivate digital output pin 22 - the LED will not light up
digitalWrite(pin22, LOW);
delay(1000);
}
// Read the input on analog pin 9 (named 'sensor')
sensorValue9 = analogRead(MQ2);
Serial.println("MQ2 is ");
Serial.println(sensorValue9); // print bytes to serial
Serial.println("...................... ");
delay(100);
// Print out the value you read
//Serial.println(sensorValue9, DEC);
// If sensorValue is greater than 500
if (sensorValue9 > 500) {
// Activate digital output pin 24 - the LED will light up
digitalWrite(pin24, HIGH);
}
else {
// Deactivate digital output pin 24 - the LED will not light up
digitalWrite(pin24, LOW);
delay(1000);
}
// Read the input on analog pin 10 (named 'sensor')
sensorValue10 = analogRead(MQ3);
Serial.println("MQ3 is ") ;
Serial.println(sensorValue10); // print bytes to serial
Serial.println("...................... ");
delay(100);
// Print out the value you read
//Serial.println(sensorValue10, DEC);
// If sensorValue is greater than 500
if (sensorValue10 > 500) {
// Activate digital output pin 26 - the LED will light up
digitalWrite(pin26, HIGH);
}
else {
// Deactivate digital output pin 26 - the LED will not light up
digitalWrite(pin26, LOW);
delay(1000);
}
// Read the input on analog pin 11 (named 'sensor')
sensorValue11 = analogRead(MQ7);
Serial.println("MQ7 is ");
Serial.println(sensorValue11); // print bytes to serial
Serial.println("***********************************************************************************************************************");
delay(100);
// Print out the value you read
//Serial.println(sensorValue11, DEC);
// If sensorValue is greater than 500
if (sensorValue11 > 500) {
// Activate digital output pin 28 - the LED will light up
digitalWrite(pin28, HIGH);
}
else {
// Deactivate digital output pin 28 - the LED will not light up
digitalWrite(pin28, LOW);
delay(1000);
}
TFT_BL_ON; // turn on the background light
Tft.TFTinit(); // init TFT library
Tft.drawNumber(MQ2, 0, 0, 3, WHITE); // draw a integer: 1024, Location: (0, 0), size: 3, color: WHITE
Tft.drawNumber(MQ3, 0, 30, 3, WHITE); // draw a integer: 1024, Location: (0, 20), size: 3, color: WHITE
Tft.drawNumber(MQ5, 0, 60, 3, WHITE); // draw a integer: 1024, Location: (0, 50), size: 3, color: WHITH
Tft.drawNumber(MQ7, 0, 90, 3, WHITE); // draw a integer: 1024, Location: (0, 90), size:3, color: WHITE
Tft.println( MQ2, 0, 0, 3, WHITE);
};