i am facing the Problem on Digital Read Function.
i am Read the digitalpin number =2;
Whenever i am inserted the interlock this value is going to 0 to 1 perfectly . but whenever i am removing the interlock they are taking the 12-16 sec to the Print or going the value 1 to 0.
i am not inserted any delay then Why i am getting so much delay i don't know .
Please Tell me the solution.
Sounds like the pin is floating (not connected to anything). A floating pin's state is undefined. This can be fixed by adding a pullup or pulldown resistor, as appropriate, to force the pin to a known state when not connected otherwise.
Hi Seggi, I take it "the interlock" is some kind of physical and electrical connection on your device - I don't know, since the term 'interlock' is somewhat ambiguous here. Well if it a physical connection, you can probably cure the floating numbers by putting a 100K resistor between the pin and ground.
a interlock is a physical device they are used for the sorting purpose.
i am making a simple circuit in this circuit only the +5V is connected to 4.7k resistor .
and capacitor one terminal is connected to +5v and second is gnd.
and d2 pin is open whenever i am inserted the interlock they sorted and +5v is going to the digital pin and else 0v is going to digital pin
A schematic diagram would help you get the help you need. Depending on its value and how you have connected it, the capacitor could explain the problem. Here's how you can help.
Explain what you are seeking to do, rather than use imprecise / ambiguous term "interlock" ("a interlock is a physical device they are used for the sorting purpose".-> in English this does not explain anything at all)
Give us a diagram of the circuit so it is clear what you have wired.
Here is the diagram that seggi drew (modified to remove distortion and color confusion):
The thing you are calling an 'interlock' we call a 'jumper pin' in English technical jargon. Problem is, I still don't see what it does! The circuit 'above' the interlock is a RC filter, but it's on a constant DC source, so it doesn't have much effect, except to limit the current into D2. D2 will read HIGH if you do digitalRead(d2).
So here is a diagram of my suggestion above (reply #2):
The resistor I added is called a 'pull down' resistor, and is used to pull inputs down to ground when they are not connected to anything else. 100K is an approximation. In your real circuit, you may need more or less ohms.
When you have a pin that is an input... and it's connected to a switch that may be on or off (assuming off = not connecting the pin to something else) or it otherwise might not be electrically connected to the rest of the circuit, the pin is said to be floating. A "floating" pin will read random values, because it will pick up ambient electromagnetic fields (this is the basis of how antennas work).
It is unclear why you have the 4.7k resistor and capacitor there - they don't look like they're doing anything for you. I suspect you meant to put them somewhere else to get some sort of RC delay, or filter noise, or something? But that's the wrong place for them for that purpose.
Usually when working with a switch, you reverse the logic, so the switch connects the pin to ground - then you can set pinMode(pin,INPUT_PULLUP) and use the internal pullup in the arduino to pull it up to vcc when the button isn't pressed, saving you an external part.