Emergency Stop with ESP32

Hi there;

I am using esp32, solenoid valve in a project. The solenoid valve I use is bistable (latching) working. It opens when I give + pulse, it closes when I give - pulse. I am operating the system with 6.7V adapter. I want to create an emergency stop scenario. If there is a power cut while the water is on, I want the system to detect this and automatically cut off the water flow. The first method that came to my mind was to use a voltage divider and a high-capacity capacitor. I lowered the 6.7V power supply voltage to 3.3V with a voltage divider and connected it to the ADC pin of the ESP32 and took a voltage reading. I then connected a 2200uF capacitor in parallel with the power supply. I am sharing the schematic of the connection I described below with you.

Ekran görüntüsü 2023-07-05 083442

I am also sharing the code I wrote about emergency stop with you.

void EMERGENCY_STOP()
{
  float ADC_Value = (float)analogRead(34) / 4095;
  float voltage = ADC_Value * 3.3;
  if (voltage <= 3.2)
  {
    digitalWrite(SOLENOID_PIN_1, LOW);
    delay(12);
    digitalWrite(SOLENOID_PIN_2, HIGH);
    delay(10);
    digitalWrite(SOLENOID_PIN_1, LOW);
    digitalWrite(SOLENOID_PIN_2, LOW);
  }
}

The system works as I want with this schematic and software. When I unplug the power supply, the solenoid valve can close thanks to the voltage stored in the capacitor. My question is, is there any other way to do this? I think the capacitor should definitely be used as a backup power supply but what else can I use other than a voltage divider to read the power supply voltage?

Another method I tried was to use a regulator. I dropped the voltage by 3.3V using the LM1117 and connected the output leg of the regulator to the ADC. But the problem I have here is that when I cut off the electricity, the voltage dropped slowly due to the regulator and when the system realized that the electricity was cut off, there was no energy left in the capacitor to close the solenoid valve.

Is there a method you would recommend? Thank you for your support in advance.

Estop and safety circuits should be hardware only so no cpu failure can prevent safety.

I’d agree - something like a conventional solenoid held open by the mains supply might do it .
You need to look at what you mean by emergency stop - what are the consequences of loss of control - ie is it really an emergency ? Arduino is not suitable for safety critical situations , it’s a hobby item .

1 Like

Use this type of switch to generate a Emergency Stop for the system.

grafik

In my project, I control the solenoid valve with the internet. As a scenario, the user turned on the water over the internet. If the power goes out before the user gives the command to turn off the water, I planned to make a precautionary mechanism to prevent the water from flowing unnecessarily until the power returns. I've also done this with a voltage divider. I'm wondering if another method can be applied?

How you do it , depends on the consequence of not turning the water off -do you just waste water or does someone die - dependant upon the consequence , determines the action to be taken .
Also when power returns how does your device react? What about battery backups?

Probably "Emergency Stop" isn't the best phrase to use here. I think "Emergency Valve Shut Off" would be better because we don't want to stop the ESP32, just want to react quickly to a minor brown-out on the power supply while there's still enough time to send a pulse to turn off the valve.

I think using an interrupt would be the best solution to ensure the best reaction time to a voltage drop. I haven't tried this, but it seems the touch interrupt could be an ideal solution. Just use a touch input rather than an adc input.

Yes, you are right. I used the wrong term. "Emergency Valve Shut Off" is a much more accurate term. Thank you for your suggestion. So should I continue using a voltage divider to detect voltage drop or is there another voltage sense method you can recommend?

Your voltage divider circuit looks good and is probably the best solution for detecting the power supply voltage. If the length of the wiring is long, it might be a good idea to add a 0.1μF cap at the IO34 input to prevent any noise pickup from becoming an issue.

thank you for your advice. I continue to test the power outage and I observed a problem. My test is actually very simple. I open the solonoid valve and unplug the adapter and observe how the circuit behaves when the power goes out. I noticed that sometimes it closes the solenoid valve, sometimes it doesn't. This may be because the capacitor I use as a backup power supply also powers the voltage divider circuit. Therefore, even if I cut off the power, due to the capacitor, the ESP32 takes a measurement of 3.3 volts for a certain period of time and realizes that the power has been cut late. Therefore, when the ESP32 realizes that the electricity is cut off, there may not be enough voltage in the capacitor to close the solenoid valve. This is not always the case, it happens sometimes. But how can I avoid this?

Cannot do without power ...apparently...sorry.

It actually has a power supply. There is a capacitor as a backup power supply. The 4700uf 16V provides me with the necessary power for a short time, I just need to detect the power failure fast

I think post #3 would be the best solution. Without the valve failing and no power the water will stop. At this point you need power to turn it back on. If you use the processor to turn it off in a fault condition it may crash and leave the valve on. By chance is this for a sprinkler system? If so you could simply put one mains control valve in the main feed and shut all the zones water off.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.