24vac solenoid valve activation with 3.3v arduino

Hello everyone.
The objective of the project is to activate 2 solenoid valves with an arduino nano 33 ble sense.

The valves specifications: 24VAC, 350mA start up consumption, 190 mA hold consumption.
I have a 2A, 220 to 24V AC power supply.

I’m using the attached circuit as startup reference.

So far i’ve chosen the first resistor as 220 ohm based on an activation current of 15 mA for the MOC3010.

Then I have no experience with TRIACs and would like to hear a suggestion for the choosing the model (i’ve checked and local market has BT137, BT138 and BT139, also TIC 206/216/226/236/246).

  1. What would be the application differences between BTs and TICs?
  2. Cannot find in the MOC3010, the maximum output current, in order to select R20 and R19. Can you assist me in calculating these 2?
  3. Purpose of the TVS diode: Can this component be replaced by some other?

Thanks.

Can your 3.3V Arduino outputs supply 15mA? You may need a "helper" transistor. Don't forget to subtract the LEDs forward voltage (1.15V nominal) from 3.3V = 2.15 / 220 = 9.8mA.
I can't answer your triac question, but at that current, any of them should work. The TVS diode is needed for surge suppression.

I see a lot of SSRs, solid state relay, on Ebay that have a 24 vac lower limit. If your project was mine, I would go that way.

Paul

Solenoid with triac & optocoupler.png

JCA34F:
The TVS diode is needed for surge suppression.

Why would surge suppression be required when switched by a Triac?

JIC (just in case).

Your questions indicate that you have not used triacs and are learning about then.

Trying to control AC with DC can be difficult and the slightest mistake can get really exciting. If you think magic smoke is exciting.

If this is not a school assignment then using a device with isolation is highly recommended

SSR or icecube relay.

JCA34F:
Can your 3.3V Arduino outputs supply 15mA? You may need a "helper" transistor. Don't forget to subtract the LEDs forward voltage (1.15V nominal) from 3.3V = 2.15 / 220 = 9.8mA.
I can't answer your triac question, but at that current, any of them should work. The TVS diode is needed for surge suppression.

Thanks JCA. Arduino Nano 33 BLE sense says it can output up to 15mA. I'm not sure if it's intended for extended operations (this would be terms of half an hour twice a day). In any case, accounting for the LEDs forward voltage, I believe that it would be better for me to get the MOC3012 to be able to reduce the trigger current to 5mA.

Paul_KD7HB:
I see a lot of SSRs, solid state relay, on Ebay that have a 24 vac lower limit. If your project was mine, I would go that way.

Paul

dave-in-nj:
Your questions indicate that you have not used triacs and are learning about then.

Trying to control AC with DC can be difficult and the slightest mistake can get really exciting. If you think magic smoke is exciting.

If this is not a school assignment then using a device with isolation is highly recommended

SSR or icecube relay.

Thanks Paul and Dave. Not going for a SSR is just a matter of local availability. I will keep looking for in the meantime. A couple of questions:

  1. Doesn't the MOC30xx provide isolation by means of the optocoupler?
  2. Could I power the SSR directly with the 3.3v?

ignacio_g:
Thanks JCA. Arduino Nano 33 BLE sense says it can output up to 15mA. I'm not sure if it's intended for extended operations (this would be terms of half an hour twice a day). In any case, accounting for the LEDs forward voltage, I believe that it would be better for me to get the MOC3012 to be able to reduce the trigger current to 5mA.

Thanks Paul and Dave. Not going for a SSR is just a matter of local availability. I will keep looking for in the meantime. A couple of questions:

  1. Doesn't the MOC30xx provide isolation by means of the optocoupler?
  2. Could I power the SSR directly with the 3.3v?

Do you mean "control" the SSR? Look at the specs for the SSR!

Paul

ignacio_g:

  1. Doesn't the MOC30xx provide isolation by means of the optocoupler?

Yes, of course it does. :grinning:

ignacio_g:
2. Could I power the SSR directly with the 3.3v?

As long as the Arduino can supply the trigger current specified by the SSR and the SSR cites 3 V as the minimum of its required voltage. You do not need a series resistor for the SSR, it controls the input current itself.

