detecting if a wire is in a pin.

is there a way that i can simply detect if a wire is in a pin or not. because im getting floating numbers when its not connected.

Yes, use MOEB = (Mark One EyeBall) 0 from software no.

What the hell is

floating numbers

floats are numbers with decimal points and there is no way you are gettiing those!

Mark

sorry horrible choice of words. the readings are fluctuating. is there a way i can just zero it out or detect if the pin is being used by a wire?

what im doing is dedicating a0-a7 for voltage reading to help diagnose my circuit.

i want it to be able to detect the wire and if no wire then it wont display in the monitor.

the readings are fluctuating. is there a way i can just zero it out or detect if the pin is being used by a wire?

No!

Mark

Grieva: sorry horrible choice of words. the readings are fluctuating. is there a way i can just zero it out or detect if the pin is being used by a wire?

what im doing is dedicating a0-a7 for voltage reading to help diagnose my circuit.

i want it to be able to detect the wire and if no wire then it wont display in the monitor.

Yes, English is annoying how words are overloaded with ambiguous context with which to select meaning.

I assumed you meant you were getting readings as if the pin was "floating" as opposed to you were getting "floating point" numbers...

The answer for many microprocessors is "YES!" Unfortunately for the ATmega328P it's "what do you expect to be connected to the pin?"

Can you show me a diagram of what might be connected to the pin?

If the impedance of the signals you are measuring is <=10K, then you could detect if a wire is connected to an analog input by:

  1. Connecting 1M pulldown resistor(s) to the analog input(s).
  2. Switching the internal pullup (30K) on and off.

To test if a wire is connected:

If the ADC reading is >100, then a wire is connected.

If the ADC reading is <100, then to test, enable INPUT_PULLUP and take a reading. If the reading doesn’t change by more than a few hundred counts, then a wire is connected. if it jumps to >900, then no wire is connected.

But what if the wire is carrying a low voltage? Then there is no way of telling in code if this is due to just the pull down or the wire carrying a low voltage.

Grumpy_Mike: But what if the wire is carrying a low voltage? Then there is no way of telling in code if this is due to just the pull down or the wire carrying a low voltage.

For many microprocessors both their clock frequency and their physical size is large, so it is possible to determine how many instructions it takes for their internal pullups to pull up their pin capacitance. If the pin is floating then the number of cycles is determined by the values specified in the microprocessor datasheet.

The ATmega328P on the Uno, however, is both too slow and too small to use this trick. If your expected circuit has a minimum amount of capacitance, however, then it is still possible to use the RC time constant (measured in clock cycles) to determine if its pin is floating or not.

In this response I determined it only took 22pF to use this trick with the Uno. A moderately loaded I2C bus would have 22pF.

If the impedance of the circuit being measured is <=10K and you’re measuring a low voltage, then you would test if this is due to a connected wire by enabling the internal 30K pullup. If a wire is connected, this will not have much influence on the reading. If there’s no wire connected, the reading should jump to >900.

Note that the 1M pulldown resistor would always remain in the circuit.

EDIT: Calculating for 30K/1M voltage divider, the upper measurement range would have to be limited to 4.85V, so ADC code range 992-1023 would need to be reserved for the wire detection test.

trying to do a simple charge/discharge and i wanted to use the analog pins to try and figure out whats wrong with it.

yea i dont understand what you are saying. dlloyd can you explain that by fritzing and code.

In your picture it looks like you aren't connecting to anything but 5V and GND.

Which pin do want to detect is floating?

The charge will be almost instant and the discharge will only be down to the forward volts drop of the LED. So another x-y promlem.

What do you actually want to do?

When you press the left button, you charge the capacitor. After that you press the right button to discharge?

The positive leg of the capacitor is at +5V after charge. The one leg (I can't see if it's anode or cathode) of the LED is connected to +5V as well. No voltage difference so no current flowing.

Maybe the LED needs to be connected to GND?

i want the left button the charge the cap and the second button to release the charge into the led. Like i dont get why im having so much damn trouble with this.

the pins i can read the voltage its just i wanted to make the code flexible and shorter rather than throwing it line by line in the code into the serial monitor.

led was in ground. its just my breadboard in real life has the rows flipped. but the led is plugged into ground.

I guess it was this statement that threw me off course...

the readings are fluctuating. is there a way i can just zero it out or detect if the pin is being used by a wire?

holmes4's reply is looking pretty good right now.

so whats wrong with the circuit??

Grieva: led was in ground. its just my breadboard in real life has the rows flipped. but the led is plugged into ground.

That's not an argument ;) You make it sound like GND is +5V and +5V is GND. Post a new picture in a new post (including the connection for measurement; currently nothing is connected to the analog pins). Most of us actually prefer a proper diagram; even a scan or photo of a handdrawn one is considered better than a fritzing).

Grieva: so whats wrong with the circuit??

It will not do what you want because there is no resistor in the charging path and it will not discharge fully.

STATUS UPDATE

Turns out..it was the damn breadboard that was giving out. I redid the entire schematic on a different breadboard and bam it worked the first try. i did it right i was able to press button 1 and hold it to charge it then second button to release the charge to run the led.

i even went as far as add more capacitors in parallel to extend the led light by a good 2.8 seconds. so now i got a mini capacitor bank.

so my next step is to put then in series and dump them and have my clamps observe the voltage spike.

How can i get it to discharge fully?