# How to protect my program in ATmega328?

**URL:** <https://forum.arduino.cc/t/how-to-protect-my-program-in-atmega328/91915>\
**Category:** Programming\
**Created:** [February 26, 2012, 4:56pm UTC](https://forum.arduino.cc/t/how-to-protect-my-program-in-atmega328/91915 "2012-02-26T16:56:17Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![nickgammon](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nickgammon](https://forum.arduino.cc/u/nickgammon)\
**Post date:** [February 26, 2012, 7:51pm UTC](https://forum.arduino.cc/t/how-to-protect-my-program-in-atmega328/91915/6 "2012-02-26T19:51:35Z")

</div>

It would be something like this:

```arduino
avrdude -c usbtiny -p m328p -U lock:w:0xFC:m

```

You could do that via the SPI interface using a USBtinyISP or similar programmer.

Be warned that after doing this you can only ever change the chip again by using a high-voltage programmer like the AVR Dragon. So if you don't have one of those to hand you have now made your chip un-programmable. Better do that when you are really confident it is right.

> Is there a way to protect my code when I use only Arduino board and Arduino IDE? Can I set the lock bits from the program that I upload into the processor?

No, I don't think the bootloader has that capability.

The USBtinyISP (kit) costs $22 from Adafruit:

> **[USBtinyISP AVR Programmer Kit (USB SpokePOV Dongle)](https://www.adafruit.com/product/46)**
>
> USBtinyISP is a simple open-source USB AVR programmer and SPI interface. It is low cost, easy to make, works great with avrdude, has both 6 and 10 pin standard ISP cables, is ...

This is a kit, you have to assemble it.

* * *

The AVR Dragon costs $50.96 from Digi-Key.

> **[ATAVRDRAGON | DigiKey Electronics](https://www.digikey.com/en/products/detail/microchip-technology/ATAVRDRAGON/1124251?lang=en&s=N4IgTCBcDaIIYDcBOACAJkuBzA9gOxAF0BfIA&site=US&x=0&y=0)**
>
> Order today, ships today. ATAVRDRAGON – AVR® AVR Dragon™ Programmer (In-Circuit/In-System) from Microchip Technology. Pricing and Availability on millions of electronic components from Digi-Key Electronics.

Be warned that to use the Dragon you have to do a fair bit of jumpering of pins because it is designed for lots of different processors.

* * *

Personally I wouldn't bother. Unless you are doing production runs of lots of processors it is hardly worth the effort. If it is just for you, you need the extra expense and trouble of being able to reprogram with one of these devices.

For your customers, if you have them, they can no longer field-reprogram them, so if you find a bug they would have to be returned to you. And if the processor is soldered onto the board you will have a lot of trouble using the high-voltage programming.

---

_[View the full topic](https://forum.arduino.cc/t/how-to-protect-my-program-in-atmega328/91915)._
