Use 4 inputs and single output

 To implement a program where the output is low if any one of the four inputs is low, you can use the following code in the loop() function:


const int inputPin1 = 2;  // Input pin 1

const int inputPin2 = 3;  // Input pin 2

const int inputPin3 = 4;  // Input pin 3

const int inputPin4 = 5;  // Input pin 4

const int outputPin = 6;  // Output pin


void setup() {

  pinMode(inputPin1, INPUT);

  pinMode(inputPin2, INPUT);

  pinMode(inputPin3, INPUT);

  pinMode(inputPin4, INPUT);

  pinMode(outputPin, OUTPUT);

}


void loop() {

  if (digitalRead(inputPin1) == LOW || digitalRead(inputPin2) == LOW ||

      digitalRead(inputPin3) == LOW || digitalRead(inputPin4) == LOW) {

    digitalWrite(outputPin, LOW);  // Set output pin LOW

  } else {

    digitalWrite(outputPin, HIGH);  // Set output pin HIGH

  }

}

In this code, four input pins (inputPin1, inputPin2, inputPin3, inputPin4) and one output pin (outputPin) are defined. In the setup() function, the input pins are set as inputs, and the output pin is set as an output.


In the loop() function, the code checks the state of each input pin using digitalRead(). If any one of the input pins reads LOW, the output pin is set to LOW using digitalWrite(). Otherwise, if all input pins are HIGH, the output pin is set to HIGH.


You can connect your input devices (e.g., switches or sensors) to the defined input pins and connect an output device (e.g., an LED or relay) to the output pin. The output device will be driven LOW if any one of the input pins is LOW.







Comments

Popular Posts