#include <Wire.h>
#include <NDIR_I2C.h>
NDIR_I2C mySensor(0x4D); //Adaptor's I2C address (7-bit, default: 0x4D)
void setup()
{
Serial.begin(9600);
if (mySensor.begin()) {
Serial.println("Wait 10 seconds for sensor initialization...");
delay(10000);
} else {
Serial.println("ERROR: Failed to connect to the sensor.");
while(1);
}
}
void loop() {
if (mySensor.measure()) {
Serial.print("CO2 Concentration is ");
Serial.print(mySensor.ppm);
Serial.println("ppm");
} else {
Serial.println("Sensor communication error.");
}
delay(1000);
}
I have the switch in the I2C position and wires connected as shown on the attached pictures:
When I open the serial monitor the LED on arduino flashes a bit, but no output is given on the serial monitor.
If I remove a wire from analog pins A4 or A5 the serial monitor displays the text "ERROR: Failed to connect to the sensor.". The same text is displayed if the wires from the I2C/UART interface board points SDA and SCL are connected elsewhere on the Arduino Uno board.
The image shows the SCL/SDA wires the wrong way round. It should be A4 = SDA, A5 = SCL
Does your power supply deliver enough current as the web site you linked says...
NOTE: Your USB2.0 port on your PC may not be able to provide sufficient current to power the sensor and your Arduino in the same time. To minimize the supply voltage fluctuation on the sensor, it is recommended to use an external 12V power supply on your Arduino.
First thing to try is the I2C scanner from here. Upload it and see if it finds the NDIR at 0x4D.
If it finds it then the problem might still be power related as maybe your external PSU or the regulator on the Arduino cannot deliver the current needed (your powering the NDIR from the Arduino 5V pin in the picture).
If you don't find it then maybe try the software serial example instead and see if it hangs.
Do you get nothing at all or do you see the "Wait 10 seconds for sensor initialization..." message?
I tried the I2C scanner according to the instructions, but the message on the serial monitor output stops at "Scanning..." and no further messages are displayed.
When using the sellers NDIR_I2C example no message is displayed at all on the serial monitor when the wiring is A4 = SDA, A5 = SCL
I tried the sellers NDIR_SoftwareSerial example to connect using UART:
#include <SoftwareSerial.h>
#include <NDIR_SoftwareSerial.h>
//Select 2 digital pins as SoftwareSerial's Rx and Tx. For example, Rx=2 Tx=3
NDIR_SoftwareSerial mySensor(2, 3);
void setup()
{
Serial.begin(9600);
if (mySensor.begin()) {
Serial.println("Wait 10 seconds for sensor initialization...");
delay(10000);
} else {
Serial.println("ERROR: Failed to connect to the sensor.");
while(1);
}
}
void loop() {
if (mySensor.measure()) {
Serial.print("CO2 Concentration is ");
Serial.print(mySensor.ppm);
Serial.println("ppm");
} else {
Serial.println("Sensor communication error.");
}
delay(1000);
}
I had the I2C/UART interface board set at UART mode and wiring connected as shown in the attached pictures.
The message I got was "ERROR: Failed to connect to the sensor."
Still not working then. Is there something wrong with my setup?
As a last resort it might be worth swapping the RX/TX wires around and trying again but if that does not work then maybe the module is faulty/damaged or you have power problems.
Hi, I found the solution to this issue and want to share it here, even if it is not technical.
I emailed the seller and they told that the 4 pin cable provided in the kit has been faulty a few times in the past. I bought some new cables and the thing works now just as intended.