Hello All,
I have this simple circuit from which i wish to read a steady high using an Arduino when the source are shorted or when the source is OFF. I get the below output on the serial
As i understand it, after the CS_State goes HIGH then wait for a pre-defined time and read the pin-state again to check if it a steady HIGH is seen, then execute the code.

I have this simple circuit from which i wish to read a steady high using an Arduino when the source are shorted or when the source is OFF. I get the below output on the serial
My code is as follows,CS State:0
CS State:1
CS State:0
CS State:1
CS State:0
CS State:1
CS State:0
CS State:1
CS State:0
CS State:1
Code:
const byte ZERO_PIN = 2; //Input pin from zero cross detector
const byte TRIAC = A1; //Output pin to TRIAC / SSR
const byte cs = 10;
const byte Ready = 4;
byte count = 0;
byte prevCS_State;
byte cs_State;
byte currCS_State;
byte autoWeldFlag;
volatile boolean zeroCrossingFlag = false;
unsigned long dTime = 50;
unsigned long currT;
//int SET_PIN = A3; //Analog pin for setting the dutyCycle value with a pontentiometer
void setup()
{
pinMode(ZERO_PIN, INPUT_PULLUP);
pinMode(Ready, OUTPUT);
pinMode(cs, INPUT_PULLUP);
pinMode(TRIAC, OUTPUT);
Serial.begin (115200);
attachInterrupt(0, setFlag, FALLING); // zero cross
}
void setFlag()
{
zeroCrossingFlag = true; // interrupt sets flag true
}
void weld()
{
Serial.println("STEADY HIGH");
}
void loop()
{
zeroCrossingFlag = false;
while (!zeroCrossingFlag) {}
delayMicroseconds(8500);
digitalWrite(TRIAC, HIGH);
delayMicroseconds(200);
digitalWrite(TRIAC, LOW);
cs_State = digitalRead(cs);
currCS_State = cs_State;
currT = millis();
Serial.print("CS State:");
Serial.println(currCS_State);
if (currCS_State == HIGH && millis() - currT >= dTime)
{
currCS_State = cs_State;
if (currCS_State == HIGH)
{
Serial.print("Second IF:");
Serial.println(digitalRead(cs));
digitalWrite(Ready, HIGH);
weld();
digitalWrite(Ready, LOW);
}
}
//prevCS_State = currCS_State;
}

Last edited:

