Circle Area Calculator Using Arduino Uno R3

by NightmareHDH in Circuits > Arduino

448 Views, 1 Favorites, 0 Comments

Circle Area Calculator Using Arduino Uno R3

Screenshot 2024-02-16 4.26.45 PM.png

In this tutorial, we will create a Circle Area Calculator using Arduino Uno R3, a 16x2 LCD (I2C), a keypad, and jumper wires. The calculator will prompt the user to enter the radius of the circle via the keypad and then calculate and display the area of the circle on the LCD screen. We will be using Tinkercad, a virtual electronics platform, to simulate the circuit.

Supplies

Screenshot 2024-02-16 4.29.12 PM.png

- Arduino Uno R3

- 16x2 LCD (I2C)

- Keypad

- Jumper wires

.

.

Tinkercad

Open TinkerCad

download.png

Start by logging into your Tinkercad account or sign up for free if you don't have one. Once logged in, create a new circuit simulation project.

Add Components

Screenshot 2024-02-16 4.29.12 PM.png

In the Tinkercad editor, locate the components panel on the right-hand side. Drag and drop the following components onto the workspace:

- Arduino Uno R3
- 16x2 LCD (I2C)
- Keypad

Connection

Screenshot 2024-02-16 4.31.09 PM.png
Screenshot 2024-02-16 4.32.25 PM.png
Screenshot 2024-02-16 4.32.37 PM.png

Connect the components within Tinkercad according to the images

Code in Arduino

Screenshot 2024-02-16 4.35.35 PM.png

Next, we'll upload the provided Arduino code and understand its functionality. Here's a breakdown of the code:


cpp

#include <Keypad.h>
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd_1(0);

const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

String inputString = "";

void setup() {
Serial.begin(9600);
lcd_1.begin(16, 2);
lcd_1.print("Enter Radius");
}

void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
Serial.println(customKey);
lcd_1.setCursor(7, 1);
lcd_1.setBacklight(1);
if (customKey == 'D') {

float radius = inputString.toFloat();
float area = PI * radius * radius;
lcd_1.print(" ");
lcd_1.setCursor(0, 1);
lcd_1.print("Area: ");
lcd_1.print(area);
delay(10000);
lcd_1.clear();
lcd_1.print("Enter Radius");
inputString = "";
} else if (customKey == 'C') {

inputString = "";
lcd_1.clear();
lcd_1.print("Enter Radius");
} else {

if (customKey >= '0' && customKey <= '9') {
inputString += customKey;
lcd_1.print(customKey);
if (inputString.length() % 3 == 0 && inputString.length() < 12) {

lcd_1.print(',');

}
}
}
}
}



Explanation of the Code


- The code begins with including necessary libraries for the keypad and LCD.

- It sets up the keypad matrix and defines the row and column pins.

- Inside the setup function, it initializes the serial communication, initializes the LCD, and displays "Enter Radius" on the LCD.

- In the loop function, it constantly checks for keypad input.

- It performs the corresponding action if a key is pressed ('D' for calculation, 'C' for clearing input).

- When 'D' is pressed, it calculates the area of the circle using the entered radius and displays it on the LCD.

- The inputString variable stores the entered digits from the keypad.

Test the Circuit

Screen recording 2024-02-16 4.36.34 PM.gif

Start the simulation in Tinkercad. Use the virtual keypad to enter the radius of the circle. Press 'D' when finished entering the radius. The LCD should display the calculated area of the circle.

Experiment and Modify:

Screenshot 2024-02-16 4.42.04 PM.png

Feel free to experiment with the code and circuit:

- Modify the code to add more features or improve functionality.
- Explore different components and circuit configurations to enhance your understanding.

Conclusion:

Screen recording 2024-02-16 4.36.34 PM.gif

Congratulations! You've successfully created a Circle Area Calculator using Arduino Uno R3, a 16x2 LCD (I2C), and a keypad within the Tinkercad platform. This project provides an excellent opportunity to learn and experiment with Arduino programming and virtual electronics. Enjoy exploring further possibilities and expanding your knowledge!