3.3 V Pin on Arduino Micro

Hi,

For my project I am using Arduino Micro and A4988 driver. I need to install several switches to get the Arduino to reverse direction, increase or decrease speed, high speed rewind, etc.

I am wondering if the 3.3 Volt pin of the Arduino is meant for that purpose. For example, can I put a switch in between the 3.3V pin and A0 and write code to watch A0 and when turned high (because the switch is on) do something like turn another pin high or low?

Typical way to do a switch on arduino is this:

Attach 1 terminal of switch to digital pin (anything)
Attach 2nd terminal of switch to ground.

pinMode(pin,INPUT);
digitalWrite(pin,HIGH);

you must add the pinMode(pin,INPUT), don’t forget that!

But what happens is this sequence enabled the “internal pullup resistor.” So the circuit looks like this:
PIN-(inside the chip)—>20,000 Ohm resistor (inside the chip) —> switch! —> gnd.

When digitalRead(pin)==LOW, the switch is closed.
when digitalRead(pin)==HIGH, the switch is open.

This is the typical way to do this.

If you use the 3.3V pin, you must add a resistor. So it must go 3.3V, SWITCH, RESISTOR, GROUND. Then, the resistor prevents you from shorting the 3.3V to ground.

The one benefit of doing your way, to an analog pin, is that you can use one pin for multiple switches. If you set up your resistors correctly there can be a voltage divider and a certain voltage corresponds to a different switch having been pressed. it’s trickier, though.

Edit: more detail. The issue with your method is that you just have 3.3V - SWITCH - Pin. When switch is open, voltage is “floating” and you cannot know for certain that is counts as LOW. Eventually it will be LOW when you run analogRead, but that is just because analogRead takes a miniscule current from the capacitance of the wire. You also are adding 3.3V direct to the pin, so if you do something like pinMode(A0, OUTPUT), then digitalWrite(pin,LOW) you will damage the pin by flooding with 3.3V and no current limiting resistor. This is a bit too much detail, though.

Also, try googling “arduino basic switch tutorial” or something like that, I’m sure there will be good tutorials. I personally really enjoyed the “arduino cookbook” when I first was starting out. it starts with the very basics and gets to some serious details, too, over time in the book.

Thank you.

So what you are saying is that turning a pin high externally is not the best way to do a switch and that it can be done internally.

I do get how code can be used to direct a pin to be high or low. I don’t see the role of the external switch here. I will read some more in order to better understand…

I did find the article you mentioned at: arduino.cc/en/tutorial/switch