Analogous data from sensor & requirements

int sensor_input = A0; // Analog input of the Arduino
int relay_pin = 12; // any digital pin will do

int sensor_data;
int sensor_addition;
int sensor_data_avg;
int number_of_sample = 10;
unsigned long reading_time = 2000;
int threshold = 154;
int scaleval;

void setup()
{  
   Serial.begin(9600);
   pinMode(relay_pin, OUTPUT);
   digitalWrite(relay_pin, LOW);
}

void loop()
{
    sensor_addition = 0;
    for (int x=0;x<number_of_sample;x++)
    {
         sensor_data = analogRead(sensor_input);
         sensor_addition = sensor_addition + sensor_data;
         delay(reading_time);
    }
   sensor_data_avg = sensor_addition / number_of_sample;
   Serial.print("Rawvalue from Analog input  =");
   Serial.print(sensor_data_avg);
   // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
   scaleval = map(sensor_data_avg, 0, 675, 0, 20);
   Serial.print("   Scaled Value =");
   Serial.println(scaleval);          
   
   if (sensor_data_avg > threshold)
   {
       digitalWrite(relay_pin, HIGH);
   }
  else
  {
     digitalWrite(relay_pin, LOW);
  }        
}

Is that code suitable for
Screenshot 2022-09-09 100304

Or,
That code is suitable -

int analogPin = A3; 
int Rawval ;  // variable to store the value read
int Scaleval ;
void setup()
{
  Serial.begin(9600);           //  setup serial
}

void loop()
{
  int Rawval = analogRead(analogPin);
  Serial.print("Rawvalue from Analog input  =");
  Serial.print(Rawval);
  // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
  Scaleval = map(Rawval, 0, 675, 0, 20);
  Serial.print("   Scaled Value =");
  Serial.println(Scaleval);          
}

This mapping depends on the analog reference voltage of your controller.

1 Like

Kindly do compare with both the image & check the code

@anon45799003
You are copying the solution you were given yesterday in another thread. What is still not clear here?
What is your question?

The above code contains a ready-made solution.

As I see, your last nickname was banned for repeating meaningless questions. Do not start again. Try to think yourself before asking.

Any alternative of- DIY CO2 Incubator: CO2 Regulation - YouTube

Using -Analogous data from sensor & requirements

What is "alternative" do you need? Please explain in detail

Control and regulation used in the same sentence seems to be contradiction. Do you want to control or do you want to regulate? Either will need a sensor to measure pressure or flow.

What do you want to do with this project?

The video shows an Arduino turning on a CO2 valve when the CO2 sensor detects less than 5% CO2 concentration. Is that what you want to do? Are you having trouble doing that? Have you purchased any of the components?

1 Like

Have you changed your name and did you not already have a post on this project?

I am having this.

int sensor_input = A0; // Analog input of the Arduino
int relay_pin = 12; // any digital pin will do

int sensor_data;
int sensor_addition;
int sensor_data_avg;
int number_of_sample = 10;
unsigned long reading_time = 2000;
int threshold = 154;
int scaleval;

void setup()
{  
   Serial.begin(9600);
   pinMode(relay_pin, OUTPUT);
   digitalWrite(relay_pin, LOW);
}

void loop()
{
    sensor_addition = 0;
    for (int x=0;x<number_of_sample;x++)
    {
         sensor_data = analogRead(sensor_input);
         sensor_addition = sensor_addition + sensor_data;
         delay(reading_time);
    }
   sensor_data_avg = sensor_addition / number_of_sample;
   Serial.print("Rawvalue from Analog input  =");
   Serial.print(sensor_data_avg);
   // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
   scaleval = map(sensor_data_avg, 0, 675, 0, 20);
   Serial.print("   Scaled Value =");
   Serial.println(scaleval);          
   
   if (sensor_data_avg > threshold)
   {
       digitalWrite(relay_pin, HIGH);
   }
  else
  {
     digitalWrite(relay_pin, LOW);
  }        
}

Experimental Replication

If you have seen it carefully. You might have seen that The CO2 Sensor is different. Do need full for my CO2 sensor as an alternative of video demonstrated CO2 sensor

CO2 regulation

Do I have a code for relay operation? Using this calibrated data from the Analogous sensor

int analogPin = A3; 
int Rawval ;  // variable to store the value read
int Scaleval ;
void setup()
{
  Serial.begin(9600);           //  setup serial
}

void loop()
{
  int Rawval = analogRead(analogPin);
  Serial.print("Rawvalue from Analog input  =");
  Serial.print(Rawval);
  // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
  Scaleval = map(Rawval, 0, 675, 0, 20);
  Serial.print("   Scaled Value =");
  Serial.println(Scaleval);          
}
int analogPin = A3; 
int Rawval ;  // variable to store the value read
int Scaleval ;
void setup()
{
  Serial.begin(9600);           //  setup serial
}

void loop()
{
  int Rawval = analogRead(analogPin);
  Serial.print("Rawvalue from Analog input  =");
  Serial.print(Rawval);
  // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
  Scaleval = map(Rawval, 0, 675, 0, 20);
  Serial.print("   Scaled Value =");
  Serial.println(Scaleval);          
}

Do I have a code for relay operation for CO2 regulation?


image

How to calibrate this sensor?

I have merged your cross-posts @anon45799003.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@anon45799003, stop wasting the moderators' time with the nuisance flagging.

@anon45799003,
I have stopped you from posting for 2 days because of your repeated pointless flags to the moderators despite being warned about doing this.

The next ban will be longer, possibly permanent.