Condition not fulfilled yet it execute

its nano noy uno :slight_smile:

how do i change it :thinking:

I already showed you.
Reply #16

1 Like

There's more, but they're mostly the same, just different pin numbers. (The curse of cut-and-paste)

analogRead is a relatively expensive operation.
You may wish to consider doing each only once, and storing the result in a variable.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int analogPin1= 19;
int analogPin2= 20;
int analogPin3= 21;
int analogPin4= 22;
int analogPin5= 23;
int analogPin6= 24;
int analogPin7= 25;
int analogPin8= 26;

int raw=0;
int Vin= 5;
float Vout= 0;

float R1= 1000;
float R2 = 0;

float essarr= 0;
float lavarr= 0;
float inter= 0;
float pv= 0;
float gv= 0;
float lavav= 0;
float adac1= 0;
float adac2= 0;

float buffer= 0;
void setup() {
lcd.clear();
lcd.begin(16, 2);
}

void loop() {
if (analogRead(analogPin1) != 0){
raw= analogRead(analogPin1);
buffer= raw * Vin;

Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
essarr= R1 * buffer;

//Serial.print("ess-arr: ");
//Serial.println(essarr);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("ess-arr: ");
lcd.print(essarr);
delay(1000);
lcd.clear();
lcd.print("clean");  
delay(1000);
}
else if (analogRead(analogPin2) !=0) {
raw= analogRead(analogPin2);
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
lavarr= R1 * buffer;

//Serial.print("lav-arr: ");
//Serial.println(lavarr);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("lav-arr: ");
lcd.print(lavarr);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);  
}
else if (analogRead(analogPin3) !=0.0){
raw= analogRead(analogPin3);  
buffer= raw* Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
inter= R1 * buffer;

//Serial.print("inter: ");
//Serial.println(inter);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("inter: ");
lcd.print(inter);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
else if (analogRead(analogPin4) !=0.0) {
raw= analogRead(analogPin4);
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
pv= R1 * buffer;

//Serial.print("PV: ");
//Serial.println(pv);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("pv: ");
lcd.print(pv);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
else if (analogRead(analogPin5) !=0.0) {
raw= analogRead(analogPin5);
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
gv= R1 * buffer;

//Serial.print("gv: ");
//Serial.println(gv);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("gv: ");
lcd.print(gv);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
else if (analogRead(analogPin6) !=0.0) {
raw= analogRead(analogPin6);
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
lavav= R1 * buffer;

//Serial.print("lav-av: ");
//Serial.println(lavav);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("lav-av: ");
lcd.print(lavav);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
else if (analogRead(analogPin7) !=0.0) {
raw= analogRead(analogPin7);
buffer= raw* Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
adac1= R1 * buffer;

//Serial.print("adac1: ");
//Serial.println(adac1);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("adac1: ");
lcd.print(adac1);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
else{
raw= analogRead(analogPin8);
buffer= raw * Vin;

Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
adac2= R1 * buffer;

//Serial.print("adac2: ");
//Serial.println(adac2);

lcd.setCursor(0, 0);
lcd.print("Vout: ");
lcd.print(Vout);

lcd.setCursor(0, 1);
lcd.print("adac2: ");
lcd.print(adac2);
delay(1000);
lcd.clear();
lcd.print("clean");
delay(1000);
}
}

did what you asked me, still same result :frowning:

I'd say you've got too much code, but I'm not clear what it's supposed to do.

You've certainly got too much code for a proof-of-concept.

are you saying (analogRead(analogPin1) != 0) is false ? how do you know?

the code is an omhmetre code if the value from A0=0 it reads other pins to A7 if its !=0 it excute an instruction to give me the resistance Value here is a picture to clarify.

i have try it in a simulator

Are you sure about those for a Nano?

seems you used the physical PIN numbers

Oh, those third party pin outs, with confusing extra info and sometimes plain wrong

well let's say you need to take the right info :slight_smile:

I don’t blame OP, if I was starting out with arduino and looked at that pin out, I also would have gone for physical pin numbers. BTW, when does one ever need physical pin number?

it's documentation... it can be useful to advanced users when some specific pins have specific use.
Agree it's not obvious depending on the pinout document you look at.

that being said, if you read the Arduino doc, or look at the board, you would use A0, A1, A2, ... and not those numbers