Electronics 101 - Getting started with Arduino

ArduinoYunFront_2_450pxThese days everybody talks about IoT. Connecting your toaster to the internet has become a nationwide priority. Finally the barrier to entry to the hobbyist/home electronics have fallen and anyone can hack an hardware solution using cheap and simple components.
And putting together a simple circuit controlled by Arduino/Raspberry Pi/whatever is easy, it’s just a matter of
I have always enjoyed writing software that effect the real world and this new wave seemed like a good opportunity to dust off my 12th grade electronics classes from old. Having acquired an Arduino Yun I’m ready to create my very own “hello world” example. In this case make a LED (Light Emitting Diode) blink.

Ingredients

For the purpose of this simple demo you would need to following:
image

Writing the application

Writing code for Arduino is easy. A program is called “sketch” and it uses a C like syntax. We have comments, variables and functions. The bare minimum are two methods: setup and loop.
You can add additional methods if the need arise but this is as simple as it gets.
image
Let’s write our program. We’ll use pin 13 for output. The reason for choosing pin 13 is that on most Arduino boards we have a LED on board.
yun_scheme_p3
The code for this first simple program looks something like this:

const int ledPin = 13; 

void setup() { 
    pinMode(ledPin, OUTPUT); 


void loop() { 
    digitalWrite(ledPin, HIGH); 
    delay(1000); 
    digitalWrite(ledPin, LOW); 
    delay(1000); 
}

Seems simple enough, but just in case let’s go over the code:
And that’s it, the loop would run continuously turning the LED on and off.
Use Ctrl+R to compile and verify the sketch. You can also upload and run without connecting any components and see the little L13 LED on the board light up – but what’s the fun in that?

Connecting the board

Looking at the Arduino you’ll see it has a few numbers and weird words on its side.
image
The numbers are the digital inputs/outputs. near number 13 we have GND (ground) which will also need.
Connecting to the outputs is as simple as putting a wire through a hole.

In the real world it would look something like this:
image
For the uninitiated it might look a bit “wireless” – the components do not appear to be connected. Just remember that the bread board has wires running underneath which essentially connect the whole line.
Here is the same circuit with the “hidden connections” marked.
image

Run!

Connect your Arduino to your computer and Upload the sketch.
image
Note: Don’t forget to choose the correct port and board before trying to upload.
image
And after a short while you should see the LED lighting up!

image

Troubleshooting: If your LED does not light up (but the on-board LED does)check that all the components are connected in the right order, make sure that you’ve connected the positive side of the LED (long) to pin 13 and the negative side to GND.
If you feel comfortable enough with this simple example – why not try and implement a binary counter:

What’s next

That was a simple electric circuit using Arduino Yun. I hope that it looked simple enough and that you’ll be able to use this post to build your own. I hate to see software developers shy from electronics just because it’s out of their comfort zone (being “hardware”).
As for me – I’m waiting for a big shipment of electronic goodies – and have plans for future hobby projects that I can use them in. I might even write a few more posts on the subject.

But until then – happy coding…

Labels: , ,