Si7021 Displaying Wrong Values

I'm making use of Sparkfun's Si7021 breakouty board, as well as the library provided by Sparkfun.

Code worked 100% until two days ago.

Temperature and Humidity readings are below zero.

void getHumTemp()
{
   //Measure Relative Humidity from the HTU21D or Si7021
  humidity = sensor.getRH();

  //Measure Temperature from the HTU21D or Si7021
  tempC = sensor.getTemp();

  Serial.print("Temp:");
  Serial.print(tempC);
  Serial.print(" °C, ");

  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.println(" %");  
}

Both tempC and humidity are float values. The function is also called periodically every 6 seconds by Blynk Timer.

If you look at the library code SparkFun_Si7021_Breakout_Library.cpp, then you see that Weather::makeMeasurment() returns 100 if the communication with the sensor is lost. That error code is not used by other code of the library. When that "100" is used in sensor.getTemp(), then it results into -46.5818725586 for the temperature. That is what you have.

If you restart the project, perhaps it shows a message that the sensor is not found. Perhaps a reset will make it work.

To be able to say something about your I2C bus, I would like to know many things: Which Arduino board do you use ? Please show a photo of all the I2C wires. Which modules are connected to the I2C bus (with links to where you bought them), a full sketch between code-tags, and so on.

Thanks for clarifying.

I'm making use of the ESP32.

3.3V - 3.3V
GND - GND
SDA - 21
SCL - 22

It seems like the jumper pin of the 3V connector did not make contact.

I even switched to using millis() as I still want to see my readings even when the device is offline:

Main File:

 /**********************************************************************************
TITLE: GROWSPACE

AUTHOR: SHAWN TAYLOR

VERSION: 1.0.1

NOTE: CONTROL LIGHT SCHEDULE
    : CONTROL INLET FANS AND OUTLET FANS
    : MONITOR TEMPERATURE AND HUMIDITY
    : MONITOR VPD
 **********************************************************************************/

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxx"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
//#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD

// On time Defines
#define ON_TIME 1080 //Minutes
#define ON_TIME_START 420 // 07:00

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

//#include <WiFi.h>
//#include <WiFiClient.h>
//#include <WiFiUdp.h>
//#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include "SparkFun_Si7021_Breakout_Library.h"
#include <NTPClient.h>

//Si7021
float humidity = 0;
float tempC = 0;