Thanks. While I get the SSR, I've made a simpler attempt to turn on the Solenoids:

Considering I have 3.3V outputs, and a MOC3011 which requires a trigger current of 10mA, I thought a 220ohm resistor could work. This should have let me obtain (3.3v - 1.1v forward voltage of the led)/220 = 10mA.

Now, when powering up the circuit and activating the desired output, i'm only measuring 2.27V at the pin.
I am seeing 1.12v drop across the resistor which indicates a 5mA current is goign thru.

Anyone has a clue on why the output is not delivering the 3.3v?

Thanks.

Likely because the pin from the 555 is not a steady DC.

Paul

switch a small transistor, maybe 2n3004 with a 1k base resistor, that will power the MOC led thru 220ohm from 3.3V rail, if you only want it on-off, you are set, you should buy a snubber in case the triac isn't rated snuberless, or tends to stay on when it shouldn't. wikipedia:

"when a TRIAC has been conducting and attempts to turn off with a partially reactive load, such as an inductor. The current and voltage are out of phase, so when the current decreases below the holding value, the TRIAC attempts to turn off, but because of the phase shift between current and voltage, a sudden voltage step takes place between the two main terminals, which turns the device on again.
If the commutating dv/dt rating is exceeded, the device will not turn off. "

, a small inductive load like a solenoid should not be a problem imho.

The big problem begins if you want to phase angle control it, for lets say dimming the lights, then you need a phase detection circuit, and if you are driving strong inductive loads it gets very,very tricky

Semtex9:
switch a small transistor, maybe 2n3004 with a 1k base resistor, that will power the MOC led thru 220ohm from 3.3V rail, if you only want it on-off, you are set, you should buy a snubber in case the triac isn't rated snuberless, or tends to stay on when it shouldn't. wikipedia:

"when a TRIAC has been conducting and attempts to turn off with a partially reactive load, such as an inductor. The current and voltage are out of phase, so when the current decreases below the holding value, the TRIAC attempts to turn off, but because of the phase shift between current and voltage, a sudden voltage step takes place between the two main terminals, which turns the device on again.
If the commutating dv/dt rating is exceeded, the device will not turn off. "

, a small inductive load like a solenoid should not be a problem imho.

The big problem begins if you want to phase angle control it, for lets say dimming the lights, then you need a phase detection circuit, and if you are driving strong inductive loads it gets very,very tricky

Thanks Semtex, I guess I could add a transistor to amplify the current. However that does not explain why the output is not delivering the 3.3V it should, and that makes it complicated to calculate any current for the transistor as well right?

You attempted to post an image in #9, but on an inappropriate site.

Can we see the image please?

Attaching the wire diagram.

Just an aside: Generally a bad idea to wire switches to the supply voltage, especially the 3.3 V here.

Wire them to ground, put the pull-ups to 3.3 V on the board near the Arduino - you may not even need them if the wiring is not too long as you can use the internal pull-ups. That way you cannot have any "accidents" with the 3.3 V line and they are less susceptible to interference. :grinning:

Hi,
Can you post your code please?

Thanks.. Tom.. :slight_smile:

Hello,
Attaching code below. It accounts for 2 outputs even thou you can see only 1 in the wire diagram. The idea is to extend a second one once I can make it work.

As a note:

  • the output D12, with nothing connected to it, delivers 3.31v as expected when activated.

Adding a thought: Pins D11 and D12 are also listed as MISO & MOSI. I don´t know what this function means, but could it limit the current availability for these outputs?

Also I will attempt to set the output to High with a “while” instead of a “for”.

 //Defino pines
#include <ArduinoBLE.h>
  
  const int D2 = 2;     // D2 entrada para Sector Arriba
  const int D3 = 3;     // D3 entrada para Sector Abajo
  const int D6 = 6;    // D6 entrada para modo MANUAL
  const int D7 = 7;   // D7 entrada para modo Automático
  const int D11 = 11;  // D11 arranque sector Arriba
  const int D12 = 12;  // D12 arranque sector Abajo
  const long IntervaloRiego = 25000;
  const long DuracionRiego = 5000;
  unsigned long previousMillis = 0;
  unsigned long CuentaRegresiva = 0;
  int SectorArriba = 0;
  int SectorAbajo = 0;
  int ModoManual = 0; // debugging modo manual
  int ModoAuto = 0;
