Is it supposed to happen this way?

I was following the book's instructions to a tee, and even copied the correct code from makezine.com/ getstartedarduino to make the sketch where you press the button once to make the led light stay on. I verified the code and it came up clean. Then I uploaded it to my Arduino Duemilanove. I made the circuit down to the last contact on the breadboard using (note this) Adafruit Industries' Arduino Budget Pack. I noticed that in the first pushbutton lessen, when I used one of the two pushbuttons the budget pack gave me, only when I let go of the pushbutton did the LED blink. (as apposed to when I hold down the button) At first I assumed it was defected, and I tried the other one. The same thing happened. So then I thought that maybe it was supposed to happen and moved on to the next step: // Example 03A: Turn on the LED when the button is pressed and keep it on after it is released. This failed as well, for all that happened was the exact same thing as the first step. I was hoping that you more experienced ones could help me out. Is this supposed to mess up? Does the next step fix it? Is it an equipment malfunction? Or does the budget pack have the wrong type of pushbutton?

I was following the book's instructions to a tee

According to my book, your supposed to cut the butter into the flour until it is the consistency of cornmeal. Are you sure you did that? Or, are we not reading the same book?

What book are you talking about?

Each exercise in the book (whatever book it is) should produce the results described.

If pressing the button has some effect, but not the desired effect, it generally comes down to incorrect code or bad expectations.

Perhaps you could post the code you uploaded for one of the exercises, explain what you expected to have happen, and what you actually observed.

That you are able to connect hardware together, upload code, and see results shows that you are not too far off.

The book I am using is called "Getting Started with Arduino" and it was written by Massimo Banzi co-founder of Arduino.

This is the code I am using:

// Example 03A: Turn on LED when button is pressed // and keep it on after it is released

define LED 13 // the pin for the LED

define BUTTON 7 // the input pin where the pushbutton is connected

int val = 0; // val will be used to store the state of the input pin int state = 0; // 0 = LED off while 1 = LED on

void setup() { pinMode(LED, OUTPUT); // tell arduino LED is an output pinMode(BUTTON, INPUT); // and BUTTON is an input }

void loop() { val = digitalRead(BUTTON); // read the input value and store it

// check if the input pin is HIGH (button pressed) // and change the state if (val == HIGH) { state = 1 - state; }

if (state == 1) { digitalWrite(LED, HIGH); // turn LED ON } else { digitalWrite(LED, LOW); } }

What I expected to happen was for the LED to turn on and stay on after I pressed and released the button. and turn off when the button was pressed again.

P.S. You book has some hilarious sounding instructions, lol!

The code does not take contact bounce into consideration. Maybe that is what you are experiencing ??

I haven't learned about contact bounce yet. I'm a newbe.

Well that's surely going to toggle the value of state every time loop() runs round and the button is held? Which will be at least a few loops in the time it takes you to take your finger off the push button.

I'm not feeling sharp tonight but something like this might work - you only want to toggle the led when the button is pressed, not while it is held down.

#defines as previously

int buttonBlock = 0;
int ledState = 0;

void setup()
{
   // as before
}

void loop()
{
   int val = digitalRead(BUTTON);
   // if the button goes high whereas before it was low
   if ( (val == HIGH) && (buttonBlock == 0) )
   {
      ledState = 1 - ledState; //toggle LED
      if (ledState == 1)
               digitalWrite(LED, HIGH);
      else
            digitalWrite(LED, LOW);
        //set buttonBlock to 1 so that this code doesn't run again until
        //the button has gone low again first
      buttonBlock = 1;
   }
   else if (val == LOW)
         buttonBlock = 0;
}

Never mind, I got it to work. Thanks for all your help! Good luck!

What did you correct to make it work as expected?
Future readers with similar problems will want to know. :slight_smile:

Yeah, I have the same book... he's actually two examples away from doing what he wanted to. Please read that chapter closely because he's baby stepping you through this example to explain to you how to learn to write code. He even says right after the example sketch, "Now go test this code. You will notice that it works... somewhat. You'll find that the light changes so rapidly that you can't reliably set it on or off with a button press." and later tells you the Arduino will change the LED's value 16 million times a second, if you let it. He's having you learn one thing at a time so you can see what each new addition does for you. I went through that book and Making Things Talk and literally a week later was making just about any crazy thing that popped into my head. Don't just skim the chapter and copy/paste the code from Make... you wont learn a whole lot that way. Just my two cents...

Thank you so much for that advice. I got it to work now. And by the way, What kind of stuff did you make?

No problem, glad to help. The only build I've documented is this guy; http://www.instructables.com/id/Fart-Operated-Random-Channel-TV-Remote/

I've also built a handful of things to help around the house, played with input sensors and I'm working on another top secret project that'll become my second Instructable... if I ever finish it. Oh, and I've been playing with RFID readers and key fob tags. I tried putting a reader on the inside of a door and the lock will only unbolt if the fob is in place while the key is turned, but it didn't quite work out so I scrapped it. But yeah, I've only had my Arduino for a couple months and I've already been building stuff... it's pretty easy to learn.

According to my book, your supposed to cut the butter into the flour until it is the consistency of cornmeal. Are you sure you did that? Or, are we not reading the same book?

What book are you talking about?

This was just beautiful. Thank you PaulS for that! Call me childish, but I was just about on the floor laughing! :)

Some day I hope to be this good with words.. wow

Dear Schmidtn,
You have to buy a breadboard and Arduino board for every project, right? What is your source? How do you find out how to use code to control other random things like, for instance (I saw this on instructables), a Wii nunchuck?

You have to buy a breadboard and Arduino board for every project, right? What is your source? How do you find out how to use code to control other random things like, for instance (I saw this on instructables), a Wii nunchuck?

I'm not Schmidtn, but I can tell you that you don't need to buy new arduinos and breadboards for every project. The arduino boards as well as breadboards are meant for prototyping. You use them over and over again. Once you get a project working on a breadboard, you replicate it onto a PCB. Like these. This does require you to solder the components in so you would need that equipment too. It is not very difficult to make a standalone board with the ATmega328.

I'd suggest you start out very small with easy projects and slowly progress towards more advanced ones like interfacing with wii controllers..

P_Wood’s got the idea. I use an Adafruit ProtoShield, then move that over to RadioShack perfboard. I usually only end up needing the bare bones of the Arduino for things I build, so if you have an avr-programmer (Adafruit, again) then you can put the firmware on the ATmega chip and use your Arduino to flash your sketch to it. Or Adafruit sells ATmega chips already loaded with bootloaders.

ProtoShield I use:

with this 1/4-size breadboard on top:

RadioShack’s perfboard (in my local store) is hanging on a hook over by the pull out tool chests where they keep all their small parts.

USBtinyISP AVR Programmer Kit:

…and here are instructions on using it and your Arduino to load bootloaders (scroll down to, “How do I program a bootloader onto an Arduino?”)
http://www.ladyada.net/make/usbtinyisp/faq.html

Or this might be easier, just buy ATmega328 chips already loaded with the Arduino bootloader:

As far as input sensors go, I either read about it on sites like, Makezine, Instructables, HackaDay or forums, like this one. Or if nobody’s written about working with that particular sensor before I’ll read whatever datasheets are available for either it, or the IC that operates it, and play around until I figure it out. That’s the fun part! :wink:

You need to think about Arduino the same way you think about LEGO pieces. You only need to buy new stuff if you use the OLD stuff in a project permanantly.

And you know what? That's not what people generally do. I know SOME people do it... (keep the project on a breadboard and make it semi permanent) but that allows for SO many things to go wrong.

The breadboard should not be considered permanent because wires WILL fall out with the slightest provacation. If it's been a few days or weeks... you'll forget where things belong... so you end up with a broken circuit that takes time to fix.

Most people WILL convert a working design to something more permanant using PERFBOARD and solder all the connections, Other people,, (including me) will make a printed circuit board and make the design permanant and somewhat professional looking.

This really only applies to circuits that you REALLY want to keep. If, on the other hand, you will work on many lessons or ideas at once... you do want to buy some spare breadboards and wires.

Where to BUY breadboards and wires depends on whether you have places you can by direct over the counter or you have to buy online.

That adapter looks to small to have a normal usb cable. Were does it go in?

where do I find exact instructions to switch it to a PCB? do you get rid of the arduino board completely?

There's a guide in the Playground:

http://www.arduino.cc/en/Main/Standalone

You'll need an Atmega328 with bootloader and other various components.

With regards to pwillard; I agree that a printed circuit looks much better than perfboard, but etching your own board is a bit of a hassle (in my opinion) and I've only ever done it once on my own. You have to lay it out in CAD, print it, transfer it, there's nasty chemicals involved, you have to drill all those tiny holes by eye... just not fun and takes a while. Plus, I only really see an advantage to it, in a hobby sense, if you're making a bunch of the same circuit.

Artemis Fowl; the USB cable used with the AVR programmer is an A-B USB cable (same cable used to upload Sketches to your Arduino) and the square-ish end goes into the right side (on the picture) on the black enclosure.