//NTP DATE/TIME
//Week Days
String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
//Month names
String months[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
  
// Define Switch Pins
#define s1 34 // LIGHTS
#define s2 35 // INLET
#define s3 32 // OUTLET
#define s4 33 // HUMIDIFIER
#define s5 25 // UNDEFINED

// Define Relay Pins
#define r1 25 // LIGHT 1
#define r2 27 // LIGHT 2
#define r3 14 // INLET
#define r4 12 // OUTLET
#define r5 13 // HUMIDIFIER

// Define Hysteresis
#define tempDeadBand 3

uint8_t currentMin = 0;
int currentHour = 0;
int currentMinCalc = 0;
//uint16_t onTimeDuration = 1080;
//uint8_t onTimeDurationFans = 20;
//const int onTime = 420;
uint8_t currentCalcMin = 0;
uint8_t lightsON = 0;
uint16_t waitMin = 0;
uint16_t waitMinFans = 0;
uint8_t hourScheduler = 02;
uint16_t r1Time = 0;
uint16_t r2Time = 0;
uint16_t r3Time = 0;
uint16_t r4Time = 0;

struct SCHEDULER
{
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint16_t OnTime;
};

struct SCHEDULER Scheduler[4][8];

//Millis related variables
const uint16_t readInterval = 6000;
unsigned long previousTime = 0;
unsigned long currentTime = 0;

//char auth[] = BLYNK_AUTH_TOKEN;

#define VPIN_BUTTON_1    V1 
#define VPIN_BUTTON_2    V2
#define VPIN_BUTTON_3    V3 
#define VPIN_BUTTON_4    V4
#define VPIN_BUTTON_5    V5 

#define VPIN_TEMPERATURE V9
#define VPIN_HUMIDITY    V10

// Relay State
bool toggleState_1 = HIGH; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = HIGH; //Define integer to remember the toggle state for relay 2
bool toggleState_3 = HIGH; //Define integer to remember the toggle state for relay 3
bool toggleState_4 = HIGH; //Define integer to remember the toggle state for relay 4
bool toggleState_5 = HIGH; //Define integer to remember the toggle state for relay 5

// Switch State
bool SwitchState_1 = LOW;
bool SwitchState_2 = LOW;
bool SwitchState_3 = LOW;
bool SwitchState_4 = LOW;
bool SwitchState_5 = LOW;

#include "BlynkEdgent.h"

//Instances
BlynkTimer timer;
//Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
Weather sensor;
//NTP
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");


/*void sendSensor()
{
  getHumTemp();
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(VPIN_HUMIDITY, humidity1);
  Blynk.virtualWrite(VPIN_TEMPERATURE, temperature1);
}*/

//BLYNK_CONNECTED() {
//  // Request the latest state from the server
//  Blynk.syncVirtual(VPIN_BUTTON_1);
//  Blynk.syncVirtual(VPIN_BUTTON_2);
//  Blynk.syncVirtual(VPIN_BUTTON_3);
//  Blynk.syncVirtual(VPIN_BUTTON_4);
//  Blynk.syncVirtual(VPIN_BUTTON_5);
//  Blynk.syncVirtual(VPIN_BUTTON_6);
//  Blynk.syncVirtual(VPIN_BUTTON_7);
//  Blynk.syncVirtual(VPIN_BUTTON_8);
//  Blynk.syncVirtual(VPIN_TEMPERATURE);
//  Blynk.syncVirtual(VPIN_HUMIDITY);
//  Blynk.syncVirtual(VPIN_LDR);
//}

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) 
{
  toggleState_1 = param.asInt();
  if(toggleState_1 == 1)
  {
    //digitalWrite(r1, LOW);
    //digitalWrite(r2, LOW);
  }
  else 
  { 
    digitalWrite(r1, HIGH);
    digitalWrite(r1, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_2) 
{
  toggleState_2 = param.asInt();
  if(toggleState_2 == 1)
  {
    //digitalWrite(r3, LOW);
  }
  else 
  { 
    digitalWrite(r3, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_3) 
{
  toggleState_3 = param.asInt();
  if(toggleState_3 == 1)
  {
    //digitalWrite(r4, LOW);
  }
  else 
  { 
    digitalWrite(r4, HIGH);
  }
}

BLYNK_WRITE(VPIN_BUTTON_4) 
{
  toggleState_4 = param.asInt();
  if(toggleState_4 == 1)
  {
    //digitalWrite(r5, LOW);
  }
  else 
  { 
    digitalWrite(r5, HIGH);
  }
}


BLYNK_WRITE(VPIN_BUTTON_5) 
{
  all_SwitchOff();
}

//Current minute calc func
/*void lightSchedule()
{ 
  waitMin = (currentMin + 1);
  currentCalcMin = ((currentHour * 60) + currentMin);
  
  if(currentCalcMin == onTime) // 7 * 60 = 420
  { 
    //Switch Lights On

    //Switch Inlet and Outlet On
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW); 
    
    lightsON = 1;

  } 
    if(waitMin == currentMin)
    {
      onTimeDuration--;
    }
  
    if(onTimeDuration == 0)
    {
      //Switch Lights Off
      lightsON = 0;
      onTimeDuration = 1080;
    }
}

void fanSchedule()
{

  waitMinFans = (currentMin + 1);
  
  if(lightsON == 1)
  {
    digitalWrite(r3, LOW);
    digitalWrite(r4, LOW);  
  }

  if(lightsON == 0) //Lights Off
  {
    //Wait 20 minutes after lights off to switch off Inlet & Outlet
    if(waitMinFans == currentMin)
    {
      onTimeDurationFans--;
    }

    if(onTimeDurationFans == 0)
    {
      digitalWrite(r3, HIGH);
      digitalWrite(r4, HIGH); 
    }
  }
}*/

void all_SwitchOff()
{
  toggleState_1 = 0; digitalWrite(r1, HIGH); Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1); delay(100);
                     digitalWrite(r2, HIGH);
  toggleState_2 = 0; digitalWrite(r3, HIGH); Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2); delay(100);
  toggleState_3 = 0; digitalWrite(r4, HIGH); Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3); delay(100);
  toggleState_4 = 0; digitalWrite(r5, HIGH); Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4); delay(100);
  toggleState_5 = 0;                         Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5); delay(100);

  Blynk.virtualWrite(VPIN_HUMIDITY, humidity);
  Blynk.virtualWrite(VPIN_TEMPERATURE, tempC);

}

