Input Condition Problem

Hi Guys,

I’m very new with Arduino and currently I’m struggling with condition from my input

Problem:

  • If more than one switch = high. Arduino will trigger failed LED. eg: 16 input. the input should be only returned HIGH only 1 at a time… if more than one input trigger it will return failed by turning on RED led.

Current Code:
honestly, i don’t even know where to start. tried googling but can seem to find what 1 want. can anyone please guide any related topic regarding this problem.

Thank you very much !!!

Hi,
Do you have a photo of your setup or circuit you can post? I think I understand that you have multiple buttons (inputs) and one LED (output). When more than one button is on, turn on the LED, right?

1 Like

You have not given us any real information to work with. How many switches? What type of switches? How are the switches wired to your Arduino? What Arduino board? How many LEDs? How are they wired? What is the code supposed to do?

1 Like

Hi, @slambergamer
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.
OR

Then look down to “code problems” 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?
In particular, how you have your switches connected.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

1 Like

yes you are right…

i’m sorry this is my first time posting here… i have 18 input switch… just a simple switch its for my project implementation… the switch are actually pressure switch and this is to test if the solenoid is actually working… if i trigger relay 1 = high, relay 2 = off , relay 3 = off, relay = 4.
i should only have input from relay 1 and not relay 2, 3 and 4.

thank tom… and yes its my first time posting here… basically its one portion of my whole project.
the switch input is actually a pressure switch that detect airflow from a manifold thats controlled by 18 solenoid… i have create a simple arduino code that turn on only 1 led each time… and the output also only received only 1 input each time.

Please try to answer all of our questions.

1 Like

Hi,
Can you please post a link to data/specs of your pressure switch?
How have you got the pressure sensor wired to the controller?
If between the controller input pin and 5V, you need a 10K pulldown resistor from the input pin to gnd.
If between the controller input pin and gnd, you need a 10K pullup resistor from the input pin to 5V.

Tom… :grinning: :+1: :coffee: :australia:

1 Like

switch = pressure sensor
arduino board = arduino mega
1 led to turn on if the condition not met.

how to project works:
Here is the code i used to control the relay

   int relay1 = 1;
  int relay2 = 2;
  int relay3 = 3; 
  int relay4 = 4; 
  int relay5 = 5; 
  int relay6 = 6; 
  int relay7 = 7; 
  int relay8 = 8; 
  int relay9 = 9;  
  int relay10 = 10; 
  int relay11 = 11; 
  int relay12 = 12; 
  int relay13 = 13; 
  int relay14 = 14; 
  int relay15 = 15; 
  int relay16 = 16; 
  int relay17 = 17; 
  int relay18 = 18; 

void setup() {
  
  pinMode(relay1, OUTPUT); 
  pinMode(relay2, OUTPUT); 
  pinMode(relay3, OUTPUT); 
  pinMode(relay4, OUTPUT); 
  pinMode(relay5, OUTPUT); 
  pinMode(relay6, OUTPUT); 
  pinMode(relay7, OUTPUT); 
  pinMode(relay8, OUTPUT); 
  pinMode(relay9, OUTPUT); 
  pinMode(relay10, OUTPUT); 
  pinMode(relay11, OUTPUT); 
  pinMode(relay12, OUTPUT); 
  pinMode(relay13, OUTPUT); 
  pinMode(relay14, OUTPUT); 
  pinMode(relay15, OUTPUT); 
  pinMode(relay16, OUTPUT); 
  pinMode(relay17, OUTPUT); 
  pinMode(relay18, OUTPUT);

}

void loop() {
  
  digitalWrite(relay1, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay1, LOW);   // turn the relay on (HIGH is the voltage level)
  
  digitalWrite(relay2, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay2, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay3, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay3, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay4, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay4, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay5, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay5, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay6, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay6, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay7, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay7, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay8, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay8, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay10, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay10, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay11, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay11, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay12, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay12, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay13, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay13, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay14, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay14, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay15, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay15, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay16, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay16, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay17, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay17, LOW);   // turn the relay on (HIGH is the voltage level)

  digitalWrite(relay18, HIGH);   // turn the relay on (HIGH is the voltage level)
  delay(1000);
  digitalWrite(relay18, LOW);   // turn the relay on (HIGH is the voltage level)

  

  
  while(1){}
}
  


The output from the solenoid is detected by pressure switch which act like a pressore sensor.
if the pressure sensor turn on more than 1… it will turn on RED led which is act like a failed indicator.

There are no switches in the code. Where are the switches?

Pin 1 is the hardware serial (USB) TX pin. At some point you will probably need to use the serial port for debugging. Use a different pin for the switch.

Your code could be shorter if you used arrays for the relays.

The posted code will not compile. You have 4 relay9 variables and several others are duplicated.

You do not need while(1), loop() loops by itself.

1 Like

Hello
I´m confused :thinking:
Describe in simple words how the function should work and do it very simply.

1 Like

hi sorry. i updated the code… it was a mistake.

while(1) because i just want it to run only 1 time

im sorry… basically i just want if out of 16 switches… if more then 1 switch press at the same time it will turn on a single led…

this is just to explain the whole code… im running two arduino… this code is for the relay controller.
another is for output detection… the problem is for the output which if the switch turn on more than 1… it means there are something wrong with my machine.

switch = pressure switch which act as my sensor.

Thank you very much Tom… for the input… i will keep it in mind when im doing the wiring… right now im just trying to figure the code before i do the wiring.

btw i dont have any spec. i treat it as a simple switch.

If you want the code to only run once, put the code in setup().

1 Like

In short:
I understood that you need a code that reads 18 switches and that each closed switch triggers a relay.
If more than one switch is activated simultaneously, a red LED should light up and no relays should be connected.
And that you can’t write this code.
Am I right?

PS: Are you usig arduino? UNO?
Because of the number of ports I suggest using Mega arduino.

RV mineirin

1 Like

will do… thank you!

you are right… and yes im using arduino mega