[SOLVED] Help me with my project

Hello I am working on a project in which I have an ac fan and a mq137 sensor then the 3 relays wherein there are capacitors connected which will change the speed of the fan depending on the value of the sensor. My issue is that at first I used one relay to check if the hardware is working if it will turn on/off everytime the sensor detects something, it worked fine at first but then I connected my wiring to the NO of the relay then after a few minutes even though there is no value detected on my sensor the fan is still spinning making the NO to become NC. Now another issue arose after letting my relay rest what happens is that everytime it detects something the arduino keeps resetting and in the ide it keeps disconnecting and connecting even my pc monitor suddenly turned on and off. attached is my circuit diagram and code I hope that you can help me since I don't have anyone to guide me on this one.

#include <SoftwareSerial.h>

int AmmoniaSensor = A0;
int CO2Sensor = A1;
int gas, co2lvl;
float m = -0.263;    // Slope
float b = 0.42;      // Y-Intercept
float R0 = 20;       // Sensor Resistance in fresh air from previous code
int relayPin1 = 13;  // First relay control pin
int relayPin2 = 12;  // Second relay control pin

SoftwareSerial mySerial(2, 3);  // RX, TX pins on Arduino Uno

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);
  delay(500);
  digitalWrite(relayPin1, HIGH);  // Initial state (OFF)
  digitalWrite(relayPin2, HIGH);  // Initial state (OFF)
  pinMode(CO2Sensor, INPUT);
  pinMode(AmmoniaSensor, INPUT);
}


void loop() {
  float sensor_volt;  // Define variable for sensor voltage
  float RS_gas;       // Define variable for sensor resistance
  float ratio;        // Define variable for ratio

  float sensorValueAmmonia = analogRead(AmmoniaSensor);  // Read ammonia sensor
  float sensorValueCO2 = analogRead(CO2Sensor);          // Read CO2 sensor

  sensor_volt = sensorValueAmmonia * (5.0 / 1023.0);  // Convert analog values to voltage
  RS_gas = ((5.0 * 10.0) / sensor_volt) - 10;         // Get value of RS in a gas
  ratio = RS_gas / R0;                                // Get ratio RS_gas/RS_air

  double ppm_log = (log10(ratio) - b) / m;  // Get ammonia ppm value in linear scale according to the ratio value
  double ammonia_ppm = pow(10, ppm_log);    // Convert ppm value to log scale

  gas = sensorValueCO2;
  co2lvl = gas - 64;
  co2lvl = map(co2lvl, 0, 1024, 400, 5000);

  // Send ammonia value to the serial monitor
  Serial.print("Ammonia: ");
  Serial.println(ammonia_ppm, 2);  // Print the ammonia ppm value with 2 decimal places
  delay(500);                      // Delay for 0.5 seconds

  // Send CO2 value to the serial monitor
  Serial.print("CO2: ");
  Serial.println(co2lvl);
  delay(500);

  // Send ammonia value to NodeMCU
  mySerial.print(ammonia_ppm, 2);  // Print the ammonia ppm value with 2 decimal places
  mySerial.print(",");             // Separate values with a comma
  delay(500);                      // Delay for 0.5 seconds

  // Send CO2 value to NodeMCU
  mySerial.println(co2lvl);

  // Control the relay
  if (ammonia_ppm >= 5 && ammonia_ppm < 15) {
    digitalWrite(relayPin1, LOW);   // Turn on the first relay
   
  } else {
    digitalWrite(relayPin1, HIGH);  // Turn off the first relay
 
  }


  delay(1000);  // Delay for a second before the next reading
}

CIRCUIT DIAGRAM:


I appreciate your time for reading this one! Have a good day!

How is your arduino and your relay board powered?
Is arduino ground connected to relay board ground?
What is the black thingy?

I just use my laptop to power it since I'm still making my hardware right now and yes both have the same ground. pls dont mind the black thingy. I just saw that circuit on yt and it suits the project that I'm doing just focus on the fan capactior relay and the esp but change the esp to arduino

It will not solve your problem, but the result of analogRead is an integer. It should be stored in int, not float.

Please make a scheme that exactly represents your situation. Do not use something thst looks alike..
The devil is in the detail.

ok I appreciate your help

Buy a 5V adapter (or take one that is lying around). A phone charger would be ok.
Use that to power the relay board.

You first take a log and then use a power. It seems to me you might be able to avoid that...

what would be the difference when using the arduino's 5v and should the ground be the same for the arduino and the adapter?

i do not understand this pls bear with me as I'm not technical enough for this stuff I'm a newbie for this one.

Arduinos 5v is not suitable to drive a relay.
Voltage may drop resetting the relay.
A NC connection to a relay can only be changed to NO through rewiring. Not via software.

Let it be for now.... it is most probably not the cause of your trouble....

image
is it something like this? and I should just attach a screw terminal block?

working with relay is such a pain maybe this could be one of the solutions.

Could be, but I cannot read the specs on your pic.
Yes relay board and arduino should share ground.

image
this is the description of the pic

would it still work properly if there are 3 relays?

It is AC (alternating current). You need dc...

oh okay thanks for reminding me.

What does this refer to???