Atmega8 demo assembled

Like I promised in the Protostack kit review, here is the most simple application that a beginner can make, the simple embedded version of the “Hello world”, based on simple push button input turn on a led, this involves the usage of digital input read, and digital output write.

I made a simple application to read the PORTB.5 pin state and in response turn on or off the LED attached to the PORTB.0 pin, and I want to demonstrate the importance of the pull-up or pull-down resistors when using the digital port as input source. When you configure the digital port as input, the micro controller internal circuit is reconfigured and the pins input impedance is very high, in simple terms any weak signal can change the pins state.

This is a double bladed sword, since your signal source can easily drive the input, but when your signal source isn’t connected the smallest noise can interfere with your input, and give you false readings, this is mostly common with push button, matrix keyboard, switch contact inputs.

In digital electronics the engineers use the terms pull-up or pull-down resistor, this is a simple resistor usually between 10k and 100k, to define the input state when no signal source is connected, this way overriding the noise signal, common sense dictates that when you have potentially larger noise then a smaller resistor is needed, but don’t be careless about it, don’t place a 100Ohm resistor because your signal source must be able to “defeat” the pull-up(down) resistor. A rule of thumb is to use at least 10x larger pull-up(down) resistor then your signal source impedance.

The pull-up term is used when the resistor connects the pin to the + and pull-down when connects to the ground, but then which should you choose? Good question, in these days it doesn’t really mater, your application or the pcb design should dictate, the older generation digital IC’s had asymmetrical current sink/source capability, they could sink more current and because of that the pull-up resistor was more common.

Here is the schematic of the simple application, the power and ISP connection are not shown:

atmega8 demo schematic

The ATmega8 micro controller has internal pull-up resistors of 100-200k value, this comes handy since in most cases it will be enough, I made some simple tests with and without the internal pull-ups active.

Here you have the demonstration(no pull-up active):

atmega8 demo cable touch no pull-up

Since the PORTB.5 pins is the SCK pin for the In system programming interface it’s connected to the programming cable. It was enough to touch the cable and the input pin’s state was changed.

atmega8 demo proximity no pull-up

As you can see here, I am holding the tool close to the pin header and not touching it, but the input already picks up the noise.

Now you would ask, from where does the noise signal come, well since your house is wired with the mains voltage most of the noise is picked up from the 50/60Hz, the rest is probably high frequency noise.

After I enabled the internal pull-up on the input pin these annoying interferences disappear:

atmega8 demo cable touch with pull-up

Immune to the cable touch.

atmega8 demo finger touch with pull-up

Doesn’t triggers even when I bridge the input pin to ground trough my finger.

atmega8 contact with pull-up

The LED turns on only when I connect the input to ground by short circuiting the pin header with the tool, which is the correct operation.

Overall advice: when using digital inputs, always use pull-up or pull-down resistors the most simple way is to use the internal pull-ups, but check if effectively eliminates the noise, if not use external resistors, in case of external pull-down disable the internal pull-up!

Project archive with source file and additional photos: ATmega8 simple project