How to prevent Arduino Uno digital pin for being damaged using 12V device?

That would suggest that the coin acceptor is bad not D13. I think you jumped to the Wrong conclusion. It's very rare when only one pin is damaged and not others.

Test D13 by simply connecting/disconnecting a wire to ground.

It's highly unlikely that your circuit damaged D13
As I mentioned powering an Uno through the 5V output pin is not recommended.

1 Like

But you do have a voltage divider in your schematic.

The one that connects signal to 5-V through the 1K and 10K resistors and connects to D13 at the junction.

When the signal output is 0-V, you are dividing 0 to 5-V at D13. When the signal output is 12-V, you are dividing 12 and 5-V at D13.

When the signal is high, assumed 12-V as there isn’t any information on it, you will exceed the digital pin maximum voltage.

If you go to the link you provided, there’s a sort of datasheet and some additional information about the pulse width. There’s nothing about the amplitude.

You could divide the signal referenced to ground to bring it into a safe maximum voltage or use a voltage translator.

I tried testing the D13 pin with something else, like IR sensor, where using other pins (2-12, 14-19) the IR sensor worked, but in D13, the IR sensor is permanently low which I thought it’s damaged, but yeah dunno if it’s wrong conclusion, I should test it like you said.

If powering an Uno through the 5V output in isn’t recommended, what’d be the better way? (from what I know, using the 12V dc jack isn’t recommended either)

For dividing the signal to GND rather than 5V, it’s just moving the 10K resistor from 5V to GND?

Yes, that's all.
You need to confirm what the maximum voltage is that comes from the SIG pin.
Ideally it's a scope job as it's so fast.
A meter with max and min recording would do.
Alternatively, assume it's 12 volts and play safe.
I can't do the calculation right now, but I'll look at it tomorrow.
It will just be a case of adjusting the the 1K/10K ratio so that the 12 volt high is reduced to 5 volts max.
As a guide, 5K and 5K would give you 6 volts, but it has to be related to the right end of the resistor ladder.

Connect two resistors in series between the SIG output and the common ground.
At the SIG end use a value close to 14K and at the ground end use 10K.
At the junction of the the two resistors, the voltage will be close to 5 volts. Connect this to your digital input.
All this assumes that the SIG pin of your coin device outputs either zero volts or 12 volts

Only if you have many devices connected to the Uno.
What else is connected?

Since you are using 5V there is no need for a voltage divider. and it will not work
You must have a pull-up to 5V
If you damaged D13 then it is because you did something else wrong.

This is the correct circuit:

The coin output of the TW-130B is an open collector transistor.

Here is a better / easier to read User Guide to the TW-130B coin acceptor.

The coin output of the TW-130B is an open collector transistor.
The amplitude of the pulse is determined by the circuit that the user connects to the output.

The schematic shown in post #1 should work correctly.

There's no mention of open collector in the first post.

The link provided by the OP just gives the following

1 Gray Counter
Red 12V DC
2 White Coin signal
3 Black Ground
4 Gray Counter

The OP just refers in their schematic to SIG, nothing about the other outputs.

Page 6 of this manual.
TW-130B+Coin+Acceptor+User+Manual(1).pdf (4.5 MB)

Tom.... :smiley: :+1: :coffee: :australia:

Which is completely wrong
See post #27

Now that more information has come to light, it's easy.
Working with what the OP provided, not so.
What's the difference then, between Coin signal and the counter output?

The counter output is used to operate an electro mechanical counter, like the following:


The counter is used by the machine operator to tell him how much money he expects to see in the cashbox.
The counter is housed inside the machine, and can't be seen by the general public.

The grey wire connected to pin 4 is an open collector transistor.
A counter with a 12V coil is attached between that pin and the grey wire on pin 1 that has 12V on it.
The open collector transistor conducts briefly to advance the count.

The coin output is used by the machine's electronics to operate the game/vending machine.
This output is selectable between 'normally open' and 'normally closed.

When 'normally open' is selected the output is normally held high by a pullup resistor, and goes low for the duration of the output pulse.

When 'normally closed' is selected, the output is normally low, and goes high for the duration of the output pulse.

From the code that 89jvek showed in post #1, it can be inferred that he has the output set to 'normally open', as he is waiting for the output to go low to detect a coin inserted.

Well, I’m not focusing on the other devices here, but in my case, all the digital and analog pins are used, including this coin injector.

So to clarify, for your circuit, the 10K resistor isn’t connected from the Arduino Dxx pin to 5V, but from the coin SIG directly to 5V?

Thanks for clarifying that.
It makes sense now.
The OP just referred to SIG which didn't really make it clear what they were using.
I already use the little Omron counters on several projects.

Yes.
The 330 ohm resistor is to protect the Uno in case you accidently set the pin to an output (can happen when you are busy testing code).

Set the coin acceptor for N.O. output and the pulse duration to 100ms
SIG will go low when a coin is insered

I think your test program spends most of its time in "else" delay(), not reading pin 13.

Can I substitute this with 220 ohm?

If it's all you have but something larger would be better 360 390, 430,470, 510

If you only have a limited number of resistor values, then you could always put 2 x 220Ω in series to give 440Ω.