Activity 3. LCD 16x2 and ADC

This activity uses the Arduino Uno's built-in analog-to-digital converter. A liquid crystal display is used as the output device. (50 minutes)

Activity 3

This activity uses the Arduino Uno's built-in analog-to-digital converter. A liquid crystal display is used as the output device.

The Arduino Uno:

    • Reads the analog voltage of a potentiometer
    • Converts adc_value into a voltage
    • A voltmeter has been added to the circuit to check the voltage of the potentiometer



Step 1. Draw the circuit in Tinkercad.



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

/* Voltmeter

Circuit Connections: ** LCD
               Ground                  => Gnd
               Power                     => Vcc
               Contrast                  => Potentiometer
               RS                        => PIN_0
               RW                        => Gnd
               E                         => PIN_1
               DB0                       => Gnd
               DB1                       => Gnd
               DB2                       => Gnd
               DB3                       => Gnd
               DB4                       => PIN_2
               DB5                       => PIN_3
               DB6                       => PIN_4
               DB7                       => PIN_5
               LED Anode           => Vcc
               LED Cathode          => Resistor 220Ω => Gnd
** Potentiometer 1
               Terminal 1             => Gnd
               Wiper                     => LCD_Contrast
               Terminal 2              => Vcc ** Potentiometer 2
               Terminal 1             => Gnd
               Wiper                     => PIN_A0
               Terminal 2              => Vcc
*/

//include the library #include <LiquidCrystal.h>
#define RS 0              
//give the name "RS" to PIN_0
#define EN 1             
//give the name "EN" to PIN_1
#define DB4 2           
//give the name "DB4" to PIN_2
#define DB5 3           
//give the name "DB5" to PIN_3
#define DB6 4           
//give the name "DB6" to PIN_4
#define DB7 5      
     //give the name "DB7" to PIN_5
#define pot_pin A0        //give the name "pot_pin" to PIN_A0

//configure the library with Arduino Uno - LCD interface
LiquidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7);

//variableto save data from ADC int adc_value; //number range 0~1023 //variable to calculate the analog voltage float voltage; //The setup() function initializes and sets the initial values //It will only run once after each powerup or reset void setup() { //configure the LCD's columns and rows lcd.begin(16, 2); //print a message lcd.print("The voltage is"); }

//This function loops consecutively void loop() { //read value form ADC adc_value = analogRead(pot_pin); //calculate the analog voltage voltage=(float)adc_value*5/1024; //go to: first column, second row lcd.setCursor(0,1); //print a message lcd.print(voltage); lcd.print(" Volt"); //wait for 0.5s delay(500); }


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


Step 4. Suggested modifications and discussion:

    • What should be changed in order to read the values of potentiometer2 from PIN_Α5?

    • Replace the potentiometer2 with the temperature sensor TMP36 and turn the Arduino Uno into a thermometer. The temperature in degrees Celsius measured by the sensor is:

      T = (Vsensor - 0.5) * 100