Author Topic: PC PSU monitor with Arduino  (Read 1116 times)

0 Members and 1 Guest are viewing this topic.

Offline dawgTopic starter

  • Newbie
  • Posts: 7
  • Country: au
PC PSU monitor with Arduino
« on: November 03, 2019, 01:41:49 am »
hi,

this is for a PC PSU monitor using an Arduino to monitor the

input levels.

The Nano gets power from the 5VSB rail from the PSU


i would like to have an amber led blinking to show the PSU

is on Standby but thats for later once I get the basics

sorted

so this is what happens:
PSU is on standby no leds are lit yet

press the PC on button and a green led lights up for 3 secs

then it goes off while the PC is booting

when the PC shuts down, 5v low input is read, a red led

lights up for 3 secs then goes off



all very simple but the code so far I have has GOTO and I

know thats frowned upon but its all I can do right now

the code works to display the analog input states but thats

about all it does.

any clues to what code is best used

I have tried all the arduino supplied examples but cant

decide which way the code would be best
 

Offline dawgTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: PC PSU monitor with Arduino
« Reply #1 on: November 03, 2019, 10:42:23 am »
here's a basic example of at least the flow cycle, but it doesn't light anything up when testing the input
instead of the 4 leds I opted to start again at 1 red and 1 green led

Code: [Select]
const int analogPin = A0;    // pin that the sensor is attached to
const int ledPin = 2;       // pin that the LED is attached to
const int ledPin2 = 3;       // pin that the LED2 is attached to
const int threshold = 850;   // arbitrary threshold level of analog input
void setup() {
  pinMode(ledPin, OUTPUT); 
  pinMode(ledPin2, OUTPUT);}

void loop() {
int analogValue = analogRead(analogPin);
   
loop2:
{goto low;}

loop1:
if(analogValue<threshold) {digitalWrite(ledPin2,HIGH);} //SHUTDOWN MP3
{digitalWrite(ledPin2,LOW);}
delay(333);
{if (analogValue>threshold){goto loop1;}

low:
if(analogValue<threshold) {goto loop2;} //this is to BYPASS the middle code
else if (analogValue>threshold){digitalWrite(ledPin,HIGH);}
delay (333);//pc on voice 3 sec DELAY
if (analogValue>threshold){digitalWrite(ledPin,LOW);}
delay (333);


 {goto loop1;}
}}
 

Offline ozcar

  • Frequent Contributor
  • **
  • Posts: 342
  • Country: au
Re: PC PSU monitor with Arduino
« Reply #2 on: November 03, 2019, 06:18:56 pm »
In you code you refer to a “sensor” attached to A0, but you did not explain what you are really have connected there. Of course, you should not apply a voltage greater than the Arduino VCC, so you can't directly attach it to say the 12V output of the power supply. You could monitor the 3.3V or 5V outputs, but even there I would suggest including some series resistance in case something unexpected happens, say like you accidentally set the A0 pin to output mode.

In the code, I suggest defining two variables, one to represent the current power state (on or off) and the other the previous power state (also on or off) -  then you can check for a change, which it seems is what you want.

Something like this maybe:

Code: [Select]
const int analogPin = A0;    // pin that the sensor is attached to
const int ledPin = 2;       // pin that the LED is attached to
const int ledPin2 = 3;       // pin that the LED2 is attached to
const int threshold = 850;   // arbitrary threshold level of analog input
bool PowerOn,PreviousPowerOn = false;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
  PowerOn = analogRead(analogPin) > threshold;

  if ( !PreviousPowerOn && PowerOn )
    {  // power went on, turn on a LED for 3 seconds
      digitalWrite(ledPin,HIGH);
      delay(3000);              // 3 sec DELAY
      digitalWrite(ledPin,LOW);
    }

  if ( PreviousPowerOn && !PowerOn )
    {  // power went off, turn on another LED for 3 seconds
      digitalWrite(ledPin2,HIGH);
      delay(3000);               // 3 sec DELAY
      digitalWrite(ledPin2,LOW);
    }
   
  // power did not change, do nothing.

  PreviousPowerOn = PowerOn;   // keep power state for next pass
 
}

If that does not work, try displaying the analogRead value, but given I have not tested it at all, anything is possible!
 
The following users thanked this post: dawg

Offline dawgTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: PC PSU monitor with Arduino
« Reply #3 on: November 03, 2019, 09:46:03 pm »
ok thanks, I'll try this
 

Offline dawgTopic starter

  • Newbie
  • Posts: 7
  • Country: au
Re: PC PSU monitor with Arduino
« Reply #4 on: November 04, 2019, 02:16:05 am »
shit a brick that's awesome, it worked ! Brilliant mate

1 home
2 many thanks
3 goto home

cheers
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf