else loop ignored anywhere

Hi there.

I am new of IDE and C++ but having good notions on programming I started working at a controller on Arduino Uno.

I started up with my complete sketch, then I found this hurdle and reduced the sketch down to the hurdle itself with no success.

Problem is: Any if else cycle works, but this one doesn’t, even if left ALONE in the void loop!

I changed input pins and output pins, no way. Much more complicated ifte loop worked, not this one. Syntax is the same, no code error… just ignored!

Please can anyone suggest what cause IDE to ignore an else loop?

Please read the "How to use this forum" post and follow the directions. Post your code, using code tags.

gianpa70: Please can anyone suggest what cause IDE to ignore an else loop?

No, the IDE nor the compiler nor the board will "ignore" any statements. You messed up your code somehow. You may not notice it, but you must have. Or perhaps your wiring. But either way you've made some mistake.

You chose not to show us anything about the code you were talking about, so there's not a lot we can do to help you find the mistake.

But trust me, your line of code is not being "ignored".

Hardware is ok: I changed both input and output ports and then checked them again with other ifte cycles and worked.

Here is the latest tested code, from which I removed each and every line other than the "criminal one", and still it didn't work. You will notice that there is a lot more vars and I/O defined, as the code in which this loop is bugging is much larger.

Thanks for any help, for sure a new-comer mess up :o

int DDC = 6; //Durata in ore del ciclo singolo di deumidificazione int DFC = 2; //Durata in ore del ciclo di soffiaggio in deumidificazione riscaldata int CT = 0.250; //Durata in secondi di un loop programma long CDC = DDC * 3600 / CT; //Numero loops di fine conteggio a termine ciclo deumidificazione long CFC = DFC * 3600 / CT; //Numero loops del ciclo di soffiaggio in deumidificazione riscaldata int DryUp = 0; //Richiesta deumidificazione attiva long CountDU = 0; //Contatore loops in deumidificazione int FT0 = 400; //Soglia di attivazione comparata al segnale ingresso flussometro -> settare durante taratura su impianto con misura volumetrica e tester su V ingresso pin A0!!!