// Get Date && Time Function
void getDateTime()
{
    unsigned long epochTime = timeClient.getEpochTime();
  Serial.print("Epoch Time: ");
  Serial.println(epochTime);
   
  String formattedTime = timeClient.getFormattedTime();
  Serial.print("Formatted Time: ");
  Serial.println(formattedTime);  
 
  currentHour = timeClient.getHours();
  Serial.print("Hour: ");
  Serial.println(currentHour);  
 
  currentMin = timeClient.getMinutes();
  Serial.print("Minutes: ");
  Serial.println(currentMin); 
    
  int currentSecond = timeClient.getSeconds();
  Serial.print("Seconds: ");
  Serial.println(currentSecond);  
 
  String weekDay = weekDays[timeClient.getDay()];
  Serial.print("Week Day: ");
  Serial.println(weekDay); 
}

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V9, tempC);
  Blynk.virtualWrite(V10, humidity);
  //getDateTime();
}

void getHumTemp()
{
   //Measure Relative Humidity from the HTU21D or Si7021
  humidity = sensor.getRH();

  //Measure Temperature from the HTU21D or Si7021
  tempC = sensor.getTemp();

  Serial.print("Temp:");
  Serial.print(tempC);
  Serial.print(" °C, ");

  Serial.print("Humidity:");
  Serial.print(humidity);
  Serial.println(" %");  
}
void setup()
{
  Serial.begin(115200);

  pinMode(r1, OUTPUT);
  pinMode(r2, OUTPUT);
  pinMode(r3, OUTPUT);
  pinMode(r4, OUTPUT);
  pinMode(r5, OUTPUT);


  //pinMode(wifiLed, OUTPUT);

  pinMode(s1, INPUT_PULLUP);
  pinMode(s2, INPUT_PULLUP);
  pinMode(s3, INPUT_PULLUP);
  pinMode(s4, INPUT_PULLUP);
  pinMode(s5, INPUT_PULLUP);

  
  //During Starting all Relays should TURN OFF
  digitalWrite(r1, HIGH);
  digitalWrite(r2, HIGH);
  digitalWrite(r3, HIGH);
  digitalWrite(r4, HIGH);
  digitalWrite(r5, HIGH);

  //irrecv.enableIRIn(); // Enabling IR sensor
  BlynkEdgent.begin();

  //Initialize the I2C sensors and ping them
  sensor.begin();
  
  // Set up a function to be called every x-amount of seconds //
  //timer.setInterval(3000L, getHumTemp);
  timer.setInterval(12000L, myTimerEvent);

  // Initialize NTP Client 
  timeClient.begin();
  timeClient.setTimeOffset(7200);

  waitMin = currentMin;

  //Initialize Scheduler Struct to 0xFF
  for (int i = 0; i < 4; i++)
  {
    for (int z = 0; z < 8; z++)
    {
      Scheduler[i][z].Month = 0xFF;
      Scheduler[i][z].Day = 0xFF;
      Scheduler[i][z].Hour = 0xFF;
      Scheduler[i][z].Minute = 0xFF;
      Scheduler[i][z].OnTime = 0xFFFF;
    }
  }

  // LIGHT RELAY 1 :: 07:00 - 01:00
  Scheduler[0][0].Hour = 07;      // [0] - RELAY 1 :: [0] - TIME SCHEDULE 1
  Scheduler[0][0].Minute = 00;    // [0] - RELAY 1 :: [0] - TIME SCHEDULE 1
  Scheduler[0][0].OnTime = 1080;  // [0] - RELAY 1 :: [0] - TIME SCHEDULE 1

  // LIGHT RELAY 2 :: 07:00 - 01:00
  Scheduler[1][0].Hour = 07;      // [1] - RELAY 2 :: [0] - TIME SCHEDULE 1
  Scheduler[1][0].Minute = 00;    // [1] - RELAY 2 :: [0] - TIME SCHEDULE 1
  Scheduler[1][0].OnTime = 1080;  // [1] - RELAY 2 :: [0] - TIME SCHEDULE 1

  // INLET FAN :: 07:00 - 01:20
  Scheduler[2][0].Hour = 07;      // [2] - RELAY 3 :: [0] - TIME SCHEDULE 1
  Scheduler[2][0].Minute = 00;    // [2] - RELAY 3 :: [0] - TIME SCHEDULE 1
  Scheduler[2][0].OnTime = 1110;  // [2] - RELAY 3 :: [0] - TIME SCHEDULE 1
  
  for (int i = 1; i < 6; i++)
  {
    Scheduler[2][i].Hour = hourScheduler;  // [2] - RELAY 3 :: [1] - TIME SCHEDULE 2
    Scheduler[2][i].Minute = 15;           // [2] - RELAY 3 :: [1] - TIME SCHEDULE 2
    Scheduler[2][i].OnTime = 15;           // [2] - RELAY 3 :: [1] - TIME SCHEDULE 2
    hourScheduler++;
  }

  hourScheduler = 02;

  // OUTLET FAN
  Scheduler[3][0].Hour = 07;      // [3] - RELAY 4 :: [0] - TIME SCHEDULE 1
  Scheduler[3][0].Minute = 00;    // [3] - RELAY 4 :: [0] - TIME SCHEDULE 1
  Scheduler[3][0].OnTime = 1110;  // [3] - RELAY 4 :: [0] - TIME SCHEDULE 1

    for (int i = 1; i < 6; i++)
  {
    Scheduler[3][i].Hour = hourScheduler; // [3] - RELAY 4 :: [i] - TIME SCHEDULE 2
    Scheduler[3][i].Minute = 15;          // [3] - RELAY 4 :: [i] - TIME SCHEDULE 2
    Scheduler[3][i].OnTime = 15;          // [3] - RELAY 4 :: [i] - TIME SCHEDULE 2
    hourScheduler++;
  }
  
}
void loop() 
{
    currentTime = millis();
    BlynkEdgent.run();
    manual_control(); //Manual Switch Control
    //ir_remote(); //IR remote Control
    timer.run();
    //NTP Update
    timeClient.update();
    if(currentTime - previousTime >= readInterval)
    {
      getHumTemp();
      getDateTime();
      controlHumidity();
      previousTime = currentTime;
    }
    startScheduler();
}

