[vc_row][vc_column width=”1/1″][vc_column_text]
In this post, we will use Arduino uno to translate the resistance value of the potentiometer into an analog value, read it, and displayed.
[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1395043599-1-62″][vc_column_text]
- 1 x Potentiometer
- 1 x Bread board
- Several jumper wires
[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1395043599-2-51″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Code Analysis” tab_id=”1395044457972-2-7″][vc_column_text]
In this experiment, we use the ADC 0 of Arduino. The function used to read the ADC value is analogRead(). The ATMEGA328P has a 10-bit ADC converter, so the range of the value of between 0-1023. We will output the value on the serial port. To achieve that, we first need to make sure that the baud rate of serial port of Arduino and the serial port of PC serial terminal should be same, this is configured in void setup(). We can then use Serial.print and/or Serial.println() to print the value to the serial port.
[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1395046991066-3-5″][vc_column_text]
int potpin = 0 ;/ / define analog interface 0 int ledpin = 13 ;/ / define the digital interface 13 int val = 0 ;/ / will define the variable val, and the initial value 0 void setup () { pinMode (ledpin, OUTPUT) ;/ / output interface defines the digital interface Serial.begin (9600) ;/ / set the baud rate to 9600 } void loop () { digitalWrite (ledpin, HIGH) ;/ / digital interface 13 of the LED lights delay (50) ;/ / delay of 0.05 seconds digitalWrite (ledpin, LOW) ;/ / off LED digital interface 13 delay (50) ;/ / delay of 0.05 seconds val = analogRead (potpin) ;/ / read the value of analog interface 0, and assign val Serial.println (val) ;/ / shows the value of val }
In the above code, we will use the LED that is linked to digital pin 13 to indicate the read event. Whenever we read a ADC value, the LED will blink once.
The following is the ADC readout value by turning the knob of the potentiometer.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.