let's say that I've connected an arduino uno to a pc, or to a mobile phone via usb .. how can I detect the device type and the running operation system if it's possible?


3 Answers 3


You can't, using stock firmware. And with custom firmware it's still very difficult.

The USB communication chip on the Uno has no out-of-band means of telling the main MCU that it is connected to a host. You might be able to rewrite the communication firmware on the R3 to tell the main MCU over serial that it is connected, but the firmware on the main MCU will need to be written in such a manner that it will anticipate this.

If you want this to work then you should consider using one that has a native USB connection, such as the Leonardo. You will then be able to query the USB facility directly to know whether or not you are connected to a host.


No. The arduino sees usb through a USB-> UART converter (typically FTDI). UART doesn't allow you to do anything other than listen on the RX line and throw bits at the TX line.


I did not try to go further, but I know there is some information passing on Serial1 when you plug a device.

void setup() {  

void loop() {  
  if(!Serial1.available()) {  
  else {  

Maybe you can try to see if depending on the device, information is persistent, in which case you should be able to detect a specific device / kinf of device ? I'll look at it tomorrow, maybe will have more code to show...

  • Unfortunately this proposal is fundamentally mistaken - the Arduion Uno which is the subject of the question does not have a "Serial1". Also, even in the context of some hypothetical other board, the question is not about detecting if there is a host, but detecting which type and operating system it is running, something that would require identifying and categorizing differences in behavior. Dec 3, 2016 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.