void setup(){ pinMode(1, INPUT);//livello avvio pompa sommersa, NC pinMode(2, INPUT);//livello arresto pompa sommersa, NA pinMode (3, INPUT);//livello shut down pompa circolazione, NC pinMode (4, INPUT); //stato igrostato, NA pinMode (5, INPUT);//stato termostato, NA pinMode (6, INPUT);//failure fan 1,0-5V pinMode(7, INPUT);//failure fan 2, 0-5V pinMode (A0, INPUT);//segnale flussimetro pre-convertito (impulsi->tensione) pinMode (8, OUTPUT);//rele avvio scaldiglia perimetrale pinMode(9, OUTPUT);//rele avvio alimentatore fan1 e fan2 pinMode(10, OUTPUT);//rele avvio fan1 pinMode(11, OUTPUT); //rele avvio fan2 pinMode (12, OUTPUT);//rele avvio pompa sommersa pinMode(13, OUTPUT);//rele avvio pompa circolazione pinMode(A1, OUTPUT);//LED allarme fan1 pinMode(A2, OUTPUT); //LED allarme fan2 pinMode(A3, OUTPUT);//LED allarme bassissimo livello serbatoio }

void loop() { int LSP = digitalRead(1); //assegnazione variabili agli input pins int LSPH = digitalRead(2); int LSD = digitalRead(3); int HSH = digitalRead(4); int TSL = digitalRead(5); int FF1 = digitalRead(6); int FF2 = digitalRead(7); int FT = analogRead(A0);

if(LSP == LOW && LSPH == LOW){digitalWrite(8,HIGH);} else if (LSPH == HIGH) { digitalWrite(8, LOW);}

Your code, as incorrectly posted, won't even compile.

So, any talk of it functioning properly, or not, it just blowing smoke.

Is that the whole code? Is that the end of loop? ( There's a brace missing is why I ask)

What is connected to those pins? You're going to need to show the wiring. I get that you think it is fine, but you also said it doesn't work which indicates otherwise. The comment (if I translated right) seems to indicate it is a level switch. If so, do you have a pulldown resistor for it or is it floating when it isn't made?

Please read the "How to use this forum" post and follow the directions. Post your code, using code tags.

yes, I misses the last bracket closing the loop from cut-paste. And yes, it is a portion of the full loop, the one that seems to be ignored when running: I removed any other part of code so to exclude the cause from being a problem of conflict among different instructions. The code is now run on test bed and yes, am using 10k pulldown to bring input pins voltage to ground. The code is supposed to control hydraulic system and heaters. The code I posted is just controlling the start/stop of the refilling pump between LSP (start) and LSPH (stop)

The code DOES get COMPILED and DOES run: it simply provides no output on pin 12, whatever the combination of LSP and LSPH. The same pins work perfectly on direct digitalWrite command, and feed-in perfectly on digitalRead as input to other loops

All in all, this one seems to be a wicked loop!

gianpa70: it simply provides no output on pin 12,

That makes sense. There's not a single line of code in there that writes anything to pin 12. You are writing to pin 8.

gianpa70: ...it simply provides no output on pin 12, whatever the combination of LSP and LSPH.

But the code you've posted is trying to write to pin 8?

Are you able to have it connected to a computer and print the values of LSP and LSPH to a serial monitor to double check they are reading what you think they are?

yes, correct: I switched to pin 8 in my hardware sanity check... and the LED on pin 8 does not lit either.

Good point the one of printing to my laptop the vars status, but have no clue what code to use to do that?

Good point the one of printing to my laptop the vars status, but have no clue what code to use to do that?

Is that a question? Or a statement?

Ever heard of Serial.print()?

ok, so: from serial monitor reading serial prints it turns clear that pin1 does not read the high DI. That's quite strange, I don't think it's burnt. I noticed that pins 1 and 2 have tx and rx designation, so my doubt is they could be unable to work as input pins while the usb cable is connected to the laptop. Second doubt I have (but this other sxenario should affect all the other signals as well, which is not the case) is that I am not doing the right thing using the 5 VDC from the board to generate the inputs under a 1k resistor, without bridging the 5 VDC output ground into the ground pin on the D I/O bank. Are they maybe 2 separate grounds??

You can't use pin1

pinMode(1, INPUT);//livello avvio pompa sommersa, NC

And use Serial communication with your PC

Pin 1 is Tx from the serial hardware

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. 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.

Please avoid using pins 0 and 1, as they are the programming pins and the monitor also uses them.

Thanks.. Tom.... :)

thanks Folks.

Apologies for shortcutting the tutorials: as you may have realized, I am not an addicted to Arduino, reason why am trying to programme it is because I need to manage some non-on/off logics in my house utilities.

Should I need furher assistance on the code,I'll follow instructions to export it as compilable code.

Bottom line so far: I can use 0 and 1 only if not connected to serial port, so I need to use another 2 pins to test the code and when it works reallocate to 1 and 2 before putting in operation.

Second, I can't leave a conditional open, otherwise the cose would not just go to next line and do nothing, but would do random assignment, correct?

Thanks Folks, the FULL CODE works now!!!

My lesson learnt from a general perspective and for the beginners like me:

  1. Start with HARDWARE: Need to really understand what each pin can/cannot do and in which possible combination. I was messing up my full sketch just because had put an input to a simple IFTE statement running on a TX/RX pin!

  2. Use this forum: it is fu...g powerful and has many passionate people able to support. And spend 10 mins reading TUTORIAL as this will save you time in effective communication

  3. Whatever variable or output you activate in a loop and don't want to find in the same status when the loop counter reaches the cap and loop starts over, make sure you write command lines to RESET those to their loop begin values: I had loop restarting and alarm output staying on with no alarm condition, just because I forgot to write a line to reset it at end of loop

  4. CAREFUL using the right variables. If you are reading sub-decimal values, and use the int type, whatever combination of formulas using those variables will result in ZERO. Use Float instead!

Thanks to all for supporting!