AVR acts weirdly when a 12 V solenoid valve is connected to it with a relay

Discussion in 'Embedded Systems and Microcontrollers' started by chathurinda, May 28, 2017.

  1. chathurinda

    Thread Starter New Member

    May 28, 2017
    2
    2
    Hi , I'm doing this soil moisture sensing project with a solenoid valve to automate the watering using an atmega32A microcontroller . I'm using external power pack to give 12 V to the solenoid valve and 5 V regulator to convert the 12 V and give to the microcontroller. I've attached the 12 V solenoid valve with a relay to the microcontroller. and I have added a LCD to display information.I have included 2 interrupts in the code which will display 2 messages in the LCD .

    The relay switching and everything works fine with the 12 V supply until I attach the solenoid valve to the other side of the relay. and when the 12 V solenoid valve is connected those interrupt functions starts showing up in the LCD even when I'm not pressing the interrupt switches.and the circuit sometimes gets reset. and sometimes other characters starts showing up on the LCD.

    if anyone can help I would be grateful !
     
  2. bertus

    Administrator

    Apr 5, 2008
    19,582
    3,996
    Hello,

    How are the parts connected?
    Are you using a backEMF diode on the valve?
    Can you post a schematic?

    Bertus
     
  3. Picbuster

    Well-Known Member

    Dec 2, 2013
    916
    119
    Agree with Bertus however: a bare solenoid is using current and will create spikes positive and negative ones.
    Action should betaken to diminish that.
    Power supply impedance is also having effect.(if both supply and circuit at full load are identical voltage will drop 50%)
    Next: the decoupling of processor(s)
    Next: getting all the transients from processors power supply circuit.

    But again if you want help post schematic.
    Picbuster

    Mod edit: language
     
    Last edited by a moderator: May 28, 2017
  4. JohnInTX

    Moderator

    Jun 26, 2012
    3,686
    1,913
    In addition to the good advice above, be sure to use separate power lines (power and ground) for the processor/LCD and other ugly stuff. Route each pair back to the source power and decouple there.

    Consider that transients can show up on the inputs and that you might need to consider debouncing them.
    Junk on the LCD can be from transients on the E line.
     
  5. chathurinda

    Thread Starter New Member

    May 28, 2017
    2
    2
    thanks everyone for the help ! I figured out how to solve it , it was the back emf from the solenoid. I used a 1000 uF / 35 V capacitor and a diode near the solenoid and it worked !
     
    JohnInTX and DickCappels like this.
Loading...