Interrupt randomly triggering on a simple Arduino - Coin Collector project

Hello,

I have the simplest project where the Uno is connected to a coin collector trough the digital pin 0. The Uno is powered by a 12V 1mA power adapter and the coin collector is connected to the Uno ground and powered by the Vin.

The code is very basic - every time the interrupt occurs it prints out a number. This works great with the coin collector and the coins are all identified and the numbers are all correct.

The problem is every so often the interrupt will happen without any coins being added. This happens when I plug in anything to the same power hub as the power adapter powering the project and also just at random times every few hours.

Any suggestions why this is happening and what should i read up on to solve this?

I think you have already partly identified the solution:

This happens when I plug in anything to the same power hub as the power adapter powering the project

Perhaps your power supply is noisy or not well suppressed (I assume you mean 12v 1A BTW). If you power the Arduino temporarily (eg for a day) from elsewhere does the problem still occur?

If not then it is your power supply; either change it for a better one (no, I don't know how to determine this but cheap Far Eastern ones are a common source of problems, they build down to a price remember) or put in some better power regulation/cleaning on your Arduino project (eg a suppressor coil, capacitors).

It could (but I hesitate on this one) be RFI interference when you plug something else in but I'd check out the power supply scenario first if I were you.

where the Uno is connected to a coin collector trough the digital pin 0.

1) Is the ground of the Arduino also connected to the ground of your coin collector? 2) Is the voltage from the coin collector in the range of 0 to 5V and not any bigger? 3) You should not be using pin 0 anyway because:- a) It is used for serial communications b) It is not a pin that can trigger an interrupt

I suspect that if things are actually wired up as you describe it only "works" by the merest of flukes.

1) Is the ground of the Arduino also connected to the ground of your coin collector? Not sure what you mean by that - the Arduino is powered by a 12V power adapter plugged in to the DC input. The coin collector ground goes in to the Arduino GND pin.

2) Is the voltage from the coin collector in the range of 0 to 5V and not any bigger? This one I do not actually know. The coin collector is CH-926, a model that is very popular in all the tutorials online, but the actual instructions on the device have only these two separate peaces of information:

Working voltage:12 V +-10% Coin WHITE Wire (Signal Wire)

So I'm not sure at what voltage is the signal from the collector.

3) You should not be using pin 0 anyway because:- * a) It is used for serial communications* * b) It is not a pin that can trigger an interrupt* The pin I use is marked as pin 2 or interrupt pin 0.

Check the voltage of the output of coin detector, as Mike said, and I also suggest to use a pull-up or pull-down resistor, depence on the interrupt if is RISING or FALLING.

Ciao, Ale.

The pin I use is marked as pin 2 or interrupt pin 0.

Then why did you say:-

the Uno is connected to a coin collector trough the digital pin 0.

The pin is NOT marked as interrupt pin 0 in any way.

Although it is called INT0 on the datasheet (as well as PD2).

You can hide this confusion from your code by saying

  attachInterrupt (digitalPinToInterrupt(2), my_isr, CHANGE);

Which means you only have to know about the standard pin numbers (and which of them support external interrupts)

After searching a bit, I read somewhere that the coin collector has a weak internal pullup to 12V.

With the signal (white) wire disconnected from the Uno, what voltage do you measure? What voltage do you measure with 10K pullup to 5V? What voltage do you measure with 10K pulldown to GND?

Your readings will help determine if the signal is internally pulled up to 12V, or is an active 5V signal, or is open collector type and if it is normally high or normally low. They will also help determine the best way to interface the signal to the Uno.

The problem is every so often the interrupt will happen without any coins being added. This happens when I plug in anything to the same power hub as the power adapter powering the project and also just at random times every few hours.

For high reliability, you might want to consider using an opto coupler and separate power supply for the coin collector. Place the opto coupler close to the Uno's input.

|500x263

Mike, you are totally correct - the interupt pins are not marked anywhere on the Uno. I have been using this to check witch pins to use and simply got confused. |500x385

Now for the voltage checking - unless the Arduino can do that somehow, I do not have the tools or the knowledge to check those, so investing in the tools will be a last resort if all else fails.

I have ordered all the parts that dlloyd and Ralph_S_Bacon suggested and those will be tested, but there was a huge revelation while testing the pulldown resistor option:

When I power the arduino from a different source but plug in a high wattage to a power source near the arduino the interupt triggers. I must stress that the power sources in no way connect - the arduino is powered trough the USB from a tablet and the tablet is not connected. The coin collector is connected but due to low voltage not powered. I also tried disconnecting the power for the coin collector and powering it from a different source, but the signal allways triggers if a high wattage device is plugged in nearby.

I do not have the tools or the knowledge to check those, so investing in the tools will be a last resort if all else fails.

Sorry but no. Test equipment is not a last resort if everything else fails, it is a vital and essential part of electronics. A digital volt meter can be had from a thrift shop for less than $10. As for skill, put it on the volts range and connect it between ground and your output signal. The results will tell us what sort of method you need to correctly connect your device to the Arduino.

but the signal allways triggers if a high wattage device is plugged in nearby.

This suggests that you are not connecting it in the way it needs to be connected. It suggests to me that the input is floating. This could be due to the coin box having an open collector output. But before this can be remedied you need to know that that is the case, otherwise you could damage the coin box or the Arduino or both.

Ok, I have checked the voltage and its 11,7V going in to the coin collector. The signal wire is 0.04V when nothing is happening and from 0.18V to 1.4V depending on what signal is being sent (depending on the coin). The pulldown resistor 10K changed the signal to a 0.14V, that is assuming I am using it right. No change what so ever on the signal wire, when an appliance is being plugged in and the phantom interrupt triggers.

What are you using to take the voltage readings?

Since you've already had it connected directly, and the signal seems to be weak/low voltage with 10K pulldown, then maybe you could try this. Note: need to use 10K pullup resistor to 5V, then use FALLING interrupt mode in code. The 0.1µF is recommended for hardware filtering and debouncing.

For the voltage readings I am using a UT20B multi-meter.

I have tried dlloyds latest option and while the coins are counted correctly, the same still applies with the appliances being plugged in and the interrupt triggering. I did use a 330nF capacitor, if that changes something.

I have also tried the one with the opto coupler, but that one did not work, and no signal went trough to the arduino.

I did use a 330nF capacitor, if that changes something.

No that's fine. I would first try a 1K pull up resistor before anything else.

EDIT: Please try Grumpy_Mike's suggestion first (1K pullup) and let us know what happens.

I have tried dlloyds latest option and while the coins are counted correctly, the same still applies with the appliances being plugged in and the interrupt triggering. I did use a 330nF capacitor, if that changes something.

OK, if you disconnect the white wire from the input, does false triggering still happen when the "appliances" are being plugged in? By saying "appliances", do you mean "USB devices" that are being plugged into the hub? Does the USB hub have a DC power adapter plugged in? (this is required) Have you tried using a different USB cable and/or a different USB hub?


The next thing would be to better understand the signal on the white wire. I know you have already taken some readings, but for more clarity, could you answer the following? Note: keep the black wire connected to Uno's GND.

  • With the white wire disconnected from the Uno, what voltage(s) do you measure (from the white wire to the black wire)?
  • If you connect a 1K resistor from the white wire to Uno's 5V, what is the white wire's voltage(s)?
  • If you now connect the same 1K from the white wire to GND, what is the white wire's voltage(s)?

Having the above answers, it should be possible to use the opto-coupler after adjusting some resistor values.

P.S. When you previously tried the opto-isolator, did you change the input pin's mode to INPUT_PULLUP in your code?

So I tried using a 10K pull up resistor from the Vin and i measured a 1.1V constant signal. The coins were counted correctly, but the appliance thing still happened.

If I disconnect the white signal wire from pin2 it is constantly triggering as RISING without me doing anything.

By appliances I mean anything that uses power. That includes: an electric water kettle, a desktop lamp, a phone charger, a pc monitor and even the light switch of the room. Plugging in any of these anywhere nearby my project triggers an interrupt RISING reaction with startling precision. I have tried a whole manner of different power sources / plugging in locations and this reaction of triggering seems pretty stable.

  • White wire disconnected from the arduino and not triggering is about 0.04V and when the signal is triggering it goes up to 1.4V depending on the signal (the coin used).
  • If i connect a 1k resistor from the 5V and in to the white wire from the coin collector without plugging in the wire to the arduino I get about 0.06V
  • If i connect a 1k resistor from 5V to the white wire and the white wire to GND I get about 0.01V It might be because im using the Vin to power the coin collector so the 5V is not giving anything?

P.S. Yes I did change that as well, but nothing from the opto-isolator

GreenAzz: Mike, you are totally correct - the interupt pins are not marked anywhere on the Uno. I have been using this to check witch pins to use and simply got confused.

That's not your fault. That's the fault of those people that made such things confusing. That is.... sometimes calling it this particular pin, and then sometimes calling it that particular pin (or function that gives people the impression that it is a pin). That's the kind of stuff that creates the confusion. To avoid confusion, documents should say something like 'pin 2' (aka interrupt 0, or associated with interrupt 0 functionality...etc).

Try putting a electrolytic capacitor (eg 100 microFarad) from the 5V supply pin of the arduino to a GND pin of the arduino.

And I do agree that a pull-up resistor (like 1 kOhm pullup) is the way to go.

Southpark: To avoid confusion, documents should say something like 'pin 2' (aka interrupt 0, or associated with interrupt 0 functionality...etc).

The 'attachInterrupt()' page of the "Reference" does exactly that. It also recommends the use of 'digitalPinToInterrupt(pin)' to avoid problems. (As MarkT said in reply #6.) attachInterrupt()

OldSteve: The 'attachInterrupt()' page of the "Reference" does exactly that. It also recommends the use of 'digitalPinToInterrupt(pin)' to avoid problems. (As MarkT said in reply #6.) attachInterrupt()

I just checked that ..... that one is nicely written.