====== Analog Input Circuits ====== Most microcontrollers and CUBLOC modules provide analog input pins, but connecting a sensor directly to an ADC input is usually not a good idea. This is one of the most common mistakes made by beginners. Sensor wiring often runs through electrically noisy environments. Noise, static electricity, and voltage surges can all find their way back to the controller through these wires. In severe cases, the MCU itself may be damaged. At a minimum, some basic protection should be added between the sensor and the analog input. {{ :noise_book:adccircuit.png?nolink |}} In the example circuit above, the two diodes act as clamping diodes. Their job is to prevent the input voltage from going beyond the allowed range. The resistor and capacitor help reduce noise before it reaches the ADC input. This simple circuit works well when the sensor output is already in the 0–5V range. Unfortunately, real-world sensors come in many different output types. Some produce 0–10V signals, others use 4–20mA current loops, and some even provide bipolar outputs such as ±10V. Converting all of these signals into a voltage that an MCU can safely measure often requires additional circuitry. As more protection, filtering, and isolation are added, the analog input circuit can quickly become quite complicated. That's why many engineers choose a different approach: using an industrial analog input module. {{ :noise_book:modportadc.png?nolink |}} These modules handle the signal conditioning, filtering, protection, and conversion internally. Instead of designing a complex analog circuit, you simply read the measurement data through RS-232, RS-485, or another communication interface. One final note. Sometimes people complain that their ADC readings are unstable. In many cases, the ADC is not the real problem. The ADC is simply reporting the signal it receives. If noise is present on the input signal, the measured value will naturally fluctuate. The best solution is to remove the noise before it reaches the ADC. If some variation still remains, a common software technique is to take multiple readings and average the results. This simple method is often enough to produce stable and reliable measurements. [[index|←Noise Is My Friend]]