Post topics, source code that relate to the Arduino Platform

User avatar
By BLCKPSTV
#86543 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 after the display.begin()
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.

Code: Select all#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");
    
  }
    
  }
User avatar
By Bonzo
#86544 Personally I would
1/ disable all the code in the loop and activate parts one at a time and sort out the display last.
2/ Start again getting each part working before moving ont the next.
3/ As most of your code relies on sht30.humidity I would say you want to confirm that is first.


My searching leads me to think I need to convert my sht30.humidity into an int before making the if loop.
If you think that is the problem try changing it to see what happens.
User avatar
By BLCKPSTV
#86558 Thanks for your quick response!

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.

This is the code I've changed D5 with 14!

So before I hook up the sht etc... I should get this to work again. What's the difference with arduion vs wemos on digitalwrite??

Code: Select all
        #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);
    }