Arduino has 10 bit ADC pins so whenever you apply voltage on these pins it will give you a value ranging from 0 to 1023 depending on the voltage provided. One can easily get this value using a simple function in Arduino analogRead(); but the real problem is to convert this analog value into the actual voltage present on the pin. Suppose you are using A0 pin of arduino and you are providing 3.3V over to this pin, now when you use this analoagRead() function then it will give you some value say 543, but you wanna know what's the actual voltage at this pin which is 3.3V so now converting this 543 to 3.3 is a bit tricky part. It's not difficult but involves a little calculations, which I am gonna cover today in detail. Before going any further, make sure you have already installed the Arduino Library For Proteus, if not then first do it because without this library you won't be able to use Arduino board in Proteus. So, let's get started with How to Display ADC value on LCD using Arduino.
I have divided this tutorial on How to Display ADC value on LCD using Arduino in few steps, follow these steps carefully and if you get into some trouble then ask in comments and I will try my best to resolve them, all the materials are provided at the end of step 1 for download but I suggest that you design your own so that you do mistakes and learn from them. Moreover, you should also have a look at these Arduino Projects for Beginners. Anyways, let get started:
Download Proteus Simulation and Arduino Hex File
#include <LiquidCrystal.h> #define NUM_SAMPLES 10 int sum = 0; unsigned char sample_count = 0; float voltage = 0.0; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const int PT = A0; const int CT = A1; float Cur; float Vol; float Power; void setup() { // set up the LCD's number of columns and rows: lcd.begin(20, 4); // Print a message to the LCD. lcd.setCursor(6,1); lcd.print("Welcome To"); lcd.setCursor(5,2); lcd.print("Energy Meter"); //delay(5000); lcd.clear(); Constants(); } void loop() { lcd.setCursor(0, 2); ShowVoltage(9, 0, PT); Vol = voltage; ShowVoltage(9, 1, CT); Cur = voltage; Power = Vol * Cur; lcd.setCursor(7,2); lcd.print(Power); } void Constants() { lcd.setCursor(0,0); lcd.print("Voltage: "); lcd.setCursor(0,1); lcd.print("Current: "); lcd.setCursor(0,2); lcd.print("Power: "); lcd.setCursor(14,0); lcd.print("V"); lcd.setCursor(14,1); lcd.print("A"); lcd.setCursor(12,2); lcd.print("W"); } void ShowVoltage (int x,int y, unsigned int value) { while (sample_count < NUM_SAMPLES) { sum += analogRead(value); sample_count++; delay(10); } voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0; lcd.setCursor(x, y); lcd.print(voltage); sample_count = 0; sum = 0; }
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w