BlynkEdgent.h:


extern "C" {
  void app_loop();
  void eraseMcuConfig();
  void restartMCU();
}

#include "Settings.h"
#include <BlynkSimpleEsp32_SSL.h>

#ifndef BLYNK_NEW_LIBRARY
#error "Old version of Blynk library is in use. Please replace it with the new one."
#endif

#if !defined(BLYNK_TEMPLATE_ID) || !defined(BLYNK_DEVICE_NAME)
#error "Please specify your BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME"
#endif

#include "BlynkState.h"
#include "ConfigStore.h"
#include "ResetButton.h"
#include "ConfigMode.h"
#include "Indicator.h"
#include "OTA.h"
void manual_control();
void ir_remote();
void startScheduler();
void relay1Task();
void relay2Task();
void relay3Task();
void relay4Task();
void controlHumidity();
inline
void BlynkState::set(State m) {
  if (state != m && m < MODE_MAX_VALUE) {
    DEBUG_PRINT(String(StateStr[state]) + " => " + StateStr[m]);
    state = m;

    // You can put your state handling here,
    // i.e. implement custom indication
  }
}

void printDeviceBanner()
{
  Blynk.printBanner();
  DEBUG_PRINT("--------------------------");
  DEBUG_PRINT(String("Product:  ") + BLYNK_DEVICE_NAME);
  DEBUG_PRINT(String("Hardware: ") + BOARD_HARDWARE_VERSION);
  DEBUG_PRINT(String("Firmware: ") + BLYNK_FIRMWARE_VERSION " (build " __DATE__ " " __TIME__ ")");
  if (configStore.getFlag(CONFIG_FLAG_VALID)) {
    DEBUG_PRINT(String("Token:    ...") + (configStore.cloudToken+28));
  }
  DEBUG_PRINT(String("Device:   ") + BLYNK_INFO_DEVICE + " @ " + ESP.getCpuFreqMHz() + "MHz");
  DEBUG_PRINT(String("MAC:      ") + WiFi.macAddress());
  DEBUG_PRINT(String("Flash:    ") + ESP.getFlashChipSize() / 1024 + "K");
  DEBUG_PRINT(String("ESP sdk:  ") + ESP.getSdkVersion());
  DEBUG_PRINT(String("Chip rev: ") + ESP.getChipRevision());
  DEBUG_PRINT(String("Free mem: ") + ESP.getFreeHeap());
  DEBUG_PRINT("--------------------------");
}

void runBlynkWithChecks() {
  Blynk.run();
  if (BlynkState::get() == MODE_RUNNING) {
    if (!Blynk.connected()) {
      if (WiFi.status() == WL_CONNECTED) {
        BlynkState::set(MODE_CONNECTING_CLOUD);
      } else {
        BlynkState::set(MODE_CONNECTING_NET);
      }
    }
  }
}

class Edgent 
{

public:
  void begin()
  {
    indicator_init();
    button_init();
    config_init();

    WiFi.persistent(false);
    WiFi.enableSTA(true);   // Needed to get MAC

    printDeviceBanner();

    if (configStore.getFlag(CONFIG_FLAG_VALID)) {
      BlynkState::set(MODE_CONNECTING_NET);
    } else if (config_load_blnkopt()) {
      DEBUG_PRINT("Firmware is preprovisioned");
      BlynkState::set(MODE_CONNECTING_NET);
    } else {
      BlynkState::set(MODE_WAIT_CONFIG);
    }
  }

  void run() {
    app_loop();
    switch (BlynkState::get()) {
    case MODE_WAIT_CONFIG:       
    case MODE_CONFIGURING:       enterConfigMode();    break;
    case MODE_CONNECTING_NET:    enterConnectNet();    break;
    case MODE_CONNECTING_CLOUD:  enterConnectCloud();  break;
    case MODE_RUNNING:           runBlynkWithChecks(); break;
    case MODE_OTA_UPGRADE:       enterOTA();           break;
    case MODE_SWITCH_TO_STA:     enterSwitchToSTA();   break;
    case MODE_RESET_CONFIG:      enterResetConfig();   break;
    default:                     enterError();         break;
    }
  }

};

Edgent BlynkEdgent;
BlynkTimer timer3;

void app_loop() {
    timer3.run();
    manual_control();
    startScheduler();
   // ir_remote();
}

void manual_control()
{
  if (digitalRead(s1) == LOW && SwitchState_1 == LOW) 
  {
    //digitalWrite(r1, LOW);
    //digitalWrite(r2, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_1, HIGH);
    toggleState_1 = HIGH;
    SwitchState_1 = HIGH;
    Serial.println("LIGHTS AUTOMATION ON");
  }
  
  if (digitalRead(s1) == HIGH && SwitchState_1 == HIGH) 
  {
    digitalWrite(r1, HIGH);
    digitalWrite(r2, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_1, LOW);
    toggleState_1 = LOW;
    SwitchState_1 = 0;
    Serial.println("LIGHTS AUTOMATION OFF");
  }
  
  if (digitalRead(s2) == LOW && SwitchState_2 == LOW) 
  {
    //digitalWrite(r3, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_2, HIGH);
    toggleState_2 = HIGH;
    SwitchState_2 = HIGH;
    Serial.println("INLET ON");
  }
  
  if (digitalRead(s2) == HIGH && SwitchState_2 == HIGH) 
  {
    digitalWrite(r3, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_2, LOW);
    toggleState_2 = LOW;
    SwitchState_2 = LOW;
    Serial.println("INLET OFF");
  }
  
  if (digitalRead(s3) == LOW && SwitchState_3 == LOW) 
  {
    //digitalWrite(r4, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_3, HIGH);
    toggleState_3 = HIGH;
    SwitchState_3 = HIGH;
    Serial.println("OUTLET ON");
  }
  
  if (digitalRead(s3) == HIGH && SwitchState_3 == HIGH) 
  {
    digitalWrite(r4, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_3, LOW);
    toggleState_3 = LOW;
    SwitchState_3 = LOW;
    Serial.println("OUTLET OFF");
  }
  
  if (digitalRead(s4) == LOW && SwitchState_4 == LOW) 
  {
    //digitalWrite(r5, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_4, HIGH);
    toggleState_4 = HIGH;
    SwitchState_4 = HIGH;
    Serial.println("HUMIDIFIER ON");
  }
  
  if (digitalRead(s4) == HIGH && SwitchState_4 == HIGH) 
  {
    digitalWrite(r5, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_4, LOW);
    toggleState_4 = LOW;
    SwitchState_4 = LOW;
    Serial.println("HUMIDIFIER OFF");
  }
  
  /*if (digitalRead(s5) == LOW && SwitchState_5 == LOW) 
  {
    //digitalWrite(RelayPin5, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_5, HIGH);
    toggleState_5 = HIGH;
    SwitchState_5 = HIGH;
    Serial.println("Switch-5 on");
  }
  
  if (digitalRead(s5) == HIGH && SwitchState_5 == HIGH) 
  {
   digitalWrite(RelayPin5, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_5, LOW);
    toggleState_5 = LOW;
    SwitchState_5 = LOW;
    Serial.println("Switch-5 off");
  }*/
  
  /*if (digitalRead(SwitchPin6) == LOW && SwitchState_6 == LOW) {
    digitalWrite(RelayPin6, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_6, HIGH);
    toggleState_6 = HIGH;
    SwitchState_6 = HIGH;
    Serial.println("Switch-6 on");
  }
  if (digitalRead(SwitchPin6) == HIGH && SwitchState_6 == HIGH) {
    digitalWrite(RelayPin6, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_6, LOW);
    toggleState_6 = LOW;
    SwitchState_6 = LOW;
    Serial.println("Switch-6 off");
  }
  if (digitalRead(SwitchPin7) == LOW && SwitchState_7 == LOW) {
    digitalWrite(RelayPin7, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_7, HIGH);
    toggleState_7 = HIGH;
    SwitchState_7 = HIGH;
    Serial.println("Switch-7 on");
  }
  if (digitalRead(SwitchPin7) == HIGH && SwitchState_7 == HIGH) {
    digitalWrite(RelayPin7, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_7, LOW);
    toggleState_7 = LOW;
    SwitchState_7 = LOW;
    Serial.println("Switch-7 off");
  }
  if (digitalRead(SwitchPin8) == LOW && SwitchState_8 == LOW) {
    digitalWrite(RelayPin8, LOW);
    Blynk.virtualWrite(VPIN_BUTTON_8, HIGH);
    toggleState_8 = HIGH;
    SwitchState_8 = HIGH;
    Serial.println("Switch-8 on");
  }
  if (digitalRead(SwitchPin8) == HIGH && SwitchState_8 == HIGH) {
    digitalWrite(RelayPin8, HIGH);
    Blynk.virtualWrite(VPIN_BUTTON_8, LOW);
    toggleState_8 = LOW;
    SwitchState_8 = LOW;
    Serial.println("Switch-8 off");
  }*/
}

