0% found this document useful (0 votes)
74 views5 pages

ES Experiment No. 05 B-10

This document describes an experiment to display the greatest common divisor (GCD) of two numbers on an LCD screen using an Arduino Uno board. The experiment uses Tinkercad software to write code calculating the GCD using the Euclidean algorithm and displays the result on the LCD. Components used include an Arduino, LCD screen, resistors, and breadboard. The code prompts the user to input two numbers, calculates their GCD, and displays the result on the LCD for one second.

Uploaded by

Shubham Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views5 pages

ES Experiment No. 05 B-10

This document describes an experiment to display the greatest common divisor (GCD) of two numbers on an LCD screen using an Arduino Uno board. The experiment uses Tinkercad software to write code calculating the GCD using the Euclidean algorithm and displays the result on the LCD. Components used include an Arduino, LCD screen, resistors, and breadboard. The code prompts the user to input two numbers, calculates their GCD, and displays the result on the LCD for one second.

Uploaded by

Shubham Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name –Shubham Patil

Year / Div - BE – B Roll


no. – 10

Experiment No. 05

Aim –
To display GCD code on LCD.

Software used –
Tinkercad.

Components used –
Arduino Uno, Resistors (220 ohm), Breadboard small, LCD 16x2, Connecting wires.

Procedure –
 Open the Tinkercad software.
 Create new project.
 Select all the components.
 Connect the components appropriately.
1. LCD RS pin to digital pin 7.
2. LCD Enable pin to digital pin 6.
3. LCD D4 pin to digital pin 5.
4. LCD D5 pin to digital pin 4.
5. LCD D6 pin to digital pin 3.
6. LCD D7 pin to digital pin 2.
7. LCD VCC pin to +5V .
8. LCD GND pin to POT.
 Write the code in the text box.
 Click on start simulation.
 Once the simulation is started, the monitor asks for number 1 and number 2. After
that the numbers will get compared and we will get the GCD of two numbers
displayed on the LCD.

Code –

#include<LiquidCrystal.h
> #include<stdio.h>
#include<stdlib.h>
int number_1;
int number_2;
int dividend;
int euclid_gcd(int number_1, int number_2);

LiquidCrystal lcd(7,6,5,4,3,2);
void setup()
{

Serial.begin(9600);
Serial.println("Enter first number: ");
while(Serial.available() == 0) {}
number_1 = Serial.parseInt();
Serial.println(number_1);

Serial.begin(9600);
Serial.println("Enter second number: ");
while(Serial.available() == 0) {}
number_2 = Serial.parseInt();
Serial.println(number_2);
dividend = euclid_gcd(number_1, number_2);
}

int euclid_gcd(int number_1, int number_2)


{
int dividend = number_1 >= number_2 ? number_1 : number_2;
int divisor = number_1 <= number_2 ? number_1 : number_2;
while(divisor != 0)
{
int remainder = dividend % divisor;
dividend = divisor;
divisor = remainder;
}
return dividend;
}

void loop()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(dividend)
; delay(1000);
}
Output –
Here, the two input numbers are, 36 and 15.

Here, the GCD of 36 and 15 is 3 which is displayed on the LCD.


Commands Used –
 #include<LiquidCrystal.h> - We use the LiquidCrystal library for controlling LCD. It is
a LCD library that allows us to interface with LCD.
 #include<stdio.h> - stdio.h is a header file which has the necessary information
to include the input/output related functions in our program.
 #include<stdlib.h> - The stdlib.h header defines four variable types, several macros,
and various functions for performing general functions.
 Void setup() – Use it to initialize variables, pin modes, start using libraries, etc.
 Serial.begin(9600) - This starts serial communication, so that the Arduino can send
out commands through the USB connection. The value 9600 is called the 'baud
rate' of the connection.
 Serial.println - Prints data to the serial port as human-readable ASCII text.
 Lcd.begin(16,2) - Initializes the interface to the LCD screen, and specifies the
dimensions (width and height) of the display.
 Void loop() - The code inside the loop function runs over and over as long as
the Maker Board is turned on.
 Delay(1000) - When we do delay(1000) our Arduino stops on that line for 1 second.

Conclusion –
Hence, we studied the GCD code by interfacing of LCD with Arduino.

***

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy