[UPDATE] Decoupling issues (?) during pin operation

Hello everyone, and sorry for having posted such a random topic.
I'd be glad if someone would recommend me a more appropriate title, as I can't figure out any better than the above.
To be honest I haven't investigated much on the forum, as I don't even have a clue what to search for :~ so, please, be easy on me as I'm quite lost...

Trying to explain myself.

In my current setup (but have met the problem countless times on several circuits) I have an Arduino UNO connected to four push buttons, four relays (with specific drivers), and an accelerometer MMA7361.
I'm using Firmata on Arduino and keep monitoring data using Firmata test.

Apparently everything works but whenever I push a button or trigger the relay, the accelerometers starts giving me random data.
(Quite) of course, when original conditions get restored (button no longer pressed or relay released) data return regular as expected.

My belief is that some transient current might interfere with the sensor or some quantumDimensionalBeing living in a distant galaxy connected thru a wormhole to my lab want to disrupt my plans.

Regardless on my considerations, is there any solution?
I'm quite new on electronics and I see often capacitors in the weirdest position OR resistance to ground just for pull-up/pull-down fun, possibly to overcome some of these issues.

Any chance I might get help here?

Thank you in advance.

Not much to work on without your sketch code and schematic drawing. However as a wild ass guess are you using proper debounce functions (either software or hardware) ? Bouncing button contacts can 'fool with' a lot of sketches.

Thanks Retrolefty for the reply. Once again, I stumble onto my ancestral issue on plotting software... shame on me, after a good half an hour I ended up with the horrible images attached.

And for the code, I use Firmata with some modifications to have "clean" data coming from PIN A0~A2:

(code exceed maximum post size, will attach as file)

Hope this could help... thanks a lot!



firmata_mod.txt (22.8 KB)

I stumble onto my ancestral issue on plotting software

What is wrong with the old standby of pencil and paper, then post a photo of it?

Hope this could help

No not really, that is way too little information.

The problem is probably lack of decoupling, it normally is. Have you got any decoupling around your relays, have you a reverse biased diode across them. A helpful schematic would show this.

If you don't know what decoupling is, which is a good bet if you are using Fermata, then have a read of this:-

Thank you Grumpy_mike for replying and everyone else for reading.
In a matter of fact my ancestral problem on schematics might go a little beyond software issues... :slight_smile: apparently I can't make a meaningful drawing. Still, for the sake of correctness, down below my best result (schematic.jpg).

To make an ugly drawing a little bit clear, the setup is REAL SIMPLE:
FOUR push button with a pull-down resistor on pins 2, 3, 4, 5
FOUR relay board on pins 6, 7, 8, 9 (mistakenly bought 12V, thus driven by four NPN BC337, as described in [partially solved] 12V relay not cooperating (mod.3393 to be used with Arduino) - General Electronics - Arduino Forum)
ONE MMA7361 accelerometer on pins 10, 11, 12, 13, A0, A1, A2 (as provided on standard examples untouched)

Rather than returning raw data from the accelerometer, Firmata modifications returns me Gforce "clean" data on pins A0, A1 and A2; code taken from G_force example; source attached to previous post.

In appearance everything works, data comes nice and clean from pin A0~2 (see firmata_before.jpg), relay board have optoisolators, buttons are "plain buttons" but whenever I press one of them or activate a relay, data from the accelerometers changes significantly.

[UPDATE]: While there are sudden spikes on data readout while pressing any button (pin 2~5) it seems that activating pin 6 and 7 INCREASES the average noise consistently (see firmata_6_7.jpg), but once deactivated makes data returning at the original values. Pin 8 and 9, instead, change NEGATIVELY numbers and they stay so.

Besides going to pick flowers, is anyone having recommendations for a poor and lost guy? :slight_smile:

Thank you in advance and greetings from northern Italy!

The reason I'm using Firmata is that seems the most viable solution to drive motors from a linux box using Python, but I'm open to recommendations :wink:


Thanks for the effort but those schematics do not show any more detail about your circuit than the original ones.

As to the inputs, you can get away with not using a physical resistor if you wire the switches to ground and enable the internal pull up resistors.
A full discussion on this is here:-

but whenever I press one of them or activate a relay, data from the accelerometers changes significantly.

That can happen if the ground return from your sensors is chained to the ground of your relay supply. You should try what is called a "star ground", that is where all the grounds from the separate sub system are joined at one physical point. This prevents effects from current draw causing what is called "earth lift" of the grounds.