SHT30 activates FAN

Hello,

I've a working hardware setup and two codes 1 to read the sht30 and push the data to my tft screen.

And 2 a code to set a fan (2fans) on and off.

I want to combine these whenever the humidity is over 50% the fans should go on.

3 issues arise.

  1. less important my serial.println() doesn't print anything anymore
  2. my second if loop doesn't get printed not in serial or in display
  3. Fans are not getting activated by the code.

My searching leads me to think I need to convert my sht30.humidity into an int before making the if loop.

Or it could be something entirely else ofcourse.

#include <WEMOS_SHT3X.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>



Adafruit_SSD1306 display(1);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif


SHT3X sht30(0x45);


void setup() {
  Serial.begin(115200);
  pinMode(14, OUTPUT);
  // initialize with the I2C addr 0x3C
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(1000);
  Serial.print("start");
  // Clear the buffer.
  display.clearDisplay();
}

void loop() {


 // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.setTextColor(WHITE);
 
  if(sht30.get()==0)
  {
    display.setCursor(35, 10);
    display.println("T: ");
    display.setCursor(50, 10);
    display.println(sht30.cTemp);
    display.setCursor(35, 20);
    display.println("H: ");
    display.setCursor(50, 20);
    display.println(sht30.humidity);
  }
  else
  {
    display.setCursor(35, 10);
    display.println("Error!");
    Serial.println("error");
  }
  display.display();
  delay(1000);

  Hcheck();
  Serial.println("checking humidity");
  



  
  
}

void Hcheck() {
  delay(5000);
  Serial.println("============ Check Humidity ===============");
  display.clearDisplay();
  display.setCursor(35, 10);
  display.println(sht30.humidity);
  display.display();
  delay(1000);
  Serial.println(sht30.humidity);
  
  if(sht30.humidity <= 50 ) {
    digitalWrite(14, HIGH);
    display.clearDisplay();
    display.setCursor(35, 20);
    display.display();
    delay(500);
  }else {
    digitalWrite(14, LOW);
    delay(500);
    Serial.println("Air is dry");
    
  }
    
  }

You probably run out of memory. Your display library (Adafruit_SSD1306) uses more than half of the available RAM.

You can save a lot of RAM by using the F() macro for all constant strings.

Your check for humidity is '<=' which means the fan will turn on when the humidity is at or below 50%. If it is above 50%, you turn the fans off and report "Air is dry".

I think you have it backwards.

Hi,
Can I suggest you write some code using the humidity sensor and the fan, to check that it works without bugs?
Then add the display.

Tom.. :slight_smile:

Ok I rebuild everything. And still the fans won't work.

So I hooked up the arduino again saw that I didn't add a ground wire from arduino to the whole circuit.

And tried again.

The arduino works with the code below. I just replaced the Wemos D1 mini to check if this works to proceed further.

But the wemos doesn't make the fans spin.
the fan is driven by a 12v charger. And the irf540n cicruit powers that. They just share a common ground and the pwm pin D5
This is the code I've changed D5 with 14!

I have a working fan control with the correct wiring that works with arduino.

I would like to change the arduino with a Wemos D1 mini board. 

When I hook everything up. The fans are not activated. 

Is there something I need to know about the difference in both of them? 

Below is the code, I've changed D5 in the code to 14. 

Still nothing seems to work.

        #define fan D5
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      Serial.println("start");
      pinMode(fan, OUTPUT);
    
      digitalWrite(fan, LOW);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      delay(1000);
      digitalWrite(fan, HIGH);
    
      delay(1000);
      digitalWrite(fan, LOW);
    }

A irf540n transistor is not a logic level transistor. You should not be using that. The logic level version is IRLf540

note the 'L' for logic. Logic level transitors fully turn on when driven at 5V, others do not and can not pass as much current as the fan probably needs

Hi,
What "Arduino again" are you using?
The Wemos D1 mini has 3.3V logic level output doesn't it?
So there will not be enough output voltage to operate the MOSFET gate.

Do you have a DMM?

Thanks.. Tom.. :slight_smile: