Using CO value to control relay and fan speed

Hi guys. Currently working on some project using mq-7 and esp8266.
Components I used:
MQ-7 (i've heated it up for 48hours)
ESP8266
4-channel relay
24vdc fan
mb102

All i wanna to do is mq-7 to constantly reading the co value, then the 4-channel relay will activate based on the logic to control the fan speed using different vinput on each relay channel.

I'm using the mq7.h library and here's my code for reference:

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <MQ7.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);
MQ7 mq7(A0,5.0);
const int relay1Pin = D6;
const int relay2Pin = D7;
const int relay3Pin = D8;

void setup()
{
 Serial.begin(115200);
 pinMode(A0, INPUT);
 pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
 lcd.begin();
 lcd.backlight();
}

void loop()
{
  float co = mq7.getPPM();
  lcd.setCursor(1, 0);
  lcd.print("CO: ");
  lcd.print(co);
  lcd.print(" PPM");
  delay(1000);
    Serial.print(co);
    Serial.println(" PPM");
    if (co < 10) {
    digitalWrite(relay1Pin, HIGH);
    digitalWrite(relay2Pin, LOW);
    digitalWrite(relay3Pin, LOW);
    lcd.setCursor(1, 1);
    lcd.print("Speed: LOW");
  } else if (co >= 20) {
    digitalWrite(relay1Pin, LOW);
    digitalWrite(relay2Pin, HIGH);
    digitalWrite(relay3Pin, LOW);
    lcd.setCursor(1, 1);
    lcd.print("Speed: MED");
  } else if (co >= 30) {
    digitalWrite(relay1Pin, LOW);
    digitalWrite(relay2Pin, LOW);
    digitalWrite(relay3Pin, HIGH);
    lcd.setCursor(1, 1);
    lcd.print("Speed: HIGH");
     
}
}

Is my code gonna work well? Any input is appreciated!

What fan is it? Datasheet, please.
Using PWM is likely a better option.


merk Sunon
input : 24vdc
50/60 Hz
1,44W
dc brushless fan

Have You tried feeding the fan with different voltages? I doubt it will work. Use a low frequency PWM and logic levlel N channel MOSFET transistor.

The last block when co >= 30 will never be executed. It will be taken care of in the block above. co is from 10 to 19 previous action from previous loop will be the action.

What happens when CO>10 and <20?

I haven't. Is P2904BD good?

So, how can I improve the code? What I want is the fan have three diff speed.

In my experiment, fan speed low.

NO, that won't work with an ESP8266.
Can you buy a BC547C?

What is that?

@unkillabledemonking

well a too high concentration of carbon-MONO-oxyd in short CO

Will kill you.

quoting Wikipedia about the toxity

Toxicity
Main article: Carbon monoxide poisoning
See also: Carboxyhemoglobin

Carbon monoxide poisoning is the most common type of fatal air poisoning in many countries.[92]

The Centers for Disease Control and Prevention estimates that several thousand people go to hospital emergency rooms every year to be treated for carbon monoxide poisoning.[93] According to the Florida Department of Health, "every year more than 500 Americans die from accidental exposure to carbon monoxide and thousands more across the U.S. require emergency medical care for non-fatal carbon monoxide poisoning."[94] The American Association of Poison Control Centers (AAPCC) reported 15,769 cases of carbon monoxide poisoning resulting in 39 deaths in 2007.[95] In 2005, the CPSC reported 94 generator-related carbon monoxide poisoning deaths.[43]

Carbon monoxide is colorless, odorless, and tasteless. As such, it is relatively undetectable.

It readily combines with hemoglobin to produce carboxyhemoglobin which potentially affects gas exchange; therefore exposure can be highly toxic. Concentrations as low as 667 ppm may cause up to 50% of the body's hemoglobin to convert to carboxyhemoglobin.[96] A level of 50% carboxyhemoglobin may result in seizure, coma, and fatality.[97] In the United States, the OSHA limits long-term workplace exposure levels above 50 ppm.[98]

In addition to affecting oxygen delivery, carbon monoxide also binds to other hemoproteins such as myoglobin and mitochondrial cytochrome oxidase, metallic and non-metallic cellular targets to affect many cell operations.

If you are really messing around with carbon-MONO-oxyd you should have installed two carbon-MONO-oxyd detectors that start to beep extremly loud if they detect carbon-MONO-oxyd in the room.

Depending on the CO-concentration you can be killed withing an hour or if high enough within 3 minutes. On low CO-concentrations you will get unconcious and then laying around and die.

Using a username like unkillable..... does not protect against the toxity of CO

You should install two independant working CO-detectors just to make sure that at least one will work

Even better will be to do all these work OUTSIDE with always lot's of fresh air around you.

best regards Stefan

Yes. I'm not sure about the C, but I have bc 547

Thanks, Stefan. But this is only a prototype project

I just bought a new DC 12v fan which has 4 pin. Do I still need to use n-level MOSFET?

That doesn't matter "prototype carbonmoxide is exactly the same poison as any other carbon monoxide.

You should really read up how poisoning it is.

inhalating a

SINGLE

breath of carbon-monoxyde can be deadly

inhalating a rather low concentration of carbon-monoxyde for several minutes and you loose conciousness. If it takes just 10 minutes for another person to find you - its already too late.


I have this to power the fan and the mcu, but I'm not really sure how to connect them since fan needs 12v and esp8266 and the sensor needs 5v.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.