Arduino project 7 – buttons

arduino project with an LED and two buttons

two buttons and a light

The next arduino project in the book is the first to use input: it uses two buttons and an LED, so that pushing one button will turn the light on and the other turns it off again.  Still a simple idea, but one that illustrates how input can be used in a program to control a light, and could be extended theoretically to control any components by pushbutton input.

The loop part of the program is straightforward:

void loop(){
   if (digitalRead(inputPin1)==LOW){
     digitalWrite(ledPin,LOW); //turn LED off
 }
 else if (digitalRead(inputPin2)==LOW){
   digitalWrite(ledPin, HIGH);//turn LED on
 }
}

It was strange to be back writing in Java again with its curly braces and semicolons, not to mention having to declare variable types, but I’m finding it easier these days to switch between the two – and of course indenting comes through habit having dealt with Python so much!

What does frustrate me now is that theoretically I should be able to code a set of pelican crossing lights triggered by pressing a button, and I’m sure that I could reasonably easily figure out the code to use, but the knowledge I don’t have is how to join the components together, as the project book tells you what to use and where but not why or how they work. Comments like “there is one component that might seem out of place…” really don’t help, as its assuming more knowledge of the circuit than I have.

I’m starting to make a point of looking at the circuit diagram supplied as well as the schematic of the construction, but I’ve no idea when resistors are needed or what size to use, or when a capacitor or transistor is needed, and I would not be able to create my own project, although I’d be quite happy following the sorts of instructions I’ve come across so far, which are of the type of put X here and Y there and Z goes in this spot.  To be honest, I’m not sure what sort of time I’d have to learn any more about these components, although I have come to enjoy my weekly soldering sessions (last week I made a battery powered gadget that responds to sound by flashing lights on and off, and the timer I made the week before has somehow started working correctly – previously it wasn’t beeping when the time was complete, but just when it was turned off).

What I have gained over the summer, however, is a deeper understanding of what circuit boards are (I even looked up how to make them!), what the different components are, the skill needed to assemble and solder them and the sorts of things that can be done with an arduino and a handful of bits.

There are still four more projects in the book, and there are plenty more arduino books out there, but with summer drawing to a close I’m not sure how much time I’ll have to devote to playing with electronics.  My interest has only grown over the few weeks I’ve been playing, however, and I’ll be doing my best not to abandon the arduino and the soldering iron.

I may even try playing with bits and doing some research to see if I can mock up the three traffic lights, two pedestrian lights and button that would be needed for a pelican crossing prototype!

In the meantime, the weekend’s task has to be to get the Pi up and running and see what I can do with that, so I’m off to tidy my desk up a bit to make room.

 

Advertisements

About emmyleigh
Writer/editor/proofreader who loves technology

One Response to Arduino project 7 – buttons

  1. Bosstiger says:

    Reblogged this on Gigable – Tech Blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: