Need some help with H11AA1 circuit

I am using this circuit for detecting a 24VAC signal.

For as long as the signal is present I want keep the pin triggered so a solenoid stays open.

I wired this circuit with the capacitor and as soon as I powered on the UNO the pin was triggered and the timer began and would only run one time. I tested be removing the H11AA1 fro the socket and same result.

Then I disconnected the cap and reinstalled the H11AA1 and now it kind of works. It will trigger the pin one time and the countdown begins. If the 24VAC is still present when the timer hits zero it starts over again, but it the 24VAC signal stops, and the timer is already somewhere between 5 sec and 0 sec it will stop at zero. But I need it to go the full 5 secs.

I understand the cap is to help keep the pin triggered between the AC cycles, but why was it causing a single shot on bootup.

Could the cap have been damaged when soldering?

Try a smaller capacitor (100 nF).

But you don't need the capacitor. the output of the optoisolator won't be a steady LOW signal when the AC is on, but you know the timing of the LOW pulses. AC OFF will be a steady HIGH for more than one AC cycle.

So are you saying that I should check for High after x time, then trigger countdown timer?

Show us a good image of your ‘actual’ wiring.
Posting images: https://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your sketch between code tags
[code]Paste your sketch here[/code]

Image 1

Image 2

Image 3

/*
  Post Flow Gas timer curcuit

  This is to add a post flow timeer functionality to a
  stick welding power source that does not have gas flow control built in.

  This is to be triggered from an external source such as the pedal controls of the welder
  In this design the trigger is the 24VAC power that comes from the front panel plug for the foot pedal.
  When the pedal is depressed the contact closure toggles the electrode 'HOT' and 24VAC goes high.
  When the circuit senses the 24VAC it will open the soleniod allowing gas to flow.
  The 24VAC stays high as long as the pedal is depressed and goes 'LOW' when the pedal is released and power to the electrode is removed.
  When the 24VAC goes 'LOW' the circuit timer will start and will keep the solenoid open for a preset number of seconds (Post Flow).
  After the preset time the solenoid will close and the circuit will reset for the next cycle / pedal press.

  Other conditions, if pedal is released timer should start, unless the pedal is pressed again before timer runs out then timer shoud reset to
  preset time and continue to wait for pedal release.



  The circuit:
   LCD RS pin to digital pin 12
   LCD Enable pin to digital pin 11
   LCD D4 pin to digital pin 5
   LCD D5 pin to digital pin 4
   LCD D6 pin to digital pin 3
   LCD D7 pin to digital pin 2
   LCD R/W pin to ground
   LCD VSS pin to ground
   LCD VCC pin to 5V
   10K resistor:
   ends to +5V and ground
   wiper to LCD VO pin (pin 3)
   buttonPin1 (pin 7) - starts timer - will be replaced with optocoupler
   buttonPin2 (pin 9) - increments timer

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Set pin 7 to 'buttonPin' this will be trigger from optocupler
const byte buttonPin1 = 7;
const int buttonPin2 = 9;

// set timer variable at startup
int sec = 5;

int buttonState      = 0;
int lastButtonState  = 0;

void setup() {

  // LED output
  pinMode(8, OUTPUT);
  // set serial speed
  Serial.begin(9600);
  // set buttonPin
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);

  //set LED on until timer stops
  //digitalWrite(8, HIGH);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // Print a message to the LCD.
  // lcd.print("Post Flow Sec");

  // Print timer setting to LCD
  //  lcd.setCursor(14,0);
  //  lcd.print(sec);

}

void loop() {

  // Print a message to the LCD.
  lcd.setCursor(0, 0);
  lcd.print("Post Flow Sec");

  // Print timer setting to LCD
  lcd.setCursor(14, 0);
  lcd.print(sec);


  //wait for button press to start
  while (digitalRead(buttonPin1) == HIGH)
  {

    // Read buttonPin1 for timer value set
    buttonState = digitalRead(buttonPin2);

    //check if button is pressed
    if (buttonState != lastButtonState) {

      // Change state of buttonState if buttonPin2 is pressed
      if (buttonState == 0) {

        // Add 1 to timer time
        sec++;
        // If timer reaches xx then reset to start time =5
        if (sec > 14) sec = 5;

        // slight delay
        delay(15);
      }

      lastButtonState = buttonState;
      Serial.print("timer is set to: ");
      Serial.println(sec);

      // Print timer setting changes to LCD
      lcd.setCursor(14, 0);
      if (sec < 10) {
        lcd.setCursor(15, 0);
        lcd.print(" ");
      }
      lcd.setCursor(14, 0);
      lcd.print(sec);
    }

  }
  while (digitalRead(buttonPin1) == LOW)
  {
    //buttonPin1 press detected
    digitalWrite(8, HIGH);
  }

  //
  //    SET timer here for switch release
  //


  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // countdown and output to serial:
  for (int i = sec; i >= 0; i--) {
    lcd.setCursor(0, 1);
    if (sec < 10) {
      lcd.setCursor(1, 1);
      lcd.print(" ");
    }
    lcd.setCursor(0, 1);
    lcd.print(i);
    // Print countdown to console for information
    Serial.print("i is :");
    Serial.println(i);
    // set timer step approx 1 sec
    delay(1000);

    // read timer and light LED of time is less that 1
    if (i < 1) {
      digitalWrite(8, LOW);
    } else {
      digitalWrite(8, HIGH);
    }

  }
}

The MOSFET wiring looks very suspicious.

As is, 0-5v output from the Arduino will not turn on/off the MOSFET.

What is the MOSFET part number ?


The Opto cct. doesn’t look correct also, 4 and 5 are collector and emitter.

Plus the LEDs in the Opto need a series dropping resistor.

MOSFET is an IRLZ44N.

The solenoid portion is working fine, its that the cap across the outputs of the H11AA1 was causing pin 7 to go LOW long enough to trigger and then HIGH again and countdown started when first booted, then nothing would happen on subsequent triggering.

With out the cap it does not trigger on boot, but as soon as AC is present it goes LOW and then obviously HIGH again, but at this time the timer has already started counting down.

Here is updated sketch with cap shown on correct pins of H11AA1. Markings on MOSFET and Opto are not correct on drawing.

Do you have a series resistor with the 24VAC power supply. ?


You are showing the MOSFET ‘source’ going to the red wire of 12v when red usually means positive,
is this correct ?

And you are using an N channel MOSFET as a ‘HIGH’ side switch ??? .

Edit
OKAY, looks like you are using RED as GND and BLACK as +12v, very very none standard.


BTW, In your Fritzing drawing, looks like your kickback diode needs to be turned 180°.

You need to avoid using while() and delay() in your sketches.

Both of these are ‘blocking’ constructs.

A.C. waveforms go through a zero voltage period which can can picked up by the very fast ARDUINO.

As a result pushing SW1 will result in 100/120hz detection by your program.

Adding the capacitor will help filter the Opto o/p transitions but it will be slightly effective if at all.

It is best to look for a dropout period of ~ 200ms to determine if SW1 has been released.

Have you read about making timers using the BWD (blink without delay) technique ?

If not see these:

How and Why to avoid delay():
http://playground.arduino.cc/Code/AvoidDelay

Demonstration code for several things at the same time.
http://forum.arduino.cc/index.php?topic=223286.0

larryd:
Do you have a series resistor with the 24VAC power supply. ?


You are showing the MOSFET ‘source’ going to the red wire of 12v when red usually means positive,
is this correct ?

And you are using an N channel MOSFET as a ‘HIGH’ side switch ??? .

Edit
OKAY, looks like you are using RED as GND and BLACK as +12v, very very none standard.


BTW, In your Fritzing drawing, looks like your kickback diode needs to be turned 180°.

Ok Yes to the resistor on the AC side, 5K, I forgot it the first time and the H11AA1 only lasted one time.

I corrected the Fritzing drawing, the actual board is wired correctly. FET source is ground, drain is neg(black) to solenoid Pos 12v(red). I wired the FET from the data sheet and a previous LED project.

Also I don't think I understand the good/bad of using an N-channel MOSFET as a HIGH side switch.

Here is corrected fritzing

This wiring is correct even though red is usually + and black is usually -.

It’s just that the diode needed to be turned around in the schematic :wink:


In this new schematic, you need to reverse the red and black wires going to the regulator PCB as red (positive) should be Vcc.

Don’t worry about a HIGH side switch right now as your cct. will work as you have stated.

I mentioned it as your wire colours did not make sense in the original drawing.


You need to revamp your sketch to remove delay() and while() and incorporate BWD timers.

Use a 47 to 100nF cap and put a 10k pullup resistor from +5V to the H11AA1 output pin, when you turn power on, that fat, discharged cap is pulling the input pin LOW until it can charge through the 30k internal pullup.
Is that a 220 Ohm pulldown resistor on the MOSFET gate? Should be at least 10k.

larryd:
How and Why to avoid delay():
http://playground.arduino.cc/Code/AvoidDelay

Demonstration code for several things at the same time.
http://forum.arduino.cc/index.php?topic=223286.0

Thank you, I will read these and see if I can interpret for my use.

JCA34F:
Use a 47 to 100nF cap and put a 10k pullup resistor from +5V to the H11AA1 output pin, when you turn power on, that fat, discharged cap is pulling the input pin LOW until it can charge through the 30k internal pullup.
Is that a 220 Ohm pulldown resistor on the MOSFET gate? Should be at least 10k.

Thank you, I will track down some smaller caps in the morning and make a few changes.

Does it matter what types of caps I use?

Can you follow how a timer can be set up to monitor a 120/100 Herz signal (no capacitor needed) ?

Note: The A.C. going to the H11AA1 will produce 120/100 hertz at the collector pin 5.

//When the switch is pushed, the solenoid is picked
//While the switch is pushed the solenoid remains picked
//When the switch is released, the solenoid drops out after ≈100ms


#define pickSolenoid            HIGH
#define dropSolenoid            LOW
#define PUSHED                  LOW

const byte heartbeatLED         = 13;
const byte solenoidPin          = 8;
const byte mySwitch             = 2;

//const byte tonePin              = 3;

byte lastState                  = 0;

boolean myTimerFlag             = false;

unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long myTimerMillis;

unsigned long heartbeatInterval = 500;
unsigned long switchInterval    = 10;
unsigned long dropoutInterval   = 100;

//*********************************************************************
void setup()
{
  Serial.begin(9600);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(solenoidPin, OUTPUT);

  pinMode(mySwitch, INPUT_PULLUP);

//  pinMode(tonePin, OUTPUT);
//  tone(tonePin, 120);

} //END of setup()

//*********************************************************************
void loop()
{
  //***************************
  //time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis >= heartbeatInterval)
  {
    heartbeatMillis = millis();

    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //***************************
  //time to sample the switches ?
  if (millis() - switchMillis >= switchInterval)
  {
    //reset Timer
    switchMillis = millis();

    checkSwitches();
  }

  //***************************
  //has the myTimer expired ?
  if (myTimerFlag == true && millis() - myTimerMillis >= dropoutInterval)
  {
    //disable Timer
    myTimerFlag = false;

    digitalWrite(solenoidPin, dropSolenoid);
    Serial.println("The solenoid has been dropped");
  }

  //***************************
  // other non blocking code
  //***************************

} //END of loop()

//*********************************************************************
void checkSwitches()
{
  //mySwitch
  byte currentState = digitalRead(mySwitch);

  if (lastState != currentState)
  {
    //update to the new state
    lastState = currentState;

    //is the switch pressed ?
    if (currentState == PUSHED)
    {
      digitalWrite(solenoidPin, pickSolenoid);

      //restart TIMER
      myTimerMillis = millis();

      //enable the Timer
      myTimerFlag = true;
    }
  }

  //other switches

} //END of  checkSwitches()

//*********************************************************************

As an alternative, you can place a diode in series with the 4.7k resistor and add a filter capacitor.

The resulting DC voltage will now feed the H11AA1 rather than A.C.

Just connect the end of the cap that is not connected to the opto, to +5V instead of ground.

larryd:
Can you follow how a timer can be set up to monitor a 120/100 Herz signal (no capacitor needed) ?

I think I can, and I will try! (very amateur programmer)

Is the 100ms the monitor against the frequency? If so, I would need to add another timer after switch release of desired time after myTimerFlag = false; before dropSolenoid.

Note: The A.C. going to the H11AA1 will produce 120/100 hertz at the collector pin 5.

//When the switch is pushed, the solenoid is picked

//While the switch is pushed the solenoid remains picked
//When the switch is released, the solenoid drops out after ≈100ms

#define pickSolenoid            HIGH
#define dropSolenoid            LOW
#define PUSHED                  LOW

const byte heartbeatLED         = 13;
const byte solenoidPin          = 8;
const byte mySwitch             = 2;

//const byte tonePin              = 3;

byte lastState                  = 0;

boolean myTimerFlag             = false;

unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long myTimerMillis;

unsigned long heartbeatInterval = 500;
unsigned long switchInterval    = 10;
unsigned long dropoutInterval   = 100;

//*********************************************************************
void setup()
{
 Serial.begin(9600);

pinMode(heartbeatLED, OUTPUT);
 pinMode(solenoidPin, OUTPUT);

pinMode(mySwitch, INPUT_PULLUP);

//  pinMode(tonePin, OUTPUT);
//  tone(tonePin, 120);

} //END of setup()

//*********************************************************************
void loop()
{
 //***************************
 //time to toggle the heartbeat LED ?
 if (millis() - heartbeatMillis >= heartbeatInterval)
 {
   heartbeatMillis = millis();

digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
 }

//***************************
 //time to sample the switches ?
 if (millis() - switchMillis >= switchInterval)
 {
   //reset Timer
   switchMillis = millis();

checkSwitches();
 }

//***************************
 //has the myTimer expired ?
 if (myTimerFlag == true && millis() - myTimerMillis >= dropoutInterval)
 {
   //disable Timer
   myTimerFlag = false;

digitalWrite(solenoidPin, dropSolenoid);
   Serial.println("The solenoid has been dropped");
 }

//***************************
 // other non blocking code
 //***************************

} //END of loop()

//*********************************************************************
void checkSwitches()
{
 //mySwitch
 byte currentState = digitalRead(mySwitch);

if (lastState != currentState)
 {
   //update to the new state
   lastState = currentState;

//is the switch pressed ?
   if (currentState == PUSHED)
   {
     digitalWrite(solenoidPin, pickSolenoid);

//restart TIMER
     myTimerMillis = millis();

//enable the Timer
     myTimerFlag = true;
   }
 }

//other switches

} //END of  checkSwitches()

//*********************************************************************







---



As an alternative, you can place a diode in series with the 4.7k resistor and add a filter capacitor. 

The resulting DC voltage will now feed the H11AA1 rather than A.C.

Are there guides or charts on figuring the filter capacitor value?

I found this Cfilt=Po / ωVoVr

where power must be processed by the system (Po), the frequency of the AC voltage (ω radians per second), the output voltage (Vo) and the peak-to-peak voltage ripple allowable (Vr)

So would I be close to assume that the Po and the Vo would come from the datasheet for the H11AA1 and the Vr would be small enough to stay within the Vmin and Vmax?

If I am way overthinking this feel free to tell me, I can take it.

Thank you for the direction pointing.

Not sure what you are saying.

100ms is like a filter i.e. the A.C. has to disappear for 100ms then the solenoid LED goes out.


Do some experimenting with the sketch.

unsigned long dropoutInterval = 100;
Change the line above to:
unsigned long dropoutInterval = 10000;

You should see the solenoid LED go out 10 seconds after you let go of the switch.
If you tap the switch within the 10 second interval, the 10 second interval starts over.


You can make as many timers as you need.

If you add the capacitor and diode into the schematic, you do not have to worry about filtering the output of the OPTO.

You can now treat the signal on pin 2 as if it was any other switch.

If you need to, tune the value of C1 try: 1uF or 0.1uF or 10uF.

JCA34F:
Use a 47 to 100nF cap and put a 10k pullup resistor from +5V to the H11AA1 output pin, when you turn power on, that fat, discharged cap is pulling the input pin LOW until it can charge through the 30k internal pullup.
Is that a 220 Ohm pulldown resistor on the MOSFET gate? Should be at least 10k.

There is a 10k on the bottom for the MOSFET gate, the 220 Ohm is for the LCD.