Detecting 5v using roborio dio

Hey everyone. I hope everyone had a good start with this season. I had a quick question whether on not anyone has tried this before but I was wondering if there was a way to program a limit switch in roboRio or but instead of using an actual limit switch I use a 5v Dc power source and every time the roborio detects the power source it sends a true value in VS code. Is there any way I can code it to detect 5v? Thank you for reading and have a great season!!

Sure - the DIO (accessed via DigitalInput class) will return high whenever the input’s above ~2V – it doesn’t care if that >2V is coming from a power supply or a limit switch closing.

2 Likes

Sick! I’ll try it tmr hope it works :crossed_fingers:

The roboRIO DIO have a pull-up resistor to 5v. So, when nothing is connected, they read 5v. Thus, you can’t tell the difference between having a 5v power supply connected and having nothing connected.

Instead, you need to have something that can drive the DIO to ground to be able to read it.

2 Likes

Ohhh, so what If i use a 5v relay to ground it? Or is there any easier way of doing it?

The pull-up resistor is weak. So you just need a stronger pull-down resistor. Something like 100 ohms to ground should work. Note this means the 100 ohm resistor will have 5V across it when the supply is connected, so it will be burning about 0.25 watts when power is applied, so make sure you use a resistor rated for at least 2x that (0.5 watts).

1 Like

In a picture:

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.