hepl for high school CO2 sensor project

Hello from Turkey. I'm a geography teacher. We want to make a high school project with my student. But inexperienced about arduino. And That's why we need your helps. We'll use the arduino uno MG-811 CO2 sensor and MQ-135 air quality sensor and Nokia 5110 led screen.

Question 1: We can make connections on breadboard for MG 811. But i write whatever code it's always a constant value (only 400 ppm).

Question 2: We want to use MG 811 and MQ 135 together. And we want to reflect the measurements to the Nokia 5110 led screen. Can you draw the fritzing of the right connection.

Thank you and sorry my English grammer. :slight_smile:

Please provide a schematic of your circuit.

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not have access to this useful tool. I recommend using the standard Arduino IDE instead.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Maybe the air is just super clean where you live. 400 ppm CO2 is the ideal state of the atmosphere.

ChrisTenone:
Maybe the air is just super clean where you live. 400 ppm CO2 is the ideal state of the atmosphere.

I living Istanbul. 400 ppm is impossibl. LOL

ChrisTenone:
Maybe the air is just super clean where you live. 400 ppm CO2 is the ideal state of the atmosphere.

gently blowing on the sensor should increase the CO2 reading.

wvmarle:
gently blowing on the sensor should increase the CO2 reading.

Yes, we know. But the meansurement results continuously up to 400 ppm and this value doesn't change at all.

Well.... Then it's very much time for you to read #1 (or the "how to use this forum" sticky of course) and start providing more information based on the questions/instructions given there.

pert:
Please provide a schematic of your circuit.

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not have access to this useful tool. I recommend using the standard Arduino IDE instead.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

I used that code:

Author: Tiequan Shao: tiequan.shao@sandboxelectronics.com
Peng Wei: peng.wei@sandboxelectronics.com

Lisence: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)

Note: This piece of source code is supposed to be used as a demostration ONLY. More
sophisticated calibration is required for industrial field application.

Sandbox Electronics 2012-05-31
************************************************************************************/

/Hardware Related Macros************/
#define MG_PIN (0) //define which analog input channel you are going to use
#define BOOL_PIN (2)
#define DC_GAIN (8.5) //define the DC gain of amplifier

/Software Related Macros*************/
#define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation
#define READ_SAMPLE_TIMES (5) //define the time interval(in milisecond) between each samples in
//normal operation

/Application Related Macros************/
//These two values differ from sensor to sensor. user should derermine this value.
#define ZERO_POINT_VOLTAGE (0.220) //define the output of the sensor in volts when the concentration of CO2 is 400PPM
#define REACTION_VOLTGAE (0.020) //define the voltage drop of the sensor when move the sensor from air into 1000ppm CO2

/Globals******************/
float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))};
//two points are taken from the curve.
//with these two points, a line is formed which is
//"approximately equivalent" to the original curve.
//data format:{ x, y, slope}; point1: (lg400, 0.324), point2: (lg4000, 0.280)
//slope = ( reaction voltage ) / (log400 –log1000)

void setup()
{
Serial.begin(9600); //UART setup, baudrate = 9600bps
pinMode(BOOL_PIN, INPUT); //set pin to input
digitalWrite(BOOL_PIN, HIGH); //turn on pullup resistors

Serial.print("MG-811 Demostration\n");
}

void loop()
{
int percentage;
float volts;

volts = MGRead(MG_PIN);
Serial.print( "SEN-00007:" );
Serial.print(volts);
Serial.print( "V " );

percentage = MGGetPercentage(volts,CO2Curve);
Serial.print("CO2:");
if (percentage == -1) {
Serial.print( "<400" );
} else {
Serial.print(percentage);
}

Serial.print( "ppm" );
Serial.print("\n");

if (digitalRead(BOOL_PIN) ){
Serial.print( "=====BOOL is HIGH======" );
} else {
Serial.print( "=====BOOL is LOW======" );
}

Serial.print("\n");

delay(200);
}

/***************************** MGRead *********************************************
Input: mg_pin - analog channel
Output: output of SEN-000007
Remarks: This function reads the output of SEN-000007
************************************************************************************/
float MGRead(int mg_pin)
{
int i;
float v=0;

for (i=0;i<READ_SAMPLE_TIMES;i++) {
v += analogRead(mg_pin);
delay(READ_SAMPLE_INTERVAL);
}
v = (v/READ_SAMPLE_TIMES) *5/1024 ;
return v;
}

/***************************** MQGetPercentage **********************************
Input: volts - SEN-000007 output measured in volts
pcurve - pointer to the curve of the target gas
Output: ppm of the target gas
Remarks: By using the slope and a point of the line. The x(logarithmic value of ppm)
of the line could be derived if y(MG-811 output) is provided. As it is a
logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic
value.
************************************************************************************/
int MGGetPercentage(float volts, float *pcurve)
{
if ((volts/DC_GAIN )>=ZERO_POINT_VOLTAGE) {
return -1;
} else {
return pow(10, ((volts/DC_GAIN)-pcurve[1])/pcurve[2]+pcurve[0]);
}
}

When you're having problems it's always a good idea to run the most minimal code possible:

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  Serial.println(analogRead(0));
  delay(500);
}

This way you know there is no chance of the problem being caused by a bug in the code. You should see the readings change when you blow on the sensor. If the reading doesn't change then you know the issue is with the hardware. If the problem does not still occur then you know the issue is with the code.

Can you also show us a diagram or clear picture of how the device is hooked up to the Arduino and the power?

Oh, and please use code tags when posting code - it makes it a lot easier to check and run.