# Arduino Projector Programming Questions

**URL:** <https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213>\
**Category:** General Guidance\
**Created:** [March 8, 2024, 7:14pm UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213 "2024-03-08T19:14:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kcrowl97](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kcrowl97](https://forum.arduino.cc/u/kcrowl97)\
**Post date:** [March 8, 2024, 7:14pm UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213/1 "2024-03-08T19:14:30Z")

</div>

Hi all i have a question regarding using an Arduino to power on an optoma projector after the arduino gets a ground to ground input and to send an off command if an off input has been detected i can paste the programming here to see if its an error in my programming or another problem i purchased a max 232 chip ill paste a link here so you guys know what i have now [https://www.amazon.com/dp/B07BJJ1T5G?psc=1&ref=ppx\_yo2ov\_dt\_b\_product\_details](https://www.amazon.com/dp/B07BJJ1T5G?psc=1&ref=ppx_yo2ov_dt_b_product_details)

i can see when i trigger the on contact it is sending something and i then used the serial monitor in arduino ide and its sending the on command but im not sure why the projector is still not powering on it could be i dont have the right hardware or my programming has an error but if you guys have any ideas as to why id love to try any method you guys have ill post my code below

```arduino
//Global Variables
const int pwron = 12; // On Relay declaration
const int pwroff = 13; // Off relay declaration
bool projectorOn = false;

void setup() 
{
  Serial.begin(9600); // Declaring and Setting the serial Baud rate
  pinMode(pwron, INPUT_PULLUP); // Setting the on relay as an input
  pinMode(pwroff, INPUT_PULLUP); // Setting the off relay as an input
}

void loop() {
  if(!projectorOn) {
  if(digitalRead(pwron) == LOW && digitalRead(pwroff) == HIGH) {
      ProjectorOnCommand(); // Turn Projector on
      projectorOn = true;
    }
  }

  if(projectorOn) {
  if(digitalRead(pwroff) == LOW && digitalRead(pwron) == HIGH) {
      ProjectorOffCommand(); // Turn Projector off
      projectorOn = false;
    }
  }
}

void ProjectorOnCommand() {
  Serial.println("~0000 1");
  delay(1000);
}

void ProjectorOffCommand() {
  Serial.println("~0000 0");
  delay(1000);
}``

```

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [March 8, 2024, 7:28pm UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213/2 "2024-03-08T19:28:27Z")

</div>

> [@kcrowl97](#):
>
> `if(projectorOn) {`

Should this be `else` ?

---

<div class="post-metadata">

**Author:** ![kcrowl97](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kcrowl97](https://forum.arduino.cc/u/kcrowl97)\
**Post date:** [March 8, 2024, 8:27pm UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213/3 "2024-03-08T20:27:37Z")

</div>

Agreed that’s a big one there to change thank you for pointing that out.

---

<div class="post-metadata">

**Author:** ![ruilviana](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ruilviana/32/722429_2.png) [@ruilviana](https://forum.arduino.cc/u/ruilviana)\
**Post date:** [March 10, 2024, 12:35am UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213/4 "2024-03-10T00:35:15Z")

</div>

Simplify

```arduino
//Global Variables
const int pwron = 12; // On Relay declaration
const int pwroff = 13; // Off relay declaration
bool projectorOn = false;
//----------------------------------------------------------------
void setup() {
  Serial.begin(9600); // Declaring and Setting the serial Baud rate
  pinMode(pwron, INPUT_PULLUP); // Setting the on relay as an input
  pinMode(pwroff, INPUT_PULLUP); // Setting the off relay as an input
}
//----------------------------------------------------------------
void loop() {
  if (digitalRead(pwron) == LOW && projectorOn == false) {
    ProjectorOnCommand(); // Turn Projector on
    projectorOn = true;
  }
  if (digitalRead(pwroff) == LOW && projectorOn == true) {
    ProjectorOffCommand(); // Turn Projector off
    projectorOn = false;
  }
}
//----------------------------------------------------------------
void ProjectorOnCommand() {
  Serial.println("~0000 1");
  delay(1000);
}
//----------------------------------------------------------------
void ProjectorOffCommand() {
  Serial.println("~0000 0");
  delay(1000);
}

```

---

<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:** [September 6, 2024, 12:35am UTC](https://forum.arduino.cc/t/arduino-projector-programming-questions/1233213/5 "2024-09-06T00:35:48Z")

</div>

Closed on September 6, 2024, 12:35am UTC

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