Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Sensors to Digital I/O or analog?

Solved!
Go to solution

I am not familiar with this particular device, but yes, detecting whether a contact is closed or open would be a task that can be done with a digital input. 

 

You should connect the contact between the digital input and the GND terminal. If there is a separate digital GND terminal you should use this one. Digital inputs should never be left "floating", i.e. they should be either connected to  GND or to a voltage level which is detected as a HIGH state. In most cases, digital inputs have internal pull-up resistors (connected to the supply voltage line) which will provide such a voltage level when the contact connected to the digital input is open. If this is not the case (check the technical data and/or description of digital inputs) you should use an external resistor between the input and the supply voltage of the device (many devices have an external terminal connected to the supply voltage).

 

This is the hardware - detecting a closed contact by software is another issue. All mechanical contacts bounce, i.e. as they are operated, they will open and close intermittently. Depending on the type of contact (and speed of closing it) it may take milliseconds to a fraction of a second until they are fully closed. So you should provide a software time-out and detect a closed (or opened, the process described also happens in the other direction of operation) contact only if it is closed (or opened) for a certain time, say, 100 milli-seconds. If a contact is polled only once, the result may be wrong, since due to bouncing it may be open just when it is polled once but maybe fully closed just a few milli-seconds later. There are certain software routines for debouncing, as well as circuits for debouncing contacts by hardware.  

0 Kudos
Message 11 of 11
(1,008 Views)