void startScheduler(void)
{
  if(waitMin == currentMin)
  {
    waitMin = (currentMin + 1);
    if(waitMin > 59)
    {
      waitMin -=60;
    }

    // LIGHTS 1 :: 07:00 - 01:00
    if(Scheduler[0][0].Hour == currentHour)
    {
      if(Scheduler[0][0].Minute == currentMin)
      {
        r1Time = Scheduler[0][0].OnTime;
      }
    }

    // LIGHTS 2 :: 07:00 - 01:00
    if(Scheduler[1][0].Hour == currentHour)
    {
      if(Scheduler[1][0].Minute == currentMin)
      {
        r2Time = Scheduler[1][0].OnTime;
      }
    }

    // INLET :: 07:00 - 01:00
    if(Scheduler[2][0].Hour == currentHour)
    {
      if(Scheduler[2][0].Minute == currentMin)
      {
        r3Time = Scheduler[2][0].OnTime;
      }
    }
    // INLET :: 
    if(Scheduler[2][1].Hour == currentHour)
    {
      if(Scheduler[2][1].Minute == currentMin)
      {
        r3Time = Scheduler[2][1].OnTime;
      }
    }
    // INLET
    if(Scheduler[2][2].Hour == currentHour)
    {
      if(Scheduler[2][2].Minute == currentMin)
      {
        r3Time = Scheduler[2][2].OnTime;
      }
    }
    // INLET
    if(Scheduler[2][3].Hour == currentHour)
    {
      if(Scheduler[2][3].Minute == currentMin)
      {
        r3Time = Scheduler[2][3].OnTime;
      }
    }
    // INLET
    if(Scheduler[2][4].Hour == currentHour)
    {
      if(Scheduler[2][4].Minute == currentMin)
      {
        r3Time = Scheduler[2][4].OnTime;
      }
    }
    // INLET
    if(Scheduler[2][5].Hour == currentHour)
    {
      if(Scheduler[2][5].Minute == currentMin)
      {
        r3Time = Scheduler[2][5].OnTime;
      }
    }

    // INLET
    /*if(Scheduler[0][0].Month == currentMonth |  0xFF)
    {
      if(Scheduler[0][0].Day == currentDay | 0xFF)
      {
        if(Scheduler[0][0].Hour == currenHour)
        {
          if(Scheduler[0][0].Minute == currentMin)
          {
            r2Time = Scheduler[2][6].OnTime;
          }
        }
      }
    }*/ 

    // OUTLET
    if(Scheduler[3][0].Hour == currentHour)
    {
      if(Scheduler[3][0].Minute == currentMin)
      {
        r4Time = Scheduler[3][0].OnTime;
      }
    }
    // OUTLET
    if(Scheduler[3][1].Hour == currentHour)
    {
      if(Scheduler[3][1].Minute == currentMin)
      {
        r4Time = Scheduler[3][1].OnTime;
      }
    }
    // OUTLET
    if(Scheduler[3][2].Hour == currentHour)
    {
      if(Scheduler[3][2].Minute == currentMin)
      {
        r4Time = Scheduler[3][2].OnTime;
      }
    }
    // OUTLET
    if(Scheduler[3][3].Hour == currentHour)
    {
      if(Scheduler[3][3].Minute == currentMin)
      {
        r4Time = Scheduler[3][3].OnTime;
      }
    }
    // OUTLET
    if(Scheduler[3][4].Hour == currentHour)
    {
      if(Scheduler[3][4].Minute == currentMin)
      {
        r4Time = Scheduler[3][4].OnTime;
      }
    }
    // OUTLET
    if(Scheduler[3][5].Hour == currentHour)
    {
      if(Scheduler[3][5].Minute == currentMin)
      {
        r4Time = Scheduler[3][5].OnTime;
      }
    }
           
    // Relay Tasks
    relay1Task();
    relay2Task();
    relay3Task();
    relay4Task();
  }
}

/* RELAY TASKS */
 
void relay1Task(void) // LIGHTS 
{
  if ((r1Time) && (toggleState_1 == HIGH))
  {
    digitalWrite(r1, LOW); // Switch on Relay
    r1Time--;
  }
  else if ((r1Time == 0) | (toggleState_1 == LOW))
  {
    digitalWrite(r1, HIGH); // Switch off Relay
  }
}

void relay2Task(void) //LIGHTS
{
  if ((r2Time) && (toggleState_1 == HIGH))
  {
    digitalWrite(r2, LOW); // Switch on Relay
    r2Time--;
  }
  else if ((r2Time == 0) | (toggleState_1 == LOW))
  {
    digitalWrite(r2, HIGH); // Switch off Relay
  }
}

void relay3Task(void) //INLET
{
  if ((r3Time) && (toggleState_2 == HIGH))
  {
    digitalWrite(r3, LOW); // Switch on Relay
    r3Time--;
  }
  else if ((r3Time == 0) | (toggleState_2 == LOW))
  {
    digitalWrite(r3, HIGH); // Switch off Relay
  }
}

void relay4Task(void) //OUTLET
{
  if ((r4Time) && (toggleState_3 == HIGH))
  {
    digitalWrite(r4, LOW); // Switch on Relay
    r4Time--;
  }
  else if ((r4Time == 0) | (toggleState_3 == LOW))
  {
    digitalWrite(r4, HIGH); // Switch off Relay
  }
}


void controlHumidity(void)
{
  if((humidity <= 53) && (toggleState_4 == HIGH))
  {
    digitalWrite(r5, LOW);
  }

  if((humidity >= 56) | (toggleState_4 == LOW))
  {
    digitalWrite(r5, HIGH);
  }
}
/*void ir_remote()
{
  if (irrecv.decode(&results)) {
      switch(results.value){
          case 0x80BF49B6:  
            digitalWrite(RelayPin1, toggleState_1);
            toggleState_1 = !toggleState_1;
            Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
            delay(100);            
            break;
          case 0x80BFC936:  
            digitalWrite(RelayPin2, toggleState_2);
            toggleState_2 = !toggleState_2;
            Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
            delay(100);            
            break;
          case 0x80BF33CC:  
            digitalWrite(RelayPin3, toggleState_3);
            toggleState_3 = !toggleState_3;
            Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
            delay(100);            
            break;
          case 0x80BF718E:  
            digitalWrite(RelayPin4, toggleState_4);
            toggleState_4 = !toggleState_4;
            Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
            delay(100);            
            break;
          case 0x80BFF10E:  
            digitalWrite(RelayPin5, toggleState_5);
            toggleState_5 = !toggleState_5;
            Blynk.virtualWrite(VPIN_BUTTON_5, toggleState_5);
            delay(100);            
            break;
          case 0x80BF13EC:  
            digitalWrite(RelayPin6, toggleState_6);
            toggleState_6 = !toggleState_6;
            Blynk.virtualWrite(VPIN_BUTTON_6, toggleState_6);
            delay(100);            
            break;
          case 0x80BF51AE:  
            digitalWrite(RelayPin7, toggleState_7);
            toggleState_7 = !toggleState_7;
            Blynk.virtualWrite(VPIN_BUTTON_7, toggleState_7);
            delay(100);            
            break;
          case 0x80BFD12E:  
            digitalWrite(RelayPin8, toggleState_8);
            toggleState_8 = !toggleState_8;
            Blynk.virtualWrite(VPIN_BUTTON_8, toggleState_8);
            delay(100);            
            break;  
          default : break;         
        }   
        //Serial.println(results.value, HEX);    
        irrecv.resume();   
  } 
}*/

That seems to be alright. You use the Wire.begin() which is called from the Sparkfun library during sensor.begin(); That Wire.begin() has no parameters, so the ESP32 uses its default pins for I2C. Updating the sensors every 6 seconds is also no problem of course.

To be able to check the hardware of your I2C bus, I would like to see all the other things.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.