Electronic – Detecting when AVR ICSP header has a cable connected

avricspvoltage-detector

I have a bunch of Atmega16A MCUs laying around so I want to use them with an ESP8266 to relay temperature and such in each room of my home to a server. The thing is, if I need to update the firmware on them, I need to take the device from that room to a different one to update the firmware.

The issue is once i plug in the programmer, it will supply power to the controller and it'll start detecting the temp of the room and tell the server the room it was in is the temp of the room it is currently in. The server doesn't know the difference so it'll skew my results and such.

So is there some way I can detect when the ICSP 6-pin header has the programmers cable connected? Just some simple thing that will tell the controller, "Hey we may not be in the right room, don't tell the server any measurements"

For clarification, the header that I'm going to use is this one:enter image description here

Best Answer

How about this? When the board is powered from an external source, the D1 will prevent any voltage from appearing on ICSP VCC and R1 will ensure the line ICSP Present reads low.

When you plug in the programmer and it starts supplying power, the MCU will get power through the diode and ICSP Present will read high.

The 1K resistor is there just to limit the current that may flow through the GPIO ESD diodes.

schematic

simulate this circuit – Schematic created using CircuitLab


EDIT

The datasheet states that the voltage on the GPIOs should not exceed VCC by more than 0.5V, so you should to get a Schottky with a Vf < 0.5V at whatever current your board requires.

enter image description here