Reset an arduino to factory

hi all,

I have here an arduino uno and mega 2560 both with code on it.
This code was programmed via an atmel ice an I would like to return there in there factory condition.

When I program the following bootloader I get some errors.
uno: \arduino-1.8.5\hardware\arduino\avr\bootloaders\optiboot\optiboot_atmega328.hex
mega: arduino-1.8.5\hardware\arduino\avr\bootloaders\stk500v2\stk500boot_v2_mega2560.hex

When I try to program them then with the an example I get the following error code:
Uno:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b115200 -D -Uflash:w:C:\Users\dylan\AppData\Local\Temp\arduino_build_632740/BareMinimum.ino.hex:i
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x35

Mega:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM6 -b115200 -D -Uflash:w:C:\Users\dylan\AppData\Local\Temp\arduino_build_632740/BareMinimum.ino.hex:i

avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM6
Using Programmer : wiring
Overriding Baud Rate : 115200
avrdude: stk500v2_ReceiveMessage(): timeout

Can someone help me with this problem?

If code was programmed using an Atmel ICE (or any ISP programmer), that would have erased the bootloader, so that you need to do a "burn bootloader" (or equivalent) (using an external programmer) before you can simply "upload" sketches again.

where can i find the bootloaders? the one i used aren't working

The bootloaders should be included in the Arduino IDE installation, automatically accessed by the "burn bootloader" command. The actual .hex files end up being in ".../hardware/arduino/avr/bootloaders/*" (exact location dependent on OS, install method, and actual board.)

Click "Burn Bootloader"