Solenoid trigger voltage to digital output

Thread Starter

steveT1968

Joined Aug 18, 2018
10
Hopefully someone will have the answer I'm looking for. I have looked for old posts on this, but found none.

I am trying to take a solenoid actuation pulse (12-18v) and feed it as HIGH into Arduino (attiny or atmega ultimately). The solenoids are 2 coil, 3 wire, The intent is to output an action dependent on the solenoid last direction change. I have the programme and outputs working fine, but can not get the input from the solenoids to the correct level. I have tried using opto isolators (4N25), opamps (LM324), transistors (BC557) and combinations of these. I will next try voltage division, but may struggle to get a digital HIGH level voltage from both 18v and 12v after division.

Have I been over thinking this, and there is a simple solution? Any suggestions for a solution?

I will post some circuit diagrams I have tried later, they are on a computer not connected to the web.
 

AlbertHall

Joined Jun 4, 2014
10,074
You could use a resistor and zener, or resistor and schotky diode to arduino supply.

What was wrong with the 4N25 method, that should work nicely?
 

dl324

Joined Mar 30, 2015
11,020
Welcome to AAC!
Have I been over thinking this, and there is a simple solution? Any suggestions for a solution?

I will post some circuit diagrams I have tried later, they are on a computer not connected to the web.
A voltage divider should work. Will know better after you post a schematic.
 

Thread Starter

steveT1968

Joined Aug 18, 2018
10
Hope this works.

Shown are the opamp and opto isolator versions. The complete circuit is shown for the opamp one. Replace the opamp with the opto circuit for that version without the diode on the solenoid common, which is there in case of AC solenoid activation.

examples of tried methods.jpg
 

dl324

Joined Mar 30, 2015
11,020
Cropped schematic with some whitespace removed:
upload_2018-8-18_13-28-32.png
You are misusing the opamp by exceeding the common mode input range. For LM324, that will likely cause inversion on the output. LM324 only work well with a 5V supply when the input is 0-3V, and the output only guaranteed to get as high as 3.3V.

If you're going to operate open loop, a comparator would be more appropriate.

EDIT: What are REFx in the lower schematic?
 
Last edited:

Thread Starter

steveT1968

Joined Aug 18, 2018
10
EDIT: What are REFx in the lower schematic?
Just something DesignSpark put in. They are where it connects into the rest of the circuit when I tried it instead of the opamp.

a comparator would be more appropriate
I have some 3702C here somewhere. I will find a spec sheet and see if they can do what I want.

I think part of the problem is that the input from the solenoid trigger can be either AC or DC.
 

AlbertHall

Joined Jun 4, 2014
10,074
I think part of the problem is that the input from the solenoid trigger can be either AC or DC.
If it is AC then the output from either circuit will be a series of pulses which may cause problems. In the optocoupler circuit this can be fixed by connecting a capacitor across the phototransistor to smooth out the pulses.
 

ebp

Joined Feb 8, 2018
2,332
EDIT: Oops! I missed the bit on AC or DC, though it really doesn't change much except the possible need for filtering and it makes the inverse diodes across the optocoupler inputs essential. If possible, configure the processor inputs as Schmitt triggers so they cope with the signals that will be at "undefined" voltages (on transitions with filtering of AC; twice every half cycle with unfiltered AC)
===

I would use a series resistor of about 2k between the solenoid terminal and a 4.7 volt 1/2 zener diode to ground with a 4.7k resistor in parallel with it. I would use a resistor of about 10k between the cathode of the zener and the processor port pin. Don't use internal pull up or pull down resistors.

The zener will clamp the voltage at about 4.7 volts, which is a good clean logic HIGH for a processor running on 5 volts. The 2k resistor will limit the current to about 7 mA with 18 V at the solenoid (which presumably is small relative to the solenoid current), and about 3.6 mA with 12 V. The parallel resistor is necessary to provide the logic 0 (which is what is missing in your opto circuit - nothing assures the input is pulled to ground when the optocoupler is off). Things can get messy if the processor is not powered when the solenoid is. Instead of current flowing through the zener it could flow through the protection diode at the port pin and thereby try to power the whole circuit. Adding the 10k resistor reduced the maximum current that could flow in that case to about half a milliamp, which should be safe (the Atmel datasheet is bad in this regard and protection diode current is not specified; most protection diodes will handle at least 2 mA, but less is safer). The zener will also protect against voltage negative with respect to processor common ("ground') by conducting in forward mode like an ordinary diode. You don't want to use internal pulling resistors because they would form a voltage divider with the 10k resistor.

The optocoupler scheme is "safer" because there is no possibility of driving the processor input above its supply voltage under any conditions. The 4N25 is pretty dismal. It is one of the oldest optocoupler designs still being made and the current transfer ratio (CTR) is low. For this circuit that won't matter much, since you only need a fraction of a milliamp in phototransistor. The 4N35 isn't quite as ancient and has much better CTR. It's still cheap. Again, you must have a resistor between the input and circuit common to establish the logic LOW level. I'd probably use 10k. With a 4N35, about 1.5 mA in the IRED would assure good output saturation with a 10k load resistor, so a 6.8k or 7.5k resistor would be suitable in the input circuit. With a 4N25 I'd probably use about 2k, but 1k is OK.
 
Last edited:

AlbertHall

Joined Jun 4, 2014
10,074
I would use a series resistor of about 2k between the solenoid terminal and a 4.7 volt 1/2 zener diode to ground with a 4.7k resistor in parallel with it.
If the input is AC then an additional rectifier diode and capacitor will be needed to provide a smooth DC to the resistor and zener.
 
Top