SHT30 controls FAN not working
Posted: Tue Apr 14, 2020 12:34 pm
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.
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");
}
}