Problem connecting arduino uno with esp8266 using software serial

hi..i am new to this iot project.. i am using nodemcu esp8266 and arduino uno for my project .. i use two source code which is one for the wifi and database and the other one is to read data from sensor. I use software serial to connect them but data from my sensor did not load into the database.. the reading only visible at serial monitor.. please help me on how to connect the esp8266 with the arduino using software serial ...

This is the code for my nodemcu board

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#define FIREBASE_HOST " "
#define FIREBASE_AUTH " "

//--------Wi-Fi Details -----//
char ssid[] = " ";  //SSID
char pass[] = " "; //Password
//--------------------------------------//


unsigned long Channel_ID = ; // Channel ID
const char * myWriteAPIKey = " "; // Write API Key
const int Field_Number_1 = 1;
const int Field_Number_2 = 2;
String value = "";
String val1,val2;
int value_1 = 0, value_2 = 0;
WiFiClient  client;

void setup()
{
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  ThingSpeak.begin(client);
  internet();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{
  internet();
  if (Serial.available() > 0)
  {
    delay(100);
    while (Serial.available() > 0)
    {
      value = Serial.readString();
      if (value[0] == '*')
      {
        if (value[5] == '#')
        {
          value_1 = ((value[1] - 0x30) * 10 + (value[2] - 0x30));
          value_2 = ((value[3] - 0x30) * 10 + (value[4] - 0x30));
        }
      }
    }
  }
  upload();
  val1 = String(value_1); 
  val2 = String(value_2);
  Firebase.setString("SMOKE/Value",val1);
  Firebase.setString("CARBON MONOXIDE/Value",val2);
}

void internet()
{
  if (WiFi.status() != WL_CONNECTED)
  {
    while (WiFi.status() != WL_CONNECTED)
    {
      WiFi.begin(ssid, pass);
      delay(5000);
    }
    }
}

void upload()
{
  ThingSpeak.writeField(Channel_ID, Field_Number_1, value_1, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_2, value_2, myWriteAPIKey);
  delay(15000);
  value = "";

}

I would suggest to study Serial Input Basics to handle the Serial input in the right way. If you are off for whatever reason after your readString() then your tests won't match.

i have include this code in the arduino code

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

and this code also

 Serial.println("CO (ppm) = "); 
 Serial.println(ppm);
 mySerial.println(ppm);

The data are not being transfer to firebase..can you explain to me why as when i compile both file there is no error ..tqq

The wiring i use is
esp8266 Arduino uno
gnd- gnd
rx -2
tx- 3

this

is not matching that

Arduino D2 is the Rx pin for the Arduino, so should be connected to pin Tx of the ESP.

Arduino D3 is the Tx pin for the Arduino, so should be connected to pin Rx of the ESP - through a voltage adapter as your ESP is likely not 5V compatible.

I connect my esp8266 using the usb port from esp to laptop ...Is it wrong to do so?

do u use some kind of dev board?

yes

GPIO 1 and 3 are used as TX and RX of the hardware Serial port (UART).
Is that where you connected the Arduino Uno?

no . i only use arduino uno

i connected the arduino uno at pin 2 and pin 3 of digital pwm

This does not mean anything (at least for me)

please take a paper and a pencil and draw lines showing your connexions and post a picture here.

[quote="J-M-L,


ost:11, topic:870515"]
please take a paper and a pencil and draw lines showing your connexions and post a picture here.
[/quote]
here is the connection ... sorry for taking your time

1 Like

thanks for a nice drawing and straight lines !

I suppose both your devices are powered through USB.

is your ESP8266 5V tolerant?

yes i powered both using usb.. my nodemcu support usb power supply

I'm afraid the NodeMCU does not support 5V input... I would not try like this, I would have a voltage adaptor in between

I suppose the IDE's Serial Monitor is closed right ? (for the ESP)

i'll try to do that..

yes

NodeMCU is a development board.

Anyway, do you tested NodeMCU standalone for sending data to FireBase? Does it work?

And do you able to test only the UART connection? offline? for example read SoftwareSerial and write to Serial, so you can see it in serial monitor of ArduinoIDE.

This tutorial covers Arduino to Arduino via Serial
covers connecting Mega to ESP8266. For Uno, use Software Serial.


or

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.