Im using a Arduino Leonardo trying to run 2 servos using a switch, Using pin 9 and 10 as output and using pin 8 and 7 as input and running 2 servos from one 5v output and running the switches to the inputs, and all of the input pins are going low high like crazy!
What can I do to fix the input pins going low high?
#include <Servo.h>
int servo = 0;
Servo servo_10;
Servo servo_9;
void setup()
{
pinMode(8, INPUT);
servo_10.attach(10, 500, 2500);
pinMode(7, INPUT);
servo_9.attach(9, 500, 2500);
}
void loop()
{
if (digitalRead(8) == HIGH) {
servo_10.write(0);
} else {
servo_10.write(180);
}
if (digitalRead(7) == HIGH) {
servo_9.write(0);
} else {
servo_9.write(180);
}
}
COM4
low //all switches are off
high
low
high
low
high
low
high
low
high
low
high
low
high
low
high //turned on the switch
high
high
high
high
high
high
high
high
high
low //turned off the switch
high
low
high
low
high
low
high
low
high
For a start, you could investigate how switches are normally wired instead of making it up.
i have used a multimeter to check the way the switch works
A multimeter doesn't see the switches the way a processor does.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/InputPullupSerial
It also likely that you made a wiring error, compared with your diagram, so please post images of your hardware.
oh really? im new to this so.
That's what the example sketches and tutorials are for. People who are new to it.
Also see
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
Your switch inputs are floating. From the tutorial:
"If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit".
Green == Common 5v Purple and Blue == Input Pins
oh also about the floating I/O Pin can I use a common resistor and a common ground?
Am I missing something or is that not your complete code? It doesn't have any Serial stuff.
idk about serial stuff thats what i use for trying out things
also im using 3.3v for the input is that fine?
Oh ok
Good luck!
edit (I mean for post 13)
..oh that, no that is not good. What was the idea? Have you read the tutorials yet?
refer back to this post, I will be powering the leonardo with a 12v power adapter and my electronics will be powered using 5v form the output 5v from the leonardo
and yes I am a dumbass
oh I'm not a dumbass I got temporarily removed and will be checked from the moderators for some reason ok gotchu
It is not fine. 3.3V and 5V logic levels are different. But it is not your only problem.
because im running 2 UN-LOADED servos and I'm too broke to get a 5v supply, wait how much current does a servo use when its unloaded?
so what i learned so far is I need a pull-up resistor and connect it to ground, and use 5 volts for logic I/O input
also I have reached the limit for replying 
pog
so what else do I need to fix?
3.3v to the switches then to the input pins, (8 and 7)
oh I'm dumb I'm planning to use a 12 volt dc jack
reply to idahowalker, because I'm going to use the servos unloaded? is it fine to power it form the leonardo?
reply to aarg, no my input supply WILL BE 12 volts from a power adapter but all my electronics are WILL BE powered in 5v so I'm going to run them from the 5v pin in the leonardo
wot?
I was postponing comment on that, because it is also a mistake. You can still edit posts.