I'm working on a project with many servos. I have the servos stored in an array. What I am trying to do is display an error whenever a servo is disconnected from the arduino. I have the message that will appear on a 10 bar LED all figured out.
What I need is to figure out how to know when a servo is disconnnected. Disconnected means the pin fell out of the place on the arduino it is connected to. I think there might be some way to do this using the servo method read, but i'm not sure. I tried to digitalRead as well, with no avail.
Speedy reply would be much appreciated.
It might not be possible.
Do you have a schematic of the inside of servo motor you use ?
It all depends on the signal input of the servo. If that has an impedance of 10k, it is possible, but if that has an impedance of 1M, it is not possible.
So you detach the servo. Use pinMode to make the pin INPUT_PULLUP to enable the internal pull-up resistor. Measure the input pin, and hope that you can read a '0' when the servo is connected and a '1' when not.
When you use the an analog pin for the servo motor, you can read the analog value and have more change that you can detect something.
I think you have about 20% chance you can detect the servo.
You can do a number of things:
- Add a resistor to the servo or the plug of about 10k from the signal wire to ground. Or a resistor of 1k with a led.
- Measure the current of the power to the servo.
- Do some kind of trick that might fail, like measuring the capacitance of the signal wire by sending a pulse and reading the input.
- Add a sensor or microphone (glued onto the moving part) to your project, to detect if a servo is working.
Am I allowed to do that? Set pinMode of my server pin to INPUT_PULLUP after creating the servo attachment there? I'll give it a shot, but I was under the impression that the servo library did the pinMode stuff behind the scenes and I couldn't go changing that after the fact.
I'll give it a shot this afternoon either way.
No, detach it first, change pinMode, and attach the servo again.
Please don't post the same question in two places. Ask the moderator to merge your two threads.