I am trying to make a set up which works independently, and also send some data to computer when connected to computer.
This is powered by a a 5v Arduino Nano.
My concern is how to power the Nano.
External power has to be there, and I usually just feed 5V from a buck convertor into the 5V pin of the arduino. Then I would connect it to computer also.
But recently when I was using ESP32 boards, I connected external power supply (3.3V to esp32 board 3.3V pin) and computer both at the same time and it fried the ESP32 board and my computer keyboard too.
Yes, depending on the buck converter and your PC. If the buck is off it may appear as a short circuit and if you have power applied to the USB you will be shorting out your PC USB.
To be safe, I recommend having only one connected at a time. Use a switch.
Do they sell such cables commercially which have only data transfer lines and no power lines? And there won't be any danger to the board or computer if I just cut the power line of the data cable?? @jim-p
If the Nano clone you use has the diode, then the voltage on the 5V pin will be about 4.7V when running on USB. So you can test for that.
Then if the diode is present, you could insert a similar diode in the buck converter output. That way both supplies are protected, and the supply with the higher voltage will supply the load.
You would need a schottky diode. Something like an SB220 would do fine.