Hello,
I just bought Cozir Ambient CO2 Sensor from this page CozIR®-A 2,000 ppm CO2 Sensor | CO2Meter.com and try to using SoftwareSerialExample from Arduino Library. Here is how i connect the wires.
GND Sensor-> GND Arduino | N/C -> - |
3.3V Sensor -> 3.3V Arduino | N/C -> - |
Rx Sensor-> Tx Arduino Pin 11 | N/C -> - |
Tx Sensor-> Rx Arduino Pin 10 | Zero -> - |
N/C -> - | Ambient -> - |
And here is the script:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
The problem is, the output is printing "Goodnight moon!", but not with "Hello, world?". I assume that the problem is the board cannot establish connection with SoftwareSerial port.
Anyone would like to help me here? I am new in Arduino programming.
You may well be sending "Hello, world" to the sensor, but can it print and tell you what it is receiving?
jremington:
You may well be sending "Hello, world" to the sensor, but can it print and tell you what it is receiving?
Sorry if i have mistaken your question. I don't know what is supposed to be if i send command println through SoftwareSerial. Logically by its name it should print something but in this case it doesn't.
Moreover, the program never reach these two if-statement blocks, i have tested putting Serial.println each block.
The ".print" is somewhat misleading. "something.print" generally obeys certain rules in sending data to a serial port.
In fact, ".print" NEVER prints! It just sends data to some device that might print.
Serial.print(x) sends an ASCII representation of x to the TX pin, which, if it is connected to a PC or a Mac, is often the Arduino IDE serial monitor, so that you see the result on your screen.
Software serial.print(x) sends an ASCII representation of x by serial to some other pin. If that is a device, the ASCII representation of x will generally be interpreted as a command or a value.
jremington:
The ".print" is somewhat misleading. "something.print" generally obeys certain rules in sending data to a serial port.
In fact, ".print" NEVER prints! It just sends data to some device that might print.
Serial.print(x) sends an ASCII representation of x to the TX pin, which, if it is connected to a PC or a Mac, is often the Arduino IDE serial monitor, so that you see the result on your screen.
Software serial.print(x) sends an ASCII representation of x by serial to some other pin. If that is a device, the ASCII representation of x will generally be interpreted as a command or a value.
Ok, things got understandable now. Thanks for explanation.
But what does those script supposed to do?
In my serial monitor the output only show "Goodnight moon!" without any raw data from the sensor itself.
You have to do whatever is required to encourage the sensor to send data. I doubt that sending "Hello, world" will work.
Surely there is a data sheet for the sensor and/or some example code.
Edit: I did your homework for you and checked. The manual for that sensor is here: http://www.co2meters.com/Documentation/Manuals/Manual-GSS-Sensors.pdf