Interfacing NDIR C02 with SoftwareSerial

Dear Sir,
I am testing my NDIR C02 witn UNO R3. When I test the sensor by using analog input of UNO R3, i can get the readings but when I tried to use UART / serial it seem does not work.
The specification of the NDIR C02 as follows:
Inputs and outputs

  1. Power supply DC5V+/-5%
  2. Working current 70mA,max 120mA
  3. Measuring output linearity output
  4. Output voltage 0.8-4VDC (can be customized)
  5. Digital output UART Data bit:8; Stop bit:1; Check bit :null
  6. Standard baud rate 9600bps

The sketch is as follows:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); // RX, TX mySerial(10, 11)
int incomingByte;
int c;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Goodnight moon!");

// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}

void loop() // run over and over
{
if (Serial.available())
Serial.println("Serial Is Available");
if (mySerial.available()>0)
{
//Serial.write(mySerial.read());
Serial.println("MYSERIAL Is LONG");
incomingByte = mySerial.read();
Serial.println(incomingByte);
}
else
{
Serial.println("MYSERIAL Is ZERO");
incomingByte = mySerial.read();
Serial.println(incomingByte);
}
if (mySerial.isListening()) {
Serial.println("MYSERIAL is listening!");
}
else
{
Serial.println ("MYSERIAL is NOT listening");
}

c = mySerial.read();
Serial.print("c:");
Serial.println (c);
if (mySerial.overflow()) {
Serial.println("SoftwareSerial overflow!");
}
else
{
Serial.println("SoftwareSerial DOES NOT overflow!");
}
//mySerial.write(Serial.read());
delay(3000);
}
The result display on the monitor as follows:
Goodnight moon!
----------first loop ----
MYSERIAL Is ZERO
-1
MYSERIAL is listening!
c:-1
SoftwareSerial DOES NOT overflow!
-------second loop-----
MYSERIAL Is LONG
0
MYSERIAL is listening!
c:-1
SoftwareSerial DOES NOT overflow!
-------- subsequent loops-----
MYSERIAL Is ZERO
-1
MYSERIAL is listening!
c:-1
SoftwareSerial DOES NOT overflow!

My questions are

  1. Why nothing happens to mySerial.println("Hello, world?");
  2. Why nothing happens to Serial.println("Serial is Available) in the loop()
  3. mySerial.available()>0 only hapens once, that is for the second loops, why not for the entire loop?
  4. How to get the readings from the sensor by using the SofrwareSerial?
  1. Please edit your post to insert code tags around your code (highlight the code and use the # button above the editing box).

  2. Link to the datasheet for your CO2 sensor.

  3. Tell us how you have connected the sensor to the Arduino.

  4. Why are you are sending "Hello world" to mySerial? What do you expect to happen? What do you have pin 11 connected to?

THank you DC42 for your kind response.
The code used as follow:

#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); // RX, TX mySerial(10, 11)
int incomingByte;
int c;
void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Goodnight moon!");

  // define pin modes for tx, rx:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (Serial.available())
    Serial.println("Serial Is Available");
  if (mySerial.available()>0)
  {
    //Serial.write(mySerial.read());
    Serial.println("MYSERIAL Is LONG");
    incomingByte = mySerial.read();
    Serial.println(incomingByte);
  }
  else
  {
    Serial.println("MYSERIAL Is ZERO");
    incomingByte = mySerial.read();
    Serial.println(incomingByte); 
  } 
  if (mySerial.isListening()) {
    Serial.println("MYSERIAL is listening!");
  }
  else
  { 
    Serial.println ("MYSERIAL is NOT listening");
  } 

  c = mySerial.read();
  Serial.print("c:");
  Serial.println (c);
  if (mySerial.overflow()) {
    Serial.println("SoftwareSerial overflow!");
  }
  else
  {
    Serial.println("SoftwareSerial DOES NOT overflow!");
  }
  //mySerial.write(Serial.read());
  delay(3000);
}

The supplier do not publish data sheet, only the feature of the sensor. http://en.gassensor.com.cn/products.asp?class_id=344
The sensor is connected directly to the UNO, that is rxPin (pin10) to UART RX port and txPin (pin 11) to UART TX port.
I want to test mySerial during setup(), so I think it is appropriate to mySerial.println("Hello, world?"). Futher more I just follow the example given by arduino.refernce.SoftwareSerial.Example.

mohdrais:
The sensor is connected directly to the UNO, that is rxPin (pin10) to UART RX port and txPin (pin 11) to UART TX port.

That's the wrong way round. Sensor Tx pin must go to Uno Rx pin (10) and vice versa.

mohdrais:
I want to test mySerial during setup(), so I think it is appropriate to mySerial.println("Hello, world?").

How do you expect the sensor to respond when it receives "Hello word"? Was the sensor supplied with a manual describing what input it accepts and what output it produces?

btw i see that the sensor has an analog output as well. You could just connect that to an Arduino analog input instead of using the serial interface.