LCD + I2C interfering with Relay?

Hi Everyone,

I´m trying to build this simple temperature controlled fan, but the relay will not switch the voltage to activate the fan. I do see the signal coming through to the relay and all voltages are ok. I also checked each sensor individually so I know they are ok.
It seems that the I2C+LCD is interfering with the relay. Another thing I do not understand is that, if I remove the LCD power pins (5V and GND), the buzzer will also stop working. That is confusing me.

The schematics of my project is attached and the code is down below. Any help is greatly appreciated!!! :slight_smile:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
int relayPin = 3; // Initialize Relay Pin 3
const int buzzer = 5; // Initialize buzzer pin 5
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
LiquidCrystal_I2C lcd(0x27, 16, 2); //Inicializa o display no endereco 0x27

void setup()
{
  lcd.init();
}
static bool measure_environment( float * temperature, float * humidity )
{
  static unsigned long measurement_timestamp = millis( );
  if ( millis( ) - measurement_timestamp > 3000ul )   /* Measure once every four seconds. */
  {
    if ( dht_sensor.measure( temperature, humidity ) == true )
    {
      measurement_timestamp = millis( );
      return ( true );
    }
  }
  return ( false );
}

void loop()
{
  float temperature;
  float humidity;
  if ( measure_environment( &temperature, &humidity ) == true )
  {
    lcd.setBacklight(HIGH);
    lcd.setCursor(0, 0);
    lcd.print("Temp. = ");
    lcd.print(temperature, 1);
    lcd.print(" C");
    if (temperature >= 30)
    {
      tone(buzzer, 1000); // Send 1KHz sound signal
      delay(500);              // keep it on for 1/2 second
      noTone(buzzer);     // Stop sound.
      delay(500);              // wait for 1/2 second
      tone(buzzer, 1000); // Send 1KHz sound signal
      delay(500);              // keep it on for 1/2 second
      noTone(buzzer);     // Stop sound.
      delay(500);              // wait for 1/2 second
      tone(buzzer, 1000); // Send 1KHz sound signal
      delay(500);              // wait for 1/2 second
      noTone(buzzer);     // Stop sound.
      delay(500);              // wait for 1/2 second
      lcd.setCursor(0, 1);
      lcd.print("FAN ON!!!");
      digitalWrite(relayPin, HIGH);   // turn the fan on
      delay (1000);
    }
    if (temperature < 30)
    {
      tone(buzzer, 1000); // Send 1KHz sound signal
      delay(500);              // keep it on for 1/2 second
      noTone(buzzer);     // Stop sound.
      delay(800);              // wait for 0.8 second
      digitalWrite(relayPin, LOW);   // turn the fan off
      lcd.setCursor(0, 1);
      lcd.print("FAN OFF");
    }

    //delay(2000);

  }
}

VCC and GND are not connected to the top power lines of the breadboard.

jeffvida78:

  delay(800);              // wait for 1/8 second

800 means 0.8 second.

VCC and GND were actually connected. I forgot to do that on my drawing. I updated the comments and drawing as per your suggstions. Thanks Erik.

However, the circuit is still having the same problem.

It looks as if everything is being powered from the Arduino. That defeats the purpose of the relay and the fan almost certainly draws too much current to be functional.

Thanks for the reply Shannon Member. You are right, as this could be done without the relay. The idea is just to integrate the different components into one project and to understand what is happening between the LCD and the relay.

I have disconnected the fan for testing purposes and the result is the same.

Any additional ideas?

I expect the problem is that your components between them draw too much current. You could try not turning the backlight on for the LCD to reduce it a bit, but I suspect that the relay coil is drawing a lot.

An Arduino can control other components, but it can't power anything that draws significant current.

Even if I power the arduino from the 5V barrel?

jeffvida78:
Even if I power the arduino from the 5V barrel?

Yes. The Uno can provide no more than 150mA. It just isn't intended to power anything much. Any motor (like your fan) will be too large a load. Contrary to many tutorials, it can't manage really servos either.

Separate power is needed, even if it's just some AA batteries.

Thanks for your reply! I will follow this path then and continue to try it out.