# Logical or-gate

**URL:** <https://forum.arduino.cc/t/logical-or-gate/1331847>\
**Category:** Programming\
**Created:** [December 13, 2024, 12:11pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847 "2024-12-13T12:11:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![hjjuul](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hjjuul/32/1098743_2.png) [@hjjuul](https://forum.arduino.cc/u/hjjuul)\
**Post date:** [December 13, 2024, 12:11pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/1 "2024-12-13T12:11:49Z")

</div>

For my Arduino One I have implemented a pulsating output with the use of pwm.  
I want to combine that output with another output into a final output so that the final output is the result of a logical or-gate.- Is it possible to do that software wise or do I need some external components?

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [December 13, 2024, 12:30pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/2 "2024-12-13T12:30:23Z")

</div>

You can implement a logic OR in code. Something like below pseude code

```cpp
if(someCondition == true)
{
  digitalWrite(pinPWM, HIGH);
  // or
  analogWrite(pinPWM, 255);
}
else
{
  analogWrite(pinPWM, someValue);
}

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [December 13, 2024, 2:26pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/3 "2024-12-13T14:26:09Z")

</div>

Here is the result of ?? || ??:

```arduino
void setup() {
  Serial.begin(115200);
}
void loop() {
  Serial.print(1);
}

```

> **sketch.ino**
>
> ```arduino
> int i, j;
> 
> void setup() {
> Serial.begin(115200);
> }
> 
> void loop() {
> int i = random(256);
> int j = random(256);
> Serial.print(i, BIN);
> Serial.print(" ");
> Serial.print(j, BIN);
> Serial.print(" i || j = ");
> Serial.print(i || j, BIN);
> Serial.println();
> delay(250);
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [December 13, 2024, 3:01pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/4 "2024-12-13T15:01:30Z")

</div>

> [@hjjuul](#):
>
> Is it possible to do that software wise

I would say an or gate would be preferable. A serviceable gate can be made with two diodes and a resistor, maybe that's all depending on what the output of the needs to drive.

Software? Maybe. A straightforward approach woukd be to connect the PWM output to an input and use the value you read at that pin together with whatever your other output value is.

But you'll have to do that fairly often, as the PWM signal is cranking away.

```arduino
  bool pwmIsHigh = digitalRead(connectedToPWMOutputPin);

// get whatever the other output is into otherOutput

  if (otherOutput || pwmIsHigh)
    digitalWrite(orOutputPin, HIGH);
  else
    digitalWrite(orOutputPin, LOW);

```

If you use one of the low frequency PWM pins, you'll still have to execute that logic frequently and regularly.

Try it, I did not.

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [December 13, 2024, 3:03pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/5 "2024-12-13T15:03:33Z")

</div>

But srsly we should be asking you why you want to do that, to what end.

It is very probable that you are solving the wrong problem ,or not thinking about it if this is what you come up with as a solution.

So… what are you up to over there?

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [December 13, 2024, 5:10pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/6 "2024-12-13T17:10:41Z")

</div>

I used the time waiting for she who will not be kept waiting to test the software idea.

Trust but verify: it is unsatisfactory even when the calculation is done as rapidly as possible with straight-ahead code.

a7

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 13, 2024, 5:52pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/7 "2024-12-13T17:52:03Z")

</div>

> [@alto777](#):
>
> for she who will not be kept waiting

- When you use this too many times, **she** will find out, your life could become complicated  
🤕

---

<div class="post-metadata">

**Author:** ![hjjuul](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hjjuul/32/1098743_2.png) [@hjjuul](https://forum.arduino.cc/u/hjjuul)\
**Post date:** [December 14, 2024, 9:37am UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/8 "2024-12-14T09:37:34Z")

</div>

In fact I need a pulsating signal (square) for an amount of time and after that amount of time I need a constant HIGH signal.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [December 14, 2024, 9:48am UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/9 "2024-12-14T09:48:27Z")

</div>

> [@hjjuul](#):
>
> In fact I need a pulsating signal (square) for an amount of time and after that amount of time I need a constant HIGH signal

Then just use tone() and notone() and set the digital pin HIGH after noTone().

[https://docs.arduino.cc/language-reference/en/functions/advanced-io/tone/](https://docs.arduino.cc/language-reference/en/functions/advanced-io/tone/)

---

<div class="post-metadata">

**Author:** ![jimLee](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jimlee/32/214865_2.png) [@jimLee](https://forum.arduino.cc/u/jimLee)\
**Post date:** [December 14, 2024, 9:31pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/10 "2024-12-14T21:31:59Z")

</div>

Eew, clever! I love it!

-jim lee

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [December 14, 2024, 10:25pm UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/11 "2024-12-14T22:25:05Z")

</div>

> [@hjjuul](#):
>
> In fact I need a pulsating signal (square) for an amount of time and after that amount of time I need a constant HIGH signal.

what is the exact pattern timewise?

---

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [December 15, 2024, 1:18am UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/12 "2024-12-15T01:18:51Z")

</div>

Wire the outputs in parallel and you have one output that is ON when either of the two wired outputs is ON.

You can wire switches in series to make an AND gate and switches in parallel to make an OR gate and switches in a crossed way to make an XOR gate. When the power switches itself, the parallel OR gate still works but the final output will vary as to V and A.

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [December 15, 2024, 2:38am UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/13 "2024-12-15T02:38:31Z")

</div>

> [@jim-p](#):
>
> Then just use tone() and notone() and set the digital pin HIGH after noTone().

Do we know that the required duty cycle is 50%.  
**EDIT**  
Oops. He said said square wave.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 13, 2025, 2:38am UTC](https://forum.arduino.cc/t/logical-or-gate/1331847/14 "2025-06-13T02:38:43Z")

</div>

Closed on June 13, 2025, 2:38am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
