New to the forum - have Googled a bit to try and find a solution but didn't really get anywhere..
I'm building an arcade claw/crane machine and all the electronics pretty much work as expected - here's a "walk through" video I made for a non-technical friend:
The claw unit uses a load of switches to detect when the claw's in its home position, whether the actual claw has been dropped fully etc
My problem is that - after a few minutes of usage - the digitalRead from the switches in the claw unit starts returning the wrong value (i.e. randomly returns 1 when the switch isn't pressed).. and that causes the program to stop claw movement early thinking it's already done it's job (leaving the claw in the wrong position/half-dropped/etc)
Basically the three motors, solenoid & five switch "sensors" that handle the claw movement are connected individually to the Arduino via 15 wires (wrapped into one big cable).. I'm wondering whether the long wires connected to the switches are being randomly induced(?) by the motor wires, etc, "simulating" button presses?
I've found forcing a delay() before digitalRead seemed to improve the problem (not sure why though- maybe because it means waiting a little after enabling the motors?)
The switch pins are pulled high in the program (digitalWrite(X, HIGH)), so I'm pretty sure it's not a floating issue..
Hopefully someone with more experience/etc will know where I'm going wrong
Thanks!
Edit: P.S. the motors run at 12v max ~4amp (I'm not near the project ATM & can't remember the exact current), the grab solenoid at 48v ~1-2amp. Just realised that the solenoid is always powered when the problems occur
I think your motor/solenoid wires inducing false switch readings in this 15-pin cable is a pretty good theory.
What doesn't make sense is that it only happens "after a few minutes of usage".
Any way you can separate out the switches from the high-current signals (motor/solenoids) onto separate cables?
Waiting a bit until after switching a solenoid makes sense as the current spike will have passed. You can also try filtering your switch presses in software: take 5 readings (for example) and don't consider the switch pressed until all 5 readings are the same.
--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons
RuggedCircuits:
You can also try filtering your switch presses in software: take 5 readings (for example) and don't consider the switch pressed until all 5 readings are the same.
Ah, I didn't think of that - I'll try that and see if it works as expected
RuggedCircuits:
Any way you can separate out the switches from the high-current signals (motor/solenoids) onto separate cables?
I can't because one of the metal-wrapped looms can't be removed without desoldering all the switches and motors (which I could physically do but obviously don't want to). If I removed the longer metal wrap and separated the cables in that loom I'd still have the other shorter loom potentially causing problems.
I'm gonna try disabling the solenoid in code though (if the multiple-readings suggestion doesn't work) to see if that's what's causing it (and hopefully then come up with a solution if that is the problem)
I won't be able to work on the project at all for about three weeks, so I can't tweak it right now & post the results