I have given up. Tried for a month and failed to Upload MQ2, MQ135 to thinkspeak

hi All,

I have been trying to upload the MQ2 and MQ135 data to thinkspeak server using Arduino Uno Board

What Have I done so far?

  1. Calibrated MQ2 and MQ135
  2. Able to read data from MQ135 and post it to LCD
  3. Able to manipulate MQ135 data to PPM and have smoke detection
  4. Able to read data from MQ2 and blink LED And buzzer.

What is still pending

  1. Need to measure, LPG, CO data from MQ2 and upload to LCD and then upload the data to ESP8266 using my mobile hotspot SSID. and Password.
    Then upload the data to thinkspeak server where I have created my ID with MATLAB account.
    Later Need to use MIT android App inventor to create APP.

Worst think is I dont know programming.

Please help me.

Here is the current sketch loaded.

:#include “MQ135.h”
#include <SoftwareSerial.h>
#define DEBUG true
String apiKey=
SoftwareSerial esp8266(0,1); // This makes pin 0 of Arduino as RX pin and pin 1 of Arduino as the TX pin
const int sensorPin= 0;
float air_quality;
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
pinMode(6, OUTPUT);
lcd.begin(16,2);
lcd.setCursor (0,0);
lcd.print ("ST6229609 Project ");
lcd.setCursor (0,1);
lcd.print ("IEI INDIA ");
delay(1000);
Serial.begin(115200);
esp8266.begin(115200); // your esp’s baud rate might be different
sendData(“AT+RST\r\n”,2000,DEBUG); // reset module
sendData(“AT+CWMODE=2\r\n”,1000,DEBUG); // configure as access point
sendData(“AT+CIFSR\r\n”,1000,DEBUG); // get ip address
sendData(“AT+CIPMUair_quality=1\r\n”,1000,DEBUG); // configure for multiple connections
sendData(“AT+CIPSERVER=1,80\r\n”,1000,DEBUG); // turn on server on port 80
pinMode(sensorPin, INPUT); //Gas sensor will be an input to the arduino
lcd.clear();
}

void loop()

{

MQ135 gasSensor = MQ135(A0);
float air_quality = gasSensor.getPPM();

if(esp8266.available()) // check if the esp is sending a message
{
if(esp8266.find("+IPD,"))
{
delay(1000);
int connectionId = esp8266.read()-48; /* We are subtracting 48 from the output because the read() function returns the ASCII decimal value and the first decimal number which is 0 starts at 48*/
String webpage = “

IOT Air Pollution Monitoring System

”;
webpage += “

”;
webpage+= " Air Quality is “;
webpage+= air_quality;
webpage+=” PPM";
webpage += “

”;
if (air_quality<=1000)
{
webpage+= “Fresh Air”;
}
else if(air_quality<=2000 && air_quality>=1000)
{
webpage+= “Poor Air”;
}

else if (air_quality>=2000 )
{
webpage+= “Danger! Move to Fresh Air”;
}

webpage += “

”;
String cipSend = “AT+CIPSEND=”;
cipSend += connectionId;
cipSend += “,”;
cipSend +=webpage.length();
cipSend +="\r\n";

sendData(cipSend,1000,DEBUG);
sendData(webpage,1000,DEBUG);

cipSend = “AT+CIPSEND=”;
cipSend += connectionId;
cipSend += “,”;
cipSend +=webpage.length();
cipSend +="\r\n";

String closeCommand = “AT+CIPCLOSE=”;
closeCommand+=connectionId; // append connection id
closeCommand+="\r\n";

sendData(closeCommand,3000,DEBUG);
}
}

lcd.setCursor (0, 0);
lcd.print ("Air Quality is “);
lcd.print (air_quality);
lcd.print (” PPM ");
lcd.setCursor (0,1);
if (air_quality<=1000)
{
lcd.print(“Fresh Air”);
digitalWrite(6, LOW);
}
else if( air_quality>=1000 && air_quality<=2000 )
{
lcd.print(“Poor Air, Open Windows”);
digitalWrite(6, HIGH );
}
else if (air_quality>=2000 )
{
lcd.print(“Danger! Move to Fresh Air”);
digitalWrite(5, HIGH); // turn the LED on
}
lcd.scrollDisplayLeft();
delay(1000);
}
String sendData(String command, const int timeout, boolean debug)
{
String response = “”;
esp8266.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}

:

This code is working with LCD. I have tested it with smoke and fire and CO2, duh.

As you don't mention a specific type of Arduino we all simply assume you use an Arduino UNO.

SoftwareSerial esp8266(0,1); // This makes pin 0 of Arduino as RX pin and pin 1 of Arduino as the TX pin

It's quite stupid to define a SoftwareSerial object using the pins used by the hardware serial interface. Why don't you use the hardware serial interface in the first place?

Serial.begin(115200);

It's even worse to start the hardware serial interface when you used the same pins for a software emulation before.

esp8266.begin(115200); // your esp's baud rate might be different

SoftwareSerial won't work anywhere near reliable with baudrates higher than 19200, you're trying six times that high. Simply forget it. Even if the opposite side is timing tolerant enough to handle all the timing errors this must impose, your Arduino will do nothing else than handling this serial emulation (it blocks the whole processor during complete byte transfers, no interrupts possible).

String apiKey=

Next error: don't use the String class. It fragments the memory and you don't have enough to waste it. Use C-strings instead (simple char arrays, null-terminated).

Yes,its Uno . I just corrected that.

should I make a schematics and you can help me with the code? I m all down and don't understand much of the terms.
I get one thing.

Code I've pasted needs alot modification.

What is the next step for me?
What change should I incorporate?
What info is required from me regarding the project?

from your reply.
Need to change the baud rate to 9600

That's the only take I could Get.

BUT , Can you guide me in getting entire new code with same hardware setup.

LCD same 7 8 9 10 11
mq135 A0
mq2 A1
Buzzer-No issues 6 or 5.
ESP no issues 3 as tx 4 as rx or any remaining pin.

Thats All.

Its just that, I m not much of a programming guy, yet and not able to get help from anyone in my network.

from your reply.
Need to change the baud rate to 9600

No, that's not what I meant. Get rid of SoftwareSerial and use the hardware serial interface. That way you don't have to change the hardware, just the software. For debugging you still have the LCD.

What is the next step for me?

Make one step back and simplify your setup. Remove the thingspeak/ESP code and get the two sensors running correctly with the LCD. Once you got that far, try adding the network code.

What info is required from me regarding the project?

I guess this is a school project. What specification did you get?
Post the schematics of your hardware setup.