Turning 0V/0.1V into digital LOW/HIGH?

Hi!

I am working on a circuit for train detection on a model railroad using current sensing.
The diode voltage drop when a car or engine is detected is 0.1V.

While I can use analog read for this, I wonder if there is a simple way to turn this small
voltage into a high/low signal, so that I can use all Arduino I/O pins and not just the analog ones?

Each detection block requires a circuit like the one below, so that’s why it is key that only very
few components are needed. Otherwise I’ll just use a couple more Pro Mini’s to get the number
of analog inputs I need.

Any thoughts on this?
I have some experience with circuits, but I’m by no means an electronics engineer and any help
would be appreciated.

Thanks,
Kay

Diode_Circuit.png

Hi.

Diode_Circuit.png

Can you also mention the values used for those components ?

Used an LM339 voltage comparator.
Use a forward biased 1N34 as a reference with a voltage divider.
.

MAS3:
Hi.

Diode_Circuit.png

Can you also mention the values used for those components ?

Sure!
220 ohm resistors and a 1uF cap to turn the square wave AC signal into cleaner DC.
1N5400 diodes and a 1N4148 to clip the negative voltage.

LarryD:
Used an LM339 voltage comparator.
Use a forward biased 1N34 as a reference with a voltage divider.
.

Thanks Larry, but I need 30 or more detection circuits.
Adding comparators and such adds too many additional components
and using additional Pro Mini's would be much cheaper and easier to
build.

Kay

For your future reference, there are 4 compactors in each chip.

Do you need 30 individual input points or can they be ORed together to 1?

Why D3 ?

That circuit first drops 0.65volt across the 1N5400 diodes, and then almost all of it is thrown away with D3.

You could replace D3 and C1 with a small signal transistor, e.g BC547.
Then you have an open collector output that can switch an Arduino pin with pull-up resistor to ground.
A cap across the pull-up could smooth, and kill spikes.
Leo..

LarryD:
For your future reference, there are 4 compactors in each chip.

Do you need 30 individual input points or can they be ORed together to 1?

Why D3 ?

The DCC signal is 14v AC and I'm using the diode to partially rectify the AC square wave
the signal is comprised off.
They have to be individual inputs that monitor current draw on different parts of the railroad
track.

Wawa:
That circuit first drops 0.65volt across the 1N5400 diodes, and then almost all of it is thrown away with D3.

You could replace D3 and C1 with a small signal transistor, e.g BC547.
Then you have an open collector output that can switch an Arduino pin with pull-up resistor to ground.
A cap across the pull-up could smooth, and kill spikes.
Leo…

The DCC signal is actually 14V square wave AC that transmits power to the engines and command signals
to the decoders build into the engines to control their movements.

I’ve measured around 260mV at the resistors when a 1mA current is going through the diodes. That is roughly
what an engine draws when it’s not moving. Or a train car with a 10k resistor on one of its axles.

Don’t I have to rectify the AC before I drive a transistor with it?

Below are scope snapshots of the signal at the resistors and the second at the output of the D3 and C1.

Kay

At resistors.jpg

Recified.jpg

Voltage across the two 220 ohm resistors max is .7 volts.
voltage across one 220 is .35 volts.
voltage to turn on D3 > .5 - .6 volts.

Hence only leakage current goes through D3.

.

drgonzo:
Don't I have to rectify the AC before I drive a transistor with it?

The BE junction of a transistor is basically a diode, so it can be used as rectifier.

Do you want to detect current/no current (with some threshold). So a digital output.
Or do you want to know how much current is drawn. An analogue output.

First case can be done with a transistor (or opamp).
Second case has to be done with an opamp.

Do you want to detect/measure current in both directions (your circuit does not do that).
Leo..

Why invent the wheel again?

I always use the improved version of the Lenz LB100.


You can skip the opto if you really want to but then you have to pay extra attention to the common ground part and can go wrong with multiple boosters. You can make it easily on a proto board. I have a image of that if you want to.

Whole page [rl=http://people.zeelandnet.nl/zondervan/bonte%20verzameling.html]here[/url].

The only simple hardware way is to use comparators - you can have a common reference voltage to compare with and each LM339 is actually 4 comparators in one package and extremely cheap. Note you must use
pinMode (p, INPUT_PULLUP) for the output of most comparators including the LM339.

Otherwise its analogRead.

Make sure to protect chips against negative voltages (a series resistor is probably the simplest way to limit
the current).

septillion:
Why invent the wheel again?

I always use the improved version of the Lenz LB100.


You can skip the opto if you really want to but then you have to pay extra attention to the common ground part and can go wrong with multiple boosters. You can make it easily on a proto board. I have a image of that if you want to.

Whole page [rl=http://people.zeelandnet.nl/zondervan/bonte%20verzameling.html]here[/url].

Well, this looks promising!
You wouldn't happen to have that webpage in English as well, would you?
I guess I can try to use google translate to figure it out.

Does that circuit work with 14v DCC (N Scale), and does it detect currents as small as 1mA?

If so - I'M SOLD!! :slight_smile:

Thanks,
Kay

Wawa:
The BE junction of a transistor is basically a diode, so it can be used as rectifier.

Do you want to detect current/no current (with some threshold). So a digital output.
Or do you want to know how much current is drawn. An analogue output.

First case can be done with a transistor (or opamp).
Second case has to be done with an opamp.

Do you want to detect/measure current in both directions (your circuit does not do that).
Leo..

Just no current or current >=1mA. That will give me reliable train detection.
Current in one direction is fine.
I'll try replacing D3/C1 with an NPN transistor to see what the signal on the collector is.

I'm quite sure you could daisy-chain 4 of these and inexpensively monitor up to 32 inputs on just one data line and use only one Arduino.

For monitoring the output of an opto-isolator with the above Shiftin circuit, you could connect the collector to 5V and emitter to the CD4021 input.

drgonzo:
Well, this looks promising!
You wouldn't happen to have that webpage in English as well, would you?

I don't have it in English no. But the part around this detector isn't that much. It IS designed for DCC tracks. Don't know the threshold but you should be fine. It's low enough to not have ghost detections but a DCC loc without light and standing still is detected fine. I only used it with H0 but many other people use it with N. It's an improved version of the detector Lenz sells :slight_smile:

Dutch to English for the image :
verbeterd = improved
opnieuw verbeterd = improved again (so the best working version)
meetwaarde = measurements (to debug it if needed, done with 20V DC connected (makes debugging more easy :wink: ) with K as GND)
vrij = free (= no current)
bezet = occupied (= current)

septillion:
I don't have it in English no. But the part around this detector isn't that much. It IS designed for DCC tracks. Don't know the threshold but you should be fine. It's low enough to not have ghost detections but a DCC loc without light and standing still is detected fine. I only used it with H0 but many other people use it with N. It's an improved version of the detector Lenz sells :slight_smile:

Dutch to English for the image :
verbeterd = improved
opnieuw verbeterd = improved again (so the best working version)
meetwaarde = measurements (to debug it if needed, done with 20V DC connected (makes debugging more easy :wink: ) with K as GND)
vrij = free (= no current)
bezet = occupied (= current)

Great - thanks a lot!
I'll put this on a breadboard and give it a whirl.

Kay

You can make it real easy on a stripboard. Image here. On the left a normal 5.08 screw terminal can be fitted.

Yeah - that'll work. :slight_smile:

How do you use block detection?
Just to drive signals, or for automation with JMRI and such?

I came across a very simple Arduino project to get BOD back to JMRI
via LocoNet. These current sensor circuits are going to be the frontend
for this.