digitalRead() flux

I have an Uno with a simple circuit: 5VDC goes to a LED , through a 10K resistor and to ground. Lights up steady and perfect. No problems.

I then alter the wiring a bit: put the output of this simple circuit to pin 7 and make a simple program:

void loop()

Serial.println( digitalRead(7) );
delay(100);

What I see on the screen is a steady stream of "1" for about 10 seconds... then a steady stream of "0" for about 10 seconds, then back to the "1"s and so on.... blocks of "1" followed by blocks of "0". I was expecting nothing but "1" until I pulled a wire..

Can some one please help me understand why this is happening and what i can do to make it work the way I thought it would?

Thanks in advance.

PS: pinMode(7 , INPUT); is set correctly in my setup section

Try
INPUT_PULLUP

I replaced INPUT with INPUT_PULLUP Now I have "1"s even if the wire to pin 7 is removed (thus no signal but still registers a logical "1").

You will need a 10K from the pin 7 to GND.

.

Thank you. That should work. I will try it after work today.

Read this for how to treat inputs:- Inputs

SamBrownADK:
put the output of this simple circuit

I don't know what this means. Simple circuits like this are usually used as outputs from the microcontroller, not inputs to them. What exactly do you have wired to Pin 7? Posted a schematic.

LarryD:
You will need a 10K from the pin 7 to GND.

.

I do not see switches mentioned anywhere in Sam's posts.

I assumed
'Now I have "1"s even if the wire to pin 7 is removed'
that this was their switch.

.

Thank you every one... it was a simple fix: 10K to ground then between the 10k and the switch have a wired to pin 7... I assume this is a "pull down" resistor. Whats interesting and what threw me off is I read some place to use a 220Ohm resistor... once I replaced the 220 with the 10,000 it works perfectly. thank you everyone for the help!

SamBrownADK:
Thank you every one... it was a simple fix: 10K to ground then between the 10k and the switch have a wired to pin 7... I assume this is a "pull down" resistor. Whats interesting and what threw me off is I read some place to use a 220Ohm resistor... once I replaced the 220 with the 10,000 it works perfectly. thank you everyone for the help!

I still have no idea what you're talking about. In the first post you mentioned an LED circuit and didn't say a thing about a switch. Now where's the switch in this post coming from?

I am sorry I was not clear. My fault and I apologize. I had a simple LED and it worked. Then I wanted to send its output not to a LED.... but to Pin 7 via a 4N35 optocoupler. That did not work... book says use a 220 Ohm pull down resistor on the Pin 7 side and that did not work no matter what I monkeyed around with. Once I replaced the 220 with a 10K it works ... so now the out put of a switch (which I verified was true with the LED) can "talk" to pin 7 via an optocoupler... It was just a little project to be a building block for later stuff I plan to do. Again I am sorry i was not clear before.. my days are spent outside and not as much time as I would like with Arduino.

Grumpy_Mike: I am reading that article on inputs /etc... thank you! it is answering a lot of my questions!

There's a difference between "not being clear" and "forgetting to mention entire new components you've substituted into the circuit".

Optocouplers have a spec called "current transfer ratio". As you would expect from the name, it is the ratio of how much of the input current into the LED side is allowed through the output at the transistor side. Depending on exactly which part you got it can be as high as 600% or as low as 50%. Assuming you bought an actual 4N35 from a reputable supplier and not cheap ebay junk, the datasheet lists a minimum of 100% CTR at room temperature, minimum 40% over the full temperature range.

So there's a limit to the current that the output side can generate. Knowing the current going into the input LED, it's easy to calculate how much current is generated at the output. Then you can calculate how much voltage will change for any given resistance value (Ohm's law).

So with a 10k input resistance, 220 output resistance and 100% CTR, how much voltage change is that? Redo the calculation with 10k output resistance.