89 lines
1.8 KiB
C++
89 lines
1.8 KiB
C++
/*
|
|
modified on Apr 10, 2021
|
|
Modified by MehranMaleki from Arduino Examples
|
|
Home
|
|
*/
|
|
|
|
// this is using the HiLetgo 5V 4 Channel Relay Shield
|
|
// pinout is apparently 7,6,5,4
|
|
|
|
#define USE_SHT30
|
|
|
|
#ifdef USE_SHT30
|
|
|
|
#include "SHT85.h"
|
|
#define SHT85_ADDRESS 0x44
|
|
|
|
SHT85 sht30;
|
|
|
|
#else
|
|
#include <Wire.h>
|
|
#include "DFRobot_SHT20.h"
|
|
|
|
TwoWire twowire;
|
|
DFRobot_SHT20 sht20(&twowire);
|
|
#endif
|
|
|
|
void fanOn() {
|
|
digitalWrite(7, HIGH);
|
|
}
|
|
|
|
void fanOff() {
|
|
digitalWrite(7, LOW);
|
|
}
|
|
|
|
|
|
const int PIN_RELAY4 = 4;
|
|
const int PIN_RELAY3 = 5;
|
|
|
|
void setup()
|
|
{
|
|
pinMode(PIN_RELAY4, OUTPUT);
|
|
pinMode(PIN_RELAY3, OUTPUT);
|
|
pinMode(7, OUTPUT);
|
|
digitalWrite(7, LOW);
|
|
|
|
Serial.begin(115200);
|
|
#ifdef USE_SHT30
|
|
Wire.begin();
|
|
sht30.begin(SHT85_ADDRESS);
|
|
Wire.setClock(10000);
|
|
#else
|
|
twowire.setClock(10000);
|
|
sht20.initSHT20(); // Init SHT20 Sensor
|
|
#endif
|
|
delay(100);
|
|
//sht20.checkSHT20(); // Check SHT20 Sensor
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
while (Serial.available()) {
|
|
const int c = Serial.read();
|
|
if (c == 's') {
|
|
#ifdef USE_SHT30
|
|
sht30.read();
|
|
float humd = sht30.getHumidity();
|
|
float temp = sht30.getTemperature();
|
|
#else
|
|
float humd = sht20.readHumidity(); // Read Humidity
|
|
float temp = sht20.readTemperature(); // Read Temperature
|
|
#endif
|
|
Serial.print(humd);
|
|
Serial.print(",");
|
|
Serial.print(temp);
|
|
Serial.print(",");
|
|
Serial.print(digitalRead(PIN_RELAY4));
|
|
Serial.print(",");
|
|
Serial.print(digitalRead(PIN_RELAY3));
|
|
Serial.println("");
|
|
}
|
|
if (c == 'z') digitalWrite(PIN_RELAY4, LOW);
|
|
if (c == 'Z') digitalWrite(PIN_RELAY4, HIGH);
|
|
if (c == 'y') digitalWrite(PIN_RELAY3, LOW);
|
|
if (c == 'Y') digitalWrite(PIN_RELAY3, HIGH);
|
|
}
|
|
delay(1);
|
|
}
|