Hello,
I try to find out if the following is possible with my Arduino UNO R3:
The Arduino iss attached via USB to a mini computer and a battery as well.
I want the Arduino to monitor, if the pc is switched on. If the PC is switched off, the Arduino should recognize this and perform an action.
I tried a lot of different approaches to get an on/off signal via the USB, but I never get it to recognizing, when the PC is switched off.
I would be happy for every idea, if and how to solve this.
Hello,
at first: It's a special minicomputer for astrophotography. And when it is switched off, all Ports are "dead"
I tried different approaches
1st: try to check just the serial because I would attach the Arduino just to a free UBS-Port and there is no communication. It never jumped into the "else"
void loop() {
if (Serial) {
// USB is on
} else {
// USB is off
}
}
2nd approach
void loop() {
while (!Serial) {
// USB is off
delay(500);
}
}
3rd Measure the voltage
void loop() {
if (usbVoltagePresent()) {
// USB is present
} else {
// USB is off
}
// Eine kurze Verzögerung, um die Ausgabe nicht zu überfluten
delay(1000);
}
bool usbVoltagePresent() {
return (analogRead(0) > 500);
}
In the Uno R3, the AVR microcontroller just has a UART - no native USB - so it cannot "see" the USB at all, and Serial will always be "up".
Do you have to use a Uno R3? Could you, instead, choose something with native USB? Then the processor would be able to see the state of the USB connection...
Had you connected A0 to somewhere that would measure the USB voltage only - and not your battery?
Hello,
the LED-strip is an idea. But because I take astro photos with this configuration, it has to be as dark as possible.
I'm an absolute newbie on Arduino, so I hope you don't mind my question:
What is USBVCC?
To be more precise I will describe my end goal:
I use an dedicated astrophoto computer (ASIairPlus) which controls my telescope and my astro camera. It has several USB-ports for astrocam, telescope and so on.
And it has von DC 12V outputs for these slave devices (camera, telescope,..).
You take astro photos for several hours at night. So I want to setup the gear and go to bed. When the astro computer has finished its program it switches itself of. And here comes the Arduino to action. It should monitor, if the computer is switched off, and then should trigger (i think of a servo) to close the telescope.
That's my goal.
While writing, the DC 12V ports come to my mind. Because they go "dead" too, when the computer will switch itself off.
Could this be an easier approach to know if the Master device (astro computer) went off?
Yes. On that computer, there are 4 12VDC outputs, and only two are used by my gear.
So I can choose one to monitor. And I found an DC Sensor modul on amazon, that brings the 12V down, so I can easily measure it on the arduino on one of the analog ports.