Hi, I am working on a Arduino project for my motorcycle. I want to be able to check if a switch located inside the engine is on or off. Will it work to wire it up as shown below, and use analogRead() with INPUT_PULLUP on the Arduino to determine if the switch is open or closed?
Since the switch is on the 12V part of the circuit, do i need a resistor / voltage divider between the Arduino and the switch, or will this just work because the Arduino is powered through the DC-DC step down?
Going by the circuit diagram, the switch is on the ground line. So the pull-up will make the pin read ‘high’ when the switch is off and ‘low’ when the switch is on.
The switch is nowhere near the 12V rail (according to the diagram) so you have no risk of frying the Arduino.
If the 12V is indeed going to be directed towards the input pin, you could always run it through another step down converter, 5v regulator, or switch through a transistor.
Thanks a lot, for your reply!!!! This sounds promising, just what I hoped for. Since my electronics knowledge is limited I thought it was best to check it
“ If the 12V is indeed going to be directed towards the input pin, you could always run it through another step down converter, 5v regulator, or switch through a transistor.”
Hi,
Common mistake.
You connect the 5V from your DC-DC converter to the 5V pin, not Vin of the Arduino.
Vin is the input of the onboard 5V regulator applying 5V there will guarantee less than 5V on the regulator output.
Really? That was news to me! I though it was for voltage input (pretty sure I have seen it used on multiple tutorials - but of course, you cannot trust whatever you see on the Internet....), and the 5V pin was for sharing the voltage to other units, breakout boards and stuff...
When should the VIN be used? If you power from a source above 5V? Ex if you have a 9V battery?
It could absolutely be me having misunderstood the tutorials, this might be just common knowledge that most take for granted. I have just never heard any explained this in any tutorial, and I have seen a lot of them lately since I am quite new to the game
If you are powering the Arduino via the 5v pin (unless you know it’s safe) always disconnect the external 5v power from the 5v pin when the Arduino is connected to the USB cable.