Switching from Arduino uno 2x16 screen to 4x20 lcd screen

Hi friends
I want to switch the code I have from a 2x16 screen to a 4x20 LCD screen, but I don't understand the codes too much. Is there anyone who can help?
I hope I could explain. The code below is valid for 2x16 screen. I want to switch to 4x20 lcd screen as a new screen.

Codes below

#include <LiquidCrystal.h>
#define input_1 A0
#define input_2 A1
#define input_3 A2
#define pot A3
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Pout = 7;
int AnalogValue = 0;
int potValue = 0;
int PeakVoltage = 0;
int value = 0;
int power = 0;
float AverageVoltage = 0;
float input_A0 = 0;
float input_A1 = 0;
float output = 0;
float Resolution = 0.00488;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000;
float R2 = 10000;
unsigned long sample = 0;
int threshold = 0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
pinMode(input_3, INPUT);
pinMode(Pout, OUTPUT);
pinMode(pot, INPUT);
digitalWrite(Pout, HIGH);
}
void loop()
{
PeakVoltage = 0;
value = analogRead(input_3);
vout = (value * 5.0) / 1024;
vin = vout / (R2/(R1+R2));
if (vin < 0.10)
{
vin = 0.0;
}
for(sample = 0; sample < 5000; sample ++)
{
AnalogValue = analogRead(input_1);
if(PeakVoltage < AnalogValue)
{
PeakVoltage = AnalogValue;
}
else
{
delayMicroseconds(10);
}
}
input_A0 = PeakVoltage * Resolution;
PeakVoltage = 0;
for(sample = 0; sample < 5000; sample ++)
{
AnalogValue = analogRead(input_2);
if(PeakVoltage < AnalogValue)
{
PeakVoltage = AnalogValue;
}
else
{
delayMicroseconds(10);
}
}
potValue = analogRead(pot);
threshold = map(potValue, 0, 1023, 0, 5000);
input_A1 = PeakVoltage * Resolution;
output = (input_A0 - input_A1) * 100;
output = output * 4;
power = output * vin;
while(output >= threshold || analogRead(input_1) >= 1010)
{
digitalWrite(Pout, LOW);
while(true)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Guc Kaynagini");
lcd.setCursor(0,1);
lcd.print("Kesin");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Yeniden Baslat");
lcd.setCursor(0,1);
lcd.print("Butonuna Basin.");
delay(1500);
}
}
while(output >= threshold || analogRead(input_2) >= 1010)
{
digitalWrite(Pout, LOW);
while(true)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gücü Kaynagini");
lcd.setCursor(0,1);
lcd.print("Kesin.");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Yeniden Baslat");
lcd.setCursor(0,1);
lcd.print("Butonuna Basin");
delay(1500);
}
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("V=");
lcd.print(vin);
lcd.setCursor(9,0);
lcd.print("LT=");
lcd.print(threshold);
lcd.setCursor(0,1);
lcd.print("I=");
lcd.print(output);
lcd.setCursor(9,1);
lcd.print("P=");
lcd.print(power);
Serial.print("Volatge Level at A0 = ");
Serial.println(analogRead(input_1));
Serial.print("Volatge Level at A1 = ");
Serial.println(analogRead(input_2));
Serial.print("Voltage Level at A2 = ");
Serial.println(analogRead(input_3));
Serial.println("------------------------------");
}

Hi @ayhancan65

welcome to the arduino-forum.
The first thing to do is to RE-edit your posting to post your code as a code-section.
Read this tutorial to learn how you do this

best regards Stefan

1 Like
lcd.begin(20,4);

...would be a good start

2 Likes

would be grateful if you could help by making changes to the Sample Code. I don't understand much code. Thank you.

user @SemperIdem
has made the change. Look through the sample code where in the code there is a line

lcd.begin(

additionally I can say. Small effort and ignoring rules result in short postings like

The rules are well described here
How to get the best out of this forum

You should learn understanding and writing code. Not only asking in forums
best regards Stefan

Do not expect much help with out posing your code properly. You might show what you have done to the code and what results you are expecting. Semperldem gave you the correct answer: "lcd.begin(20,4);",(columns, rows) that will setup the display but you need to change your code to reflect the formatting of the screen you want. Since you have a wired display posting a schematic would help as I do not know if they are wired the same, I always use the I2C modules.

Thank you

#include <LiquidCrystal.h>
#define input_1 A0
#define input_2 A1
#define input_3 A2
#define pot A3
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int Pout = 7;
int AnalogValue = 0;
int potValue = 0;
int PeakVoltage = 0;
int value = 0;
int power = 0;
float AverageVoltage = 0;
float input_A0 = 0;
float input_A1 = 0;
float output = 0;
float Resolution = 0.00488;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000;
float R2 = 10000;
unsigned long sample = 0;
int threshold = 0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
pinMode(input_3, INPUT);
pinMode(Pout, OUTPUT);
pinMode(pot, INPUT);
digitalWrite(Pout, HIGH);
}
void loop()
{
PeakVoltage = 0;
value = analogRead(input_3);
vout = (value * 5.0) / 1024;
vin = vout / (R2/(R1+R2));
if (vin < 0.10)
{
vin = 0.0;
}
for(sample = 0; sample < 5000; sample ++)
{
AnalogValue = analogRead(input_1);
if(PeakVoltage < AnalogValue)
{
PeakVoltage = AnalogValue;
}
else
{
delayMicroseconds(10);
}
}
input_A0 = PeakVoltage * Resolution;
PeakVoltage = 0;
for(sample = 0; sample < 5000; sample ++)
{
AnalogValue = analogRead(input_2);
if(PeakVoltage < AnalogValue)
{
PeakVoltage = AnalogValue;
}
else
{
delayMicroseconds(10);
}
}
potValue = analogRead(pot);
threshold = map(potValue, 0, 1023, 0, 5000);
input_A1 = PeakVoltage * Resolution;
output = (input_A0 - input_A1) * 100;
output = output * 4;
power = output * vin;
while(output >= threshold || analogRead(input_1) >= 1010)
{
digitalWrite(Pout, LOW);
while(true)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Guc Kaynagini");
lcd.setCursor(0,1);
lcd.print("Kesin");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Yeniden Baslat");
lcd.setCursor(0,1);
lcd.print("Butonuna Basin.");
delay(1500);
}
}
while(output >= threshold || analogRead(input_2) >= 1010)
{
digitalWrite(Pout, LOW);
while(true)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gücü Kaynagini");
lcd.setCursor(0,1);
lcd.print("Kesin.");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Yeniden Baslat");
lcd.setCursor(0,1);
lcd.print("Butonuna Basin");
delay(1500);
}
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("V=");
lcd.print(vin);
lcd.setCursor(9,0);
lcd.print("LT=");
lcd.print(threshold);
lcd.setCursor(0,1);
lcd.print("I=");
lcd.print(output);
lcd.setCursor(9,1);
lcd.print("P=");
lcd.print(power);
Serial.print("Volatge Level at A0 = ");
Serial.println(analogRead(input_1));
Serial.print("Volatge Level at A1 = ");
Serial.println(analogRead(input_2));
Serial.print("Voltage Level at A2 = ");
Serial.println(analogRead(input_3));
Serial.println("------------------------------");
}

Circuit diagram at bottom
https://drive.google.com/file/d/15pZrIHIMQAQOdF5-ikHFW6wbzZu70aBQ/view

Why?

Ok well done posting as a code-section. Still some things to learn

RE-edit your first posting
delete the code in your first posting
then do automatic formatting of your code in the arduino-IDE
by pressing ctrl-T
after formatting
copy code for forum
then insert the code new by pressing ctrl-V

After Re-editing your first posting
delete the posting # 7
best regards Stefan

Thanks for posting the code. When writing code you need to comment it, for the very same reason you are asking for help. We may not remember or know what we did a while back. You know what you intended we do not, we can only guess. Posting an annotated schematic as you have wired it would help.

Thanks for the schematic, from what I can see all you need to do is make some code changes to the lcd.print() statements. You will also have 4 additional characters per row. There is a lot of material on line about using that style of display. The mane thing you will need to do is determine how you want it to look and change the lcd.print() statements to the row and column you want.

Since it is narrower than the 2x16 screen and the volt Ampere text is side by side, I want it to be wide and volt ampere watt under the other, if 4x20 LCD, thank you

Tüm yardımlarınız için teşekkürler, Sorun Çözüldü Yardım eden arkadaşınıza teşekkürler.

Großartig, markieren Sie es als gelöst!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.