I'm using a servo to operate an indicator for a pressure gauge (simulated for fun, not exact). The operation I wish to achieve is as follows:
When toggle switch is flipped on, gauge (servo) rotates to 90 degrees
When toggle switch is flipped off, gauge rotates back to original 0 position.
(Much like an oil pressure gauge in your car)
I can get the first part thanks to interwebs, but it's the second half I'm not sure of. I'm fairly certain I need to configure a pin to the toggle switch instead of only using it as a power switch as shown in the image below.
Here's the sketch
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
myservo.write(90); // set servo to mid-point
}
void loop() {}
Why do you have a ground and a V+ wire to the switch, that could short out your power supply?
Run a wire from the right end of the switch to ground, another wire from the center pin of the switch to pin 2.
Which simulating software you have used to design this image? It's so elegant and it's not of Fritzing. Can you please let me know the software. Thanks in advance !!!
outsider:
Why do you have a ground and a V+ wire to the switch, that could short out your power supply?
Run a wire from the right end of the switch to ground, another wire from the center pin of the switch to pin 2.
#include <Servo.h>
Servo myservo;
void setup()
{
pinMode(2,INPUT_PULLUP);
myservo.write(0); // set servo to 0
myservo.attach(9);
}
jackthom41:
Which simulating software you have used to design this image? It's so elegant and it's not of Fritzing. Can you please let me know the software. Thanks in advance !!!
TinkerCAD from Autodesk. It's free and you can do quite a bit and very easy to use. I like fritzing, but I prefer the simplicity of TinkerCAD.
I was able to get multiple servos working by building on the sketch you provided Outsider, but the servos are very slow to rotate. Any ideas on how to speed that up? Power supply set to 5.4V 5A
Looks like they're all moving at the same time, pulling more current than your power supply can provide, try just one by itself, if it works right, you may have to move them in sequence with a 100 mS delay between each move.