Problems interfacing with arduino uno and nano

i want to use the code arduino uno to arduino nano to build votage indicator but it did not get the same result as arduino uno because the input & output voltage is different and the led did not light up according to condition. can someone help me to fix this problem? here is my code:

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, A0, A1, A2, A3);

int analogPin = A4;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 = 10000.0; // resistance of R2 (10K)
int value = 0;
int a[5] = {};

int greenLed = 10;
int blueLed = 11;
int yellowLed = 12;
int redLed = 13;
int sound = 8; 

void setup() 
{
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(yellowLed,OUTPUT);
  pinMode(redLed,OUTPUT);
  
  pinMode(A0,OUTPUT);
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
  pinMode(A3,OUTPUT);
  
  pinMode(A4,INPUT);
  
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setCursor(1, 0);
  lcd.print("VOLT INDICATOR");
  lcd.setCursor(6, 1);
  lcd.print("BLIS");
  delay(3000);
  lcd.clear(); 
}

void loop() 
{
 // LCD DISPLAY
  
 lcd.print("Voltage Level"); 
 // read the value at analog input
 value = analogRead(A4);
 vout = (value * 5) / 1024.0;
 vin = vout / (R2 / (R1 + R2));
 Serial.println (vin);
  
 if (vin < 0.09)
 {
  vin = 0.0;
 }
 
 lcd.setCursor(0, 1);
 lcd.print("Voltage V :");
 lcd.print(vin);
 delay(3000);
 //lcd.clear();
 
// LED & BUZZER
  
if(vin <= 11.3)
{
 digitalWrite(redLed, HIGH);
 //delay (1000);
 tone(sound, 1000, 250);              
 delay(1000);                              
 digitalWrite(redLed, LOW);
 //delay (1000);
 tone(sound, 2000, 250);             
 delay(1000);                                
}
  
  if(vin <= 11.60 && vin > 11.3) 
{
 digitalWrite(greenLed,LOW);
 digitalWrite(blueLed,LOW);
 digitalWrite(yellowLed,HIGH);
 digitalWrite(redLed,HIGH);
}
  
  if(vin <= 12.1 && vin > 11.6) 
{
  digitalWrite(greenLed,LOW);
  digitalWrite(blueLed,HIGH);
  digitalWrite(yellowLed,HIGH);
  digitalWrite(redLed,HIGH);
}

if(vin > 12.1) 
{
  digitalWrite(greenLed,HIGH);
  digitalWrite(blueLed,HIGH);
  digitalWrite(yellowLed,HIGH);
  digitalWrite(redLed,HIGH);
}
}

nano.PNG

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Both circuits would be good.

Thanks.. Tom... :slight_smile:

If you are powering the Nano from the USB connector, there is a reverse voltage diode in series that drops about 0.3 volts, so the analog reference voltage (AREF) is about 4.7 volts instead of 5V.
Change:

vout = (value * 5) / 1024.0;

To:

vout = (value * 4.7) / 1024.0;

And try it.

TomGeorge:
Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Both circuits would be good.

Thanks.. Tom... :slight_smile:

thanks for the suggestion :slight_smile: . the input voltage of pictures that i attach is vin = 11v

nano.PNG

JCA34F:
If you are powering the Nano from the USB connector, there is a reverse voltage diode in series that drops about 0.3 volts, so the analog reference voltage (AREF) is about 4.7 volts instead of 5V.
Change:

vout = (value * 5) / 1024.0;

To:

vout = (value * 4.7) / 1024.0;

And try it.

i already try it but it still does not work. i attach the picture of my project simulation when it use value 4.7 and 5.

nano 2.PNG

nano.PNG

Hi,
Are you just running simulations?

Have you built any hardware and tried your code?
Can I suggest you get down and dirty your hands and BUILD your project in REAL life, then see what you get.

If you have to use the simulation, put a virtual voltmeter on A4 and check the actual voltage going into the controller.

Tom...... :slight_smile: