NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Where is the NerdKit's button hooked up on the breadboard?

May 09, 2010
by SamGiambalvo
SamGiambalvo's Avatar

I'm trying to make a simple program where, when the button is pressed, an LED is turned on and off, and I'm not sure where the button is placed. Any help is appreciated.

May 10, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi SamGiambalvo,

That is a great exercise you have in mind. Certainly a good way to start getting familiar with things. Where you put the buutton is pretty much up to you as long as the rows you connect the push button to are all not being used. You need to wire up your pushbutton such that the microcontroller can detect when you push the button. It is up to you which pin you do this on, you just have to make the code reflect the correct pin. Our digital calipers dro has a great explanation of push buttons both in the text, and in the video. Take a look through that and see if you understand how the push button is wired up. Let us know if you have any questions.

Note: the push button leads are a bit large, but we usually just bend them a bit force them into the breadboard. It actually makes for a fairly snugg fit.

Humberto

May 10, 2010
by SamGiambalvo
SamGiambalvo's Avatar

Humberto,

Thanks for the reply, but I just can't seem to get it working. Pin C of the button is connected to MCU 28, NO is connected to MCU 26, and NC is connected to MCU 25. When I run it, the led immediately blinks and then turns off. Here is my code:

#define F_CPU 14745600

#include <avr/io.h>

#include <inttypes.h>

#include "../libnerdkits/delay.h"

int main() {

DDRC |= (1<<PC4);

PORTC |= (1<<PC5);

 if((PINC & (1<<PC5)) == 0)

 {

   PORTC |= (1<<PC4);

   delay_ms(1000);

   PORTC &= ~(1<<PC4);

}

else {

    PORTC &= ~(1<<PC4);

    }

return 0;

}

Thanks again for your help,

SamGiambalvo

May 11, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Sam,

It looks like you are more or less on the right track with the code, but you don't really understand what is happening with the button. In end your MCU can only detect a voltage change on a pin. You want to wire up your Push button such that pushing the button changes the voltage on the pin. You have the pull up resistor turned on on PB5, that is a great start, this means that PB5 will be high unless it is otherwise pulled low.

You should connect your push button with the NO (normally open) lead connected to your input pin (PB5 in this case). The C (common) lead to GND, and the NC (normally closed) lead unconnected. This way when you push the button the NO and C leads become connected electrically, pulling the voltage on PB5 low. All this is explained in the dro video tutorial I pointed you to earlier.

Humberto

Post a Reply

Please log in to post a reply.

Did you know that an analog comparator can tell when one voltage input crosses another? Learn more...