I'm working on a simple sketch for a two axis motor readout. It takes the voltage from the controller, converts it to a degree value, then displays the voltage and degree values on the LCD. Everything works fine except if there is no input voltage, that is, A0 and A1 have no connections, I still see random values showing up on the LCD. I've tried every if (condition) {then} combination I can think of in various locations to no avail. Any suggestions?
Working_digital_voltmeter_with_arduino_Uno__copy_20231006135729.ino (1.3 KB)
Please don't make us download your code. I, for one, won't do it.
Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in a code block.
Use an if structure to only print to the LCD if the voltage is above some minimum level.
If you are reading an unconnected (open or floating) input, the reading will be random. Use a high value (1M) resistor to pull down the input so that it is not floating. The high value resistor should not effect the normal operation of the analog input if the output impedance of the voltage source is low (<10K).
There is no such thing as 'no input voltage', everything has a voltage because all normal matter is made of charged particles. If the input is not connected then the voltage on it is not defined by the external circuit, it is defined by whatever random electrical interference the input happens to pick up. If you want the input to have a specific voltage when you have no external connections then you have to add circuitry to define what the voltage is.
Search for 'floating input'.
To avoid this problem, use a high value resistor (maybe around 10 M Ohms), connected between the analog pin and GND.
I believe that this value should not interfere with the control and will avoid leaving the analog pin floating.
See in the simulator:
" Voltimetro - Wokwi ESP32, STM32, Arduino Simulator
Sorry for offending. This was my first post. If I could, I'd delete the post.
No offence, please do not delete your post.
Just, please, post the code properly as requested in the forum guidelines.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.