I develop a system that filters water. I added two solenoid valves connected with a relay to the circuit. and uploaded this code to check if they worked well or not:
#define valves 10
#define led 2
void setup()
{
pinMode(valves,OUTPUT);
pinMode(led,OUTPUT);
}
void loop()
{
digitalWrite(valves, HIGH);
digitalWrite(led, HIGH);
delay(5000);
digitalWrite(valves, LOW);
digitalWrite(led, LOW);
delay(5000);
}
then, I turned the power supply on and observed that the microcontroller (ATmega328p) executes the first two lines in the loop() which are digitalWrite(valves, HIGH);
and digitalWrite(led, HIGH);
and doesn't change the state of the relay and the led into LOW state after 5 seconds, in addition to executing random instructions that does not exists in the code like toggling any I/O pin.
here is the circuit:
I tried to solve this problem. I measured the input current and the output current of the adjustable voltage regulator (LM317). The input current was 100mA and the output current was 90mA.
The LM317 was very hot, so much so that you can feel the heat when you approach your finger to the LM317. Although the regulator was very hot, it still regulates 5V and it does not change.
I changed the LM317 circuit to regulate the 33V to 14V and added a 7805 fixed regulator. I thought that I reduce the dissipated power in the LM317 therefore, the heat will be less and the microcontroller will work properly. I turned the power supply on and the 7805 regulator was super-heated and the LM317 was warm. but they still make the 5V.
When I disconnected one of the valves from the relay and turned the power supply on, the microcontroller executed the code well for a while and stopped executing it. when I disconnected the both valves, the microcontroller executed the code well and didn't stop.
this is the water inlet valve which I use in my project:
EDIT:
I replaced the 470uf capacitor with 2200uf capacitor. Moreover, I added
- 10uf electrolytic capacitor
- 1uf electrolytic cap
- 1uf ceramic cap
- 100nf cap
- 10nf cap
- 1nf cap
near the microcontroller I also added a flyback diode for each relay
But the problem was not solved. The device still the same.