I found this project which is about controlling the firing angle of SCR using Arduino and it works well.
https://simple-circuit.com/arduino-scr-half-wave-controlled-rectifier/
Then I modified the code to add an I2C LCD Display to the project.
But after modification of the code even though the LCD works well, now the firing angle of SCR stops working.
So I'm wondering where is the mistake in my code?
When I remove the last 6 lines (LCD Commands) from the code it works just fine!
#define scr_trig 8
#define pot A0
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
bool ZC = 0;
uint16_t alpha;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup(void) {
pinMode(scr_trig, OUTPUT);
digitalWrite(scr_trig, LOW);
attachInterrupt(0, ZC_detect, FALLING); // Enable external interrupt (INT0)
lcd.init();
lcd.backlight();
}
void ZC_detect() {
ZC = 1;
}
void loop() {
if (ZC) {
delayMicroseconds(alpha);
digitalWrite(scr_trig, HIGH);
delay(1);
digitalWrite(scr_trig, LOW);
ZC = 0;
alpha = analogRead(pot) * 10;
if (alpha > 10000)
alpha = 10000;
}
lcd.setCursor(0, 0);
lcd.print("Firing angle is=");
lcd.setCursor(0, 1);
lcd.print((1023 - analogRead(pot)) / 5.7);
lcd.setCursor(8, 1);
lcd.print("degree");
}