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?

Thanks in advance.

Farzad

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.

IN your code do this:
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

Farzad

Generally you can turn on the switch high externall, but you must also ensure the switch is forced DOWN with a resistor from pin to ground. This is so that when the switch is not pushing HIGH, the pin is guarenteed to be LOW, and not just “high or low”, which is how it is when it is otherwise disconnected.

The benefit of using the internal resistors, as I described, is you have 1 less component to connect. Because if you turn the switch HIGH via the 3.3V line, you must also have that resistor going to ground for when the switch is disonnected.

I hope the tutorial also helps :slight_smile:

Thanks