Hi, @klausts
Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
Can you please post some images of your project so we can see your component layout.
These are low voltage simple Servos SG90's. The breadboard hookup works fine. Others in the Model Railway community have used these for a while now. They use150-250 mA. and 4.7 - 6 V. And as mentioned, on a breadboard prototype everything did work. People have used as many as 6 when using the analog pins as well.
When wired into the layout using an Nano expansion board everything still worked when tested for itself. Only when other devices ran nearby did the servos react to power being turned on or off on those devices or a small electric motor that turns a turntable is run.
The question is why are the servos reacting to external activity to their own circuit?
Those certainly are low powered servos. Even so, random googling shows me stall current at 350mA - the lower numbers are presumably for when it's started up.
I'd estimate that ninety percent of servo problems posted here are power related and are solved with a separate power supply for the servos.
You might try a test powering them with four AA batteries to reduce the risk that you're getting a spike when other devices are starting up. As @TomGeorge is hinting, you may want to defend all the wires running to the servos from electrical interference too.
Power is from a Raspberry Pi usb charger 5V 1A.
I made a short video of this prototype running with one servo.
As you can see, it works as it is supposed to. On the actual layout when a train motor or other motor is run the servo changes position. When the turntable motor runs the servo connected to pin 6 jumps to 0 degrees. None of the wires run more than 12 inches in length from Arduino pins to servos or button switches. Hope that helps.
It is better for you to keep them as jpg and place them into your posts.
Some forum users have difficulty with pdf type files because of the platform they use.
draw on envelope, take picture, post. It's that simple.
Why? Look at your images. Your connection wires often obscure the label of their connection point, making it impossible to figure out what the wire is connected to. We don't have your boards or spec's for them in our hands, so we have no hope of seeing what it is you're connecting, where.
Schematics are excellent communication tools, though not complete. So are photos. So generally, both are best when communicating.
C
I do my schematics with a very simple CAD because if I drew the circuit by hand (mud map) you wouldn't be able to read it. (neuropathy).
To help prevent button bounce attach a 0.1uF capacitor from each of the press button inputs to gnd.
I made sketch of my setup. ( Fritzing ). Will that do?
I also tried adding 2 .1uF capacitors to one of the button switch sets.
Those two buttons now don't trigger the servo.
I only soldered one set of capacitors and buttons (to test).
I also used a separate power supply for the servos. They still react to turning my track power on and off on the rectifier or running the turntable motor. Including the one that has the capacitors attached.
You've got the idea. 'Across' in this context means two components wired in parallel - the resistor and capacitor. These two are in series with the switch.
any resistor should be between the pin and either ground or Vcc.
a capacitor shouldn't be needed. a simple delay can "debounce" the switch
the conventional approach is to connect the button between the pin and ground, configure the pin as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and for the button to pull the pin LOW.
servos are notorious for "jitter". its not going to be solved with capacitor on the switches
Hello,
I have added the capacitors in parallel to each of the button switches. The Servos are powered by a separate source with the common GND to the Arduino. This has calmed things down considerably. I am able to run trains and the turntable without the servos changing position. I did notice that if I activate another turnout near by that is not connected to the servo turnouts but still uses the old electromagnet activators, that the nearest servo to those does change position. The only thing they have in common is the main house wall socket that powers both. Not an Arduino problem... but..
#gcjr mentioned a single line of code addressing the need? What would that single line be and where in the code would it go?
use the internal pullup resistor and connect the switch between the pin and ground
servo jitter is notorious. it could be noise on the power supply. RC plane servos are powered by a battery. i'll guess another source may affect the pulses going to the servo.
certainly a much more proper way to power the servos, both to the servo as well as to the Arduino
i don't understand how putting caps on resistors in series with a button switch would affect the servos.