PC PSU monitor with Arduino - Page 1
Forum section: electronics / general

author: dawg
author_rank: Newbie
timestamp: November 03, 2019, 01:41:49 am
content: hi,this is for a PC PSU monitor using an Arduino to monitor theinput levels.The Nano gets power from the 5VSB rail from the PSUi would like to have an amber led blinking to show the PSUis on Standby but thats for later once I get the basicssortedso this is what happens:PSU is on standby no leds are lit yetpress the PC on button and a green led lights up for 3 secsthen it goes off while the PC is bootingwhen the PC shuts down, 5v low input is read, a red ledlights up for 3 secs then goes offall very simple but the code so far I have has GOTO and Iknow thats frowned upon but its all I can do right nowthe code works to display the analog input states but thatsabout all it does.any clues to what code is best usedI have tried all the arduino supplied examples but cantdecide which way the code would be best

author: dawg
author_rank: Newbie
timestamp: November 03, 2019, 10:42:23 am
content: here's a basic example of at least the flow cycle, but it doesn't light anything up when testing the inputinstead of the 4 leds I opted to start again at 1 red and 1 green ledCode:const int analogPin = A0; // pin that the sensor is attached toconst int ledPin = 2; // pin that the LED is attached toconst int ledPin2 = 3; // pin that the LED2 is attached toconst int threshold = 850; // arbitrary threshold level of analog inputvoid 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 codeelse if (analogValue>threshold){digitalWrite(ledPin,HIGH);}delay (333);//pc on voice 3 sec DELAYif (analogValue>threshold){digitalWrite(ledPin,LOW);}delay (333);{goto loop1;}}}

author: ozcar
author_rank: Frequent Contributor
timestamp: November 03, 2019, 06:18:56 pm
content: 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:const int analogPin = A0; // pin that the sensor is attached toconst int ledPin = 2; // pin that the LED is attached toconst int ledPin2 = 3; // pin that the LED2 is attached toconst int threshold = 850; // arbitrary threshold level of analog inputbool 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 secondsdigitalWrite(ledPin,HIGH);delay(3000); // 3 sec DELAYdigitalWrite(ledPin,LOW);}if ( PreviousPowerOn && !PowerOn ){ // power went off, turn on another LED for 3 secondsdigitalWrite(ledPin2,HIGH);delay(3000); // 3 sec DELAYdigitalWrite(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!

author: dawg
author_rank: Newbie
timestamp: November 03, 2019, 09:46:03 pm
content: ok thanks, I'll try this

author: dawg
author_rank: Newbie
timestamp: November 04, 2019, 02:16:05 am
content: shit a brick that's awesome, it worked ! Brilliant mate1 home2 many thanks3 goto homecheers