12V relay power on, relays clicking

I have gone above communication and tried to check all parameters or communication made but still Relays are clicking

  1. Relays are cliking with direct supply.
  2. On pressing button, code is executing correctly as “LOW” and “HIGH” appearing on LCD.
  3. When I touch Pin 12 manualy, Relay is clicking.

I am attaching scheme for ready reference. Below is code I using

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd;
#define LCD_CHEXECTIME 2000
#define LCD_INSEXECTIME 38

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

int delayA = 200;

int pushButton = 4;
int Relay4 = 12;
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
lcd.begin(LCD_COLS, LCD_ROWS);

pinMode(pushButton, INPUT_PULLUP); // set up as Relay Activation button
pinMode(Relay4, OUTPUT); // set up Relay4

}

void loop() {

int stateButton = digitalRead(pushButton); // read pushbutton state at digital input

if (stateButton == HIGH)
{lcd.setCursor(0, 1);
lcd.print(“LOW “);
digitalWrite(Relay4, LOW);
delay(delayA);
lcd.clear();
}
if (stateButton == LOW)
{lcd.setCursor(0, 1);
lcd.print(” HIGH”);
digitalWrite(Relay4, HIGH);
delay(delayA);
digitalWrite(Relay4, LOW);
delay(delayA);
digitalWrite(Relay4, HIGH);
delay(delayA);
lcd.clear();
}
}

Alpha.pdf (22 KB)

Which relay board? If it is the "standard" opto isolated type, it should be wired like this:
p5UBRLY.png

p5UBRLY.png

Please find picture of relay module.

@pankajsharma200

TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

:slight_smile: It is solved. Problem was common ground

Regards