Uno dead to me if I can't get clean analog input

Code is not required here but I will post a summary of my situation.
I did not realize that the analog input pins will/can/do float, yes I have read almost everything on how to get rid of this mainly "why would you read a pin with no input?"; problem is I am trying to read a pressure sensor, that sensor may take a second or two to initialize and if the Uno is reading an input and it is not the sensor, that's not good. I have bench tested with clean 12v in, clean signal in (ie: 2.2v) and I still get float voltage. I just need my Uno to READ 0 (zero) on the analogRead(A0) perhaps. When i do a serial print the input is always around 300, if I use the pullup resistor it goes to about 900 (both fluctuating). I need a ZERO input signal because if the sensor I am using fails, I need a ZERO to terminate the loop() to stop output and let things be as they were...
When I apply signal voltage it is always 'up' by the float voltage which is fluctuating. I can NOT use this information for my purposes.

Not much that we can do but sympathize without seeing a data sheet for the sensor and how you have it wired to the Arduino.

Sorry if you misunderstood, bench test clean 12v on input power. I usually use the USB so I can get the serial output. The input on the A0 is a clean 2.2v source (3.3 with voltage divider just so I can reference my sensor output which is usually around 2.5v). There is NO sensor installed, just floating voltage on the input pins which render them useless to me as Uno sees the float volt and will not 'stop' with no input signal of ie: if(analogRead(A0)<=0){GET OUT GET OUT;} It never sees 0 or less than 300 on the read

Why not put a 100K to 1M pull down resistor on the floating inputs to bring them to ground when unconnected.

I tried that with a 100k from A0 to GND and when I actually applied my sensor voltage it was about 1v off (3.5 not 2.5). I will try again later with a higher resistor. FYI: My usb cable is about 3 feet, even if I don't use it the power/A0 input wires are only like 6". Verified 12.2v from PS, verified 10v from a plug in transformer to the 'power connector', verified 2.5v for input on A0 :frowning:

groundFungus:
Why not put a 100K to 1M pull down resistor on the floating inputs to bring them to ground when unconnected.

See that is mainly the problem, how would UNO know it is NOT connected? Ie: I have it connected to a sensor, works fine, when I disconnect the sensor (A0) it reads a float voltage NOT zero which means I can never break a loop while it is reading as it always sees a voltage. :frowning:

What kind of sensor are you working with here? Link to datasheet?

Why do you have to design your code to work without an essential part of the system connected?

Also, you say that you see behavior as if the voltage were floating when there is a stable 2.2v on the pin - can you explain more? Once a stable voltage is present on the pin, you should get valid measurements, ie, 2.2v should read like 450 if you're using the +5v as a reference.

I am suspicious that this is an x-y problem, as you seem dead-set on doing something that doesn't make sense to the experienced people responding here - so you should explain to us what you're trying to do, and what led you to belive that you need it to read zero when no sensor is connected.

I'm making a boost controller for my car. The boost sensor is a 0-5v with nominal 12psi reading about 2.2v, it is also a very linear sensor, I want to 'fool' the ECU (just as if I used a simple voltage divider) to see less voltage to 'up' the PSI - key being if something happens ie: I loose a signal wire the UNO will never kill the loop and let me revert back to a straight sensor->ecu signal (I'm using a relay to control the signal as a failsafe).
I don't have a program to draw nice schematics so you may have to visualize ...

If I have the UNO off:
sensor ->NC of relay->ecu

UNO gets signal from sensor, closes NO contact on relay:
sensor ->UNO->ecu

if for some reason my UNO A0 wire breaks or something I want the relay to revert to NC state and it won't as UNO always sees the A0 input and would keep the coil powered always allowing the UNO signal through and if it is float voltage could be read by my ECU as -1 or 20psi so that's bad bad news.

ericmlaing:
I tried that with a 100k from A0 to GND and when I actually applied my sensor voltage it was about 1v off (3.5 not 2.5).

This implies a high impedance output on your sensor, which is unfortunate.

However there is a simple solution available: an opamp, unity gain. That will give you a low impedance output. As long as you have power for your OpAmp at the sensor, you can place it there, and it will not be bothered by your 100k pull-down.

schematic.png

Now when your sensor is connected you will see the signal; if the sensor is disconnected R1 pulls the pin to GND.

I don't have a program to draw nice schematics

You use a pencil along with something called paper. No software needed for drawing schematics.

I did not realize that the analog input pins will/can/do float,

Not only on the Arduino but ANY electronic A/D converter.

I would offer that you have the signal go to the 1:1 op-amp. that would eliminate any change in values from any controls you add.

second, I would feed the UNO all the time . if there is any, and I mean ANY change just because of the way the signal wires are run, there could be operational changes in the final device.

example, you run 1:1 to the existing controller,
then you swap the signal through the relay and the value is altered by 0.1v just because of some wring, contacts, etc. and you now have a separate and artificial condition.

lastly, I would look to add a second op-amp. feed it with your raw signal
and have the UNO feed it with what you want to change.
this op-amp would have the UNO just add to the value, or reduce, by the value that the UNO injects into the signal.
you loose the UNO, and the device should be able to be just a 1:1 repeater.

the other way to do this is to have the UNO in the loop all the time. 1:1 pass-through most of the time, but then when you want, you can alter the signal.

we still do not have a data sheet so this is pretty much just a concept.

Thanks for all the help, turns out well, I guess it's my bad. I did try A0->gnd the problem was (after metering the resistor) it was shorted. Don't know why but it was 0ohm, tried a different one (metered it first for 100k) and now A0 sees 0v when nothing connected 3v when 3v applied etc. remove my test voltage and back to 0, stupid resistor.
Also, when I kept saying I applied sensor voltage that is me bench testing it with a 3v supply and a voltage divider as the actual sensor is in my car and hard to use for bench testing :smiley:
Thanks again!