Activity 3. Analog to Digital Converter

This activity uses the Arduino Uno's built-in analog-to-digital converter. (50 minutes)

Activity 3a

In this part the aim is for the Arduino Uno to:

  • read the analog voltage of a potentiometer
  • send it to serial communication
  • a voltmeter has been added to the circuit to check the voltage of the potentiometer


Step 1. Draw the next circuit in Tinkercad.


 


Step 2Study the code and write it on the microcontroller:

/* ADC and serial
Circuit connections: Potensiometer_Terminal_1 => Gnd Potensiometer_Wiper => A0 Potensiometer_Terminal_2 => Vcc PIN_0 => Serial_RX PIN_1 => Serial_TX */ #define pot_pin A0     //give the name “pot_pin” to PIN_A0 //variable to save data from ADC int adc_value; //number range 0~1023 float voltage;  //variable to calculate the analog voltage //The setup() function initializes and sets the initial values //It will only run once after each power up or reset void setup() {   Serial.begin(9600); } //This function loops consecutively void loop() { //read analog voltage and convert to number adc_value = analogRead(pot_pin); //calculate the analog voltage from adc_number voltage = float(adc_value)/1023*5; //print to serial the adc_number and the analog voltage Serial.print("ADC number: "); Serial.println(adc_value); Serial.print("Voltage = "); Serial.print(voltage); Serial.println("V"); //wait for 5 seconds delay(5000); }

Step 3Run the simulation and check the correct operation of the circuit