Atmega328p Microcontroller ADC
It is a simple project using Analog-to-Digital Converter (ADC) on Atmega328p (Arduino UNO), so for this example, it will be used a Sensing Force. The Sensing Force is optimized for use in human touch control of electronic devices such as automotive electronics, medical systems, and in industrial and robotics applications. This project has only two outputs and the outputs depend on the ADC input value.
The Atmega328p DataSheet that will be used to develop the code.
Component - Sensing Force
the component used in this project is the FSR 402 model that is a single-zone Force Sensing Resistor which is a Force Sensing that provides an inverse change in resistance in response to an increase/decrease in applied force.
Code
Initialization ADC function:
The ADMUX register is used to select reference voltage source, how the result should be stored, analog port channel to be used for conversion.
The ADCSRA register is responsible for enabling ADC, start ADC converting, prescaler selection and interrupt control.
Read ADC function
Setting the ADSC bit to logic 1 on ADCSRA register tells ADC to start the conversion.
Initialization of the Ports
The DDR (Data Direction Register ) registers are responsible for determining whether the pins of a particular PORT will behave as input or output. Each bit of the DDR register controls the state of its respective pin. So it’s setting the Port PC0 (A0) as ADC input and the digital ports PB4(D12) and PB5(D13) as outputs.
ADC result and its conditions
this example has two levels of sensitive touch, it can be set as the first level for a less sensitive touch, it will turn on just one LED, and as the second level for stronger sensitive touch, so the two outputs will turn on, therefore both LEDs will turn light on.
There are many others applications, for example, the volume of the car sound can increase slowly on the first sensitive touch level, and the volume of the car sound can increase faster on the second sensitive touch level.