Arduino Nano with NDIR CO2 Sensor code queries

Discussion in 'Homework Help' started by inky90, Jul 16, 2017.

  1. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    Hi guys,

    so basically I'm doing a school project in which one of the components require me to use carbon dioxide sensor to sense the amount of carbon dioxide that a person is breathing out. As such, i recently purchase a CO2 sensor from DFRobot, where the model is SEN0219.

    link --> https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_Infrared_CO2_Sensor_For_Arduino_SKU:_SEN0219


    Thus, as soon as i got the sensor, i had follow the tutorial as posted by the website (above link) for the setup and the coding (setup is done through direct connection to arduino nano 5v, ground, and A0 instead of a expansion board) (code is copy and paste).

    But however, after the preheat time of 3 mins as stated and after running the sensor for more than 4 hours, the readings i got from the serial monitor are way off the chart. where the readings are hovering at about 1500 ppm on average. But however, it is known that typical acceptable CO2 levels are 350 - 800 ppm (image attached), thus the reading is wrong given since that I'm in a well ventilated room. i have also tried out in a open area outside my house.


    So i would like to know what is the problem? isnt the sensor accuracy problem? or isnt the coding issue? or perhaps the way i set up the device is wrong


    by the way, i have also notice that when i blow onto the CO2 infrared sensor, the readings from the sensor stay stagnant for quite awhile, approximately 5 to 10 secs, before the values start to increase. Are infrared sensor suppose to react this way? cause from what i believe, the readings from infrared sensor should quickly increase as soon as i blow into it, as compared to those chemical sensor such as MG811 carbon dioxide sensor.
    Side note:

    1) it was stated in the website that when the CO2 sensor get 5V power supply, it will output 0.4~2V analog value, corresponding to 0~5000 ppm, and when the sensor finds faults during the self-checking process, it will output 0V.


    2) the code that i gotten from the website is:
    Code (Text):
    1. int sensorIn = A0;
    2.  
    3. void setup(){
    4.   Serial.begin(9600);
    5.   // Set the default voltage of the reference voltage
    6.   analogReference(DEFAULT);
    7. }
    8.  
    9. void loop(){
    10.   //Read voltage
    11.   int sensorValue = analogRead(sensorIn);
    12.  
    13.   // The analog signal is converted to a voltage
    14.   float voltage = sensorValue*(5000/1024.0);
    15.   if(voltage == 0)
    16.   {
    17.     Serial.println("Fault");
    18.   }
    19.   else if(voltage < 400)
    20.   {
    21.     Serial.println("preheating");
    22.   }
    23.   else
    24.   {
    25.     int voltage_diference=voltage-400;
    26.     float concentration=voltage_diference*50.0/16.0;
    27.     // Print Voltage
    28.     Serial.print("voltage:");
    29.     Serial.print(voltage);
    30.     Serial.println("mv");
    31.     //Print CO2 concentration
    32.     Serial.print(concentration);
    33.     Serial.println("ppm");
    34.   }
    35.   delay(100);
    36. }
    3) attached images are the setup, readings I've got, and other relevant images
     
  2. ericgibbs

    Moderator

    Jan 29, 2010
    5,446
    1,020
    hi inky,
    Try powering the Nano from the USB connection to the PC and not by inputting 5V onto the +5v pin.
    To check the ADC and Nano, use either a 5k pot across the +5v and 0V, with the pot wiper to A0 or say two 4k7 resistors in series to give +5v/2 into A0 and run the Sketch.
    ie: simulate the action of the CO2 sensor.

    Note this clip :

    The official stance on supplying power directly to the 5V pin on the Arduino Uno is thus:

    5V. This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.



    Eric


    EDIT:
    Rechecking your images, it appears that you have the USB connector inserted into the Nano.
    If so, the caution about the 5V input does not apply to your project, I will not delete the information, it may help other Arduino users.

    I would still suggest the potentiometer voltage input to the A0, ADC check. Use the voltage graph from your images as a guide.
     
    • A01.gif
      A01.gif
      File size:
      31.2 KB
      Views:
      2
    Last edited: Jul 16, 2017
  3. ericgibbs

    Moderator

    Jan 29, 2010
    5,446
    1,020
    hi inky,
    Copied and Pasted your Sketch into an Arduino UNO.
    The potentiometer tests show exactly the same as your image, so the program is OK.
    Checked 3 points on the plot.

    So the problem is in the hardware.?
    E
     
  4. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    Hi eric,

    1) probably i've made a mistake in my writing somewhere, but im actually powering the nano via usb connection to the pc. The red wire u see in the pic is connected to the carbon sensor

    2) I dun have a pot with me, but i do have 4k7 resistors. i have plugged them in series between A0 of the arduino and the carbon sensor signal output and had run the sketch. but it seems to have no significant difference in readings between sensor with resistors and sensor without resistors even after running it for 10 to 15 mins (for each setup). The readings will usually be around the same value, 1500 plus plus ppm.
     
  5. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    so which means i got to change the sensor then? This is actually a really pretty new sensor as i have got it straight from a shop (as i have requested them to ship it), then immediately tested it out. Hmm it may seem like the sensor could after all be unreliable.

    few of the customer had issue as well , link--> https://www.dfrobot.com/product-1549.html
     
  6. ericgibbs

    Moderator

    Jan 29, 2010
    5,446
    1,020
    hi,
    Just read those users complaints, seems that there is a problem with some sensors.??

    I have the Uno set up on the bench, is there any other test you like me to do.? I am using a 10K pot for the A0 input.
    BTW: with a 9Vdc supply input the readings are much more stable. Using the USB supply, the readings jump around, which you would expect as the USB 5v is not very stable.

    E
     
  7. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    Hey eric, thanks for helping. i really appreciate that. I'm have no idea of how u can help me though. i mean i'm kinda new to these electronics stuff. so right now i just wanna make sure this sensors that im incorporating are reporting out its values as accurate as possible. So if you do have a explanation or a solution for this sensor, then i think it will be good. ;)

    Re-edit: i mean maybe you are right in the fact that the hardware could be a problem, but a good in-depth explanation would probably be best for me to learn though.
     
    Last edited: Jul 16, 2017
  8. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    hmm... how does voltage affects the stability of the readings?? u mean this sensor actually require 9 volts? as compared to what it stated in their official website?
     
  9. bertus

    Administrator

    Apr 5, 2008
    18,343
    3,515
    Hello,

    Reading the page provided in the openings post, the sensor itself needs to be powered with 4.5 to 5.5 Volts.
    I assume @ericgibbs means that powering the Uno over the powerjack with 9 Volts seems to give an instable reading compared to powering the Uno via USB.

    Bertus
     
  10. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    yeap, looking at the guide stated from the website. it does say operating volatge of 4.5 - 5.5 V.

    erm, do u have an alternative solution to this sensor before i have it for exchange for a new one?

    btw, i like ur quote: When you do ask questions, you may look stupid. When you do NOT ask questions, you will STAY stupid. :)
     
  11. ericgibbs

    Moderator

    Jan 29, 2010
    5,446
    1,020
    hi inky,
    I would contact the supplier for a replacement sensor or at least some explanation why the device is not working according to their specification.

    Eric
     
  12. inky90

    Thread Starter New Member

    Jul 16, 2017
    14
    0
    Hmm alright. :). thanks btw.
     
Loading...