Turn PC on With Wireless Charger

Background: I have zero experience in coding an Arduino and will borrow sections of code to get this project done. I have looked at past posts using an Arduino to turn the PC on, but have yet to see it in my version when adding more automatic functions.

I've been working on integrating an Arduino Uno with a wireless charger to turn a PC on. I've looked at past posts for sections of code I can use. My circuit is simulated on Tinkercad. I will connect my Arduino to the 5V standby power from the PSU which also powers the wireless charger when my PC is off. I am using an optocoupler. The Arduino will always be on when the PSU is on. Currently, I am using one of the led solder pads on the wireless charger to get an analog signal to trigger output. I have decided to use A1 as the pin for 3V3 to tell me PSU is on and will not need to turn pin13 HIGH.

My goals are here:

  1. If PC is off, turn on the PC using the wireless charger LED voltage as a signal to turn on the PC.
  2. If PC is on, do not send signal to turn on PC while the phone charges. Doing so will turn off PC

My current code:

int ledPin = 13;            // select the pin for the LED
const int analogPin = A0;    //pin for analog reading
const int analogPin = A1;   //pin for sensing PSU is on using 3V3 rail
int value = 0;


void setup() {
  delay (1000);
  Serial.begin(9600);   //Start Serial
  pinMode(13, OUTPUT);  // declare the ledPin as an OUTPUT:
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
	}

void loop() {
  value = analogRead(A1);         //Output to monitor for reading
  Serial.print("value =");
  Serial.println(value);
  delay(500);
 
    
//The two main goals
//-- 1. Turn PC on with Qi charger if PC is off.
//-- 2. If PC is on, do not send signal to turn PC on.
  
//I want to turn the LED (pin 13) on for only one second like a switch. 
//No repeats because I am using voltage from LED on wireless charger to trigger 
//the function once when phone is charging to turn on pc with optocoupler.
//Second, if PC is already on pin 13 must not be HIGH when phone is charging otherwise it shutdown the computer.
  
  	
    static boolean previousState = LOW;
    boolean State = digitalRead(A0);
    
    if (State == HIGH && previousState == LOW)  { 
    digitalWrite(13, HIGH);
    delay (1000);
    digitalWrite(13, LOW);
    }
    previousState = State;
  	
}
    

This is what it looks like on Tinkercad right now. I'm using simulated switches to verify individual parts of the code. I will not be using switches in the final build.

The current code accomplishes goal #1. I'm stuck achieving goal #2. I have looked at posts using state functions and some using true and false flags. The code you see is of my limited understanding and borrowing what I can find to make it work.

something like this maybe:
(Compiles, NOT tested!)

int ledPin = 13;            // select the pin for the LED
const int WirelessChargerPin = A0;    //pin for analog reading
const int PSU_Pin = A1;   //pin for sensing PSU is on using 3V3 rail
int value = 0;


void setup() {
  delay (1000);
  Serial.begin(9600);   //Start Serial
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT:
  digitalWrite(ledPin, LOW);
  pinMode(WirelessChargerPin, INPUT);
  pinMode(PSU_Pin, INPUT);
}

void loop() {
  value = analogRead(PSU_Pin);         //Output to monitor for reading
  Serial.print("value =");
  Serial.println(value);

  //The two main goals
  //-- 1. Turn PC on with Qi charger if PC is off.
  //-- 2. If PC is on, do not send signal to turn PC on.

  //I want to turn the LED (pin 13) on for only one second like a switch.
  //No repeats because I am using voltage from LED on wireless charger to trigger
  //the function once when phone is charging to turn on pc with optocoupler.
  if(PSU_Pin == LOW) {
    if(WirelessChargerPin == HIGH) {
      digitalWrite(ledPin, HIGH);
      delay (500);
      digitalWrite(ledPin, LOW);
    }
  }
  //Second, if PC is already on pin 13 must not be HIGH when phone is charging otherwise it shutdown the computer.
  else if (WirelessChargerPin == LOW) {
    if(PSU_Pin == HIGH) {
      digitalWrite(ledPin, HIGH);
      delay (500);
      digitalWrite(ledPin, LOW);
    }
  }

  delay(1000);

}

hope that helps...

I used it in Tinkercad to find out the led isn't blinking. Then I find out if have to do digitalRead on the analog pins. I added more delay just to make sure the PC doesn't act upon a false flag.

Thank you for your input. I'm gonna mark your comment as the solution since it solves my problem.

The final code below accomplished both goals.

int ledPin = 13;                                         // select the pin for the LED
const int WirelessChargerPin = A0;     //pin for analog reading
const int PSU_Pin = A1;                         //pin for sensing PSU is on using 3V3 rail
int value = 0;



void setup() {
  delay (1000);
  Serial.begin(9600);           //Start Serial
  pinMode(13, OUTPUT);   // declare the ledPin as an OUTPUT:
  digitalWrite(13, LOW); 
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);

}

void loop() {
  value = analogRead(PSU_Pin);         //Output to monitor for reading
  Serial.print("value =");
  Serial.println(value);
  delay(500);
  
//The two main goals
//-- 1. To turn PC on with Qi charger if PC is off.
//-- 2. If PC is on, do not send signal 
  
//I want to turn the LED (pin 13) on for only 1 second like a switch. 
//No repeats because I am using voltage from LED on wireless charger to trigger 
//the function once when phone is charging to turn on pc with optocoupler.
//Second, if PC is already on pin 13 must not be HIGH when phone is charging otherwise it shutdown the computer.
 	 
if(digitalRead(PSU_Pin) == LOW) {
    if(digitalRead(WirelessChargerPin) == HIGH) {
      digitalWrite(ledPin, HIGH);
      delay (1000);
      digitalWrite(ledPin, LOW);
      delay(5000);
    }
  }
 
  else if (digitalRead(WirelessChargerPin) == HIGH) {
    if (digitalRead(PSU_Pin) == HIGH){
      digitalWrite(ledPin, LOW);
    }
  }
  
  delay(1000);
}