Question: how to fix an error occurred while uploading the sketch?
Answer: 2 Answers. When uploading a sketch, you must disconnect the serial I/O pins from any devices before an upload succeeds. The Uno shares the two hardware serial pins with the USB that's used to perform sketch upload, so nothing else can be connected to the serial pins (0 and 1).