int ActivacionArriba = 0;
int ActivacionAbajo = 0;


void setup() {

  // initialize D11 & D12 as outputs
  // D11 va al opto que controla riego superior
  // D12 va al opto que controla riego inferior
  pinMode(D11, OUTPUT);
  pinMode(D12, OUTPUT);

  //entradas
  //D2 y D3 definen si riega arriba/abajo
  //D6 y D7 definen modo Auto/Manual
  pinMode(D2, INPUT);
  pinMode(D3, INPUT);
  pinMode(D6, INPUT);
  pinMode(D7, INPUT);
  digitalWrite(D11,LOW);
  digitalWrite(D12,LOW);
  delay(5000);
}

void loop() {

  //Leo entradas

  ModoManual = digitalRead(D7); // ;
  ModoAuto = digitalRead(D6); // 
  SectorArriba = digitalRead(D2);
  SectorAbajo = digitalRead(D3);

  //ActivacionArriba = digitalRead(D11);
  //ActivacionAbajo= digitalRead(D12);

//imprimo a serial para debug

Serial.println("ModoManual input is ");
Serial.println(ModoManual);
Serial.println();
Serial.println("ModoAuto input is ");
Serial.println(ModoAuto);
Serial.println();
Serial.println("SectorArriba input is ");
Serial.println(SectorArriba);
Serial.println();
Serial.println("SectorAbajo input is ");
Serial.println(SectorAbajo);
Serial.println();
//Serial.println("Estado de salida riego Arriba is ");
//Serial.println(ActivacionArriba);
//Serial.println();
//Serial.println("Estado de salida riego Abajo is ");
//Serial.println(ActivacionAbajo);
Serial.println("---------------------");
delay(2000);
  
    // activo modo manual

  if (ModoManual == HIGH) {

      if (SectorArriba == HIGH){
        digitalWrite(D11,HIGH);
        digitalWrite(D12,LOW);
      }
        else {
          digitalWrite(D11,LOW);
          digitalWrite(D12,HIGH);
        }
                           }
                           
      else {
        digitalWrite(D11,LOW);
          digitalWrite(D12,LOW);
      }
                           
  while (ModoAuto == HIGH) {
    
    unsigned long currentMillis = millis();
    Serial.println("ModoAuto Activado");
    CuentaRegresiva = IntervaloRiego - currentMillis - previousMillis;
    Serial.println("Tiempro para proximo riego:");
    Serial.println(CuentaRegresiva);
    ModoAuto = digitalRead(D6);
    
          if (currentMillis - previousMillis >= IntervaloRiego) {
          previousMillis = currentMillis;
          
              ModoAuto = digitalRead(D6);
              digitalWrite(D11,LOW);
              digitalWrite(D12,HIGH);
              Serial.println("Riego Abajo encendido");
              delay(5000);
              Serial.println("Cambiando sector");
              delay(2000);
              ModoAuto = digitalRead(D6);
              digitalWrite(D11,HIGH);
              digitalWrite(D12,LOW);
              Serial.println("Riego Arriba encendido");
              delay(5000);
              Serial.println("Riego automatico finalizado");
          digitalWrite(D11,LOW);
          digitalWrite(D12,LOW);
          ModoAuto = digitalRead(D6);
                                                              }

                            }
}

Hi,
Thanks for the code.
Did you develop this in stages?
You should have some code that JUST operates the output.

You have all sorts of stuff in your code.
Just write some code to operate the output and get that working, forget the rest until then.

Writing a mass of code then trying it is fraught with problems.

Tom... :slight_smile:

Thanks Tom.
I've tried reducing the code to just the output.
Tried with all D10, D11, D12.
As long as the MOC3011 is connected, the voltage output of the digital pin is reduced to 3.3v (edit: meant 2.3v).
Without charge, or with a tip120 transistor (tried before), the output works.
I guess the MOC3011 is asking for a higher current?