Archive

Archive for January, 2012

And if you don’t know, now you know.

January 18, 2012 Leave a comment

I’ve got to put my projects on the back-burner as school starts up again, but I’ll be trying to keep in touch with electronics and the Arduino as best as I can. I’ll probably get sucked into mini projects every now and then anyway since I constantly bombard myself with sources of intriguing information relating to electronics.

So that’s what this post will be about, spilling the beans on my current sources of stories and general info on electronics and the Arduino. I’ll try to organize this list by what I frequent the most.

reddit.com/r/Arduino+Electronics+AskElectronics+Ece+Engineeringstudents

Reddit’s electronics related subreddits combined into one link. All of those constantly provide me with new ideas and interesting articles to read, and I see people submit questions that I have all the time. /r/Breadboard and /r/Letslearnelectronics also merit a look.

EEVblog – eevblog.com

“An off-the-cuff video blog for electronics engineers, hobbyists, hackers and makers.” This guy puts out some really entertaining and educational videos, some of the topics may be a bit advanced for the beginner but it gets you thinking in that electronics mindset.

Ladyada / Adafruit Industries Tutorials

Some great tutorials by Ladyada on the Arduino, electronic components, projects, and programming.

Arduino.cc Tutorials and Arduino.cc Reference

Nothing better than having your source of info be right from the creators of the Arduino.

bildr – bildr.org

“Documented methods for doing one thing, and offering them for as many microcontrollers as possible.” Puts out beautifully done tutorials.

falstad Electronic Circuit Simulator

Simple circuit simulator. You can add wires and various components to try out some basic ideas before you build them.

kpsec The Electronics Club

Very nice site for easy to digest explanations of basic electronic principles, various components and parts, and sample projects and prototyping.

Others worth mentioning:

jeremyblum.com

electronics-tutorials.ws

tronixstuff.wordpress.com

conductiveresistance.com

Advertisements

SparkFun Free Day is Today

January 11, 2012 Leave a comment

Who doesn’t like free stuff?

Basically, it’s just a server stress test for SparkFun Read more…

Categories: Other Tags: , , , , ,

for Loop

January 11, 2012 Leave a comment

I’m going to do a quick run though the “for” loop, using a part of this guide as a foundation.

Using the Arduino.cc explanation here you can get a basic understanding of how it works.

The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.

There are three parts to the for loop header:

for (initialization; condition; increment) {
    //statement(s);
}
The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it’s true, the statement block, and the increment is executed, then the condition is tested again. When the condition becomes false, the loop ends.

So now that you have a basic understanding of the for loop, lets see how we can apply it…

I will use my own version of the original example sketch from tronixstuff to illustrate how the for loop functions.

Click here for Pastebin with syntax highlighting for the following code.

void setup(){
    pinMode(9, OUTPUT);
}
void loop(){
    for (int x = 1; x <= 5; x++){
        digitalWrite(9, HIGH);
        delay(1000);
        digitalWrite(9, LOW);
        delay(1000);
    }
    delay(10000);
}

Here’s whats actually happening in the for loop in human language:

    for (set x equal to 1; is x less than or equal to 5?; increase x by 1){
        set pin 9 high;
        wait one second;
        set pin 9 low;
        wait one second;
    }
    wait 10 seconds;

The steps taken in our loop are;

  1. a variable “x” is set to equal to 1, this is done once
  2. a test is done to check if x is equal to or less than 5
  3. if the test is passed, the statements inside the braces are acted upon
  4. x is set to equal x + 1
  5. steps 2 through 4 are done until the test fails, in which case the loop is terminated

The physical result of the sketch – if you have an LED hooked up to pin 9 of the Arduino – will be that the LED will blink 5 times, wait 10 seconds, blink 5 times… and so on, for infinity.

That’s pretty much it. You can do more complicated things with the for loop, but the fundamentals can be summarized to: initialize, test, incrament/decrement.

if Test

January 9, 2012 Leave a comment

The “if” is a test you give to the Arduino. In this test you make the questions and you determine what happens when it passes or fails. If the test that you made is passed, as in something happens that you wanted to happen, then you want the Arduino to do a certain action. Optionally, if the test is failed or something unexpected happens and the test is failed, you can tell the Arduino to take a different action.

If you wanted to make a test on the Arduino that would turn on a light for 5 seconds every time someone walked through a door it would look something like this:

if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }

And a translated human readable version to understand whats going on:

if (a person walks through the door) {
 turn on the light;
 wait 5 seconds;
 turn off the light;
 }

Now, let’s try to understand the Arduino version of the test and see why it works…

A person can only be walking through the door or not, we can represent this as 1 or 0, respectively. Then, we can assign this state to a certain variable – which can be thought of as a digital box that can hold thing – we’ll call this variable “PersonWalkingThroughDoor”.

If a person is walking though a door our variable PersonWalkingThroughDoor would equal 1, otherwise it would be 0. Given this basic setup we can run a test, and that is exactly what this part of our code does:

if (PersonWalkingThroughDoor == 1) {

If our variable PersonWalkingThroughDoor is equal to 1, then it would pass our test and go into the action phase, where it would preform a certain task.

digitalWrite(LIGHT, HIGH);
delay(5000);
digitalWrite(LIGHT, LOW);
}

What happens in our “action phase” are just some basic commands, first we use digitalWrite() to set the pin attached to the LIGHT variable to HIGH (turning on the light), then we wait 5000 milliseconds, then we turn the light off.
Finally, if you want to expand the function of the test then you can include an “else” clause which would look something like this:


 if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }
 else {digitalWrite(LIGHT, LOW);}

In that case, if the initial test is failed you can tell the Arduino to take a different action. In our case it would simply keep the light off if there is nobody walking through the door, and it truly inessential as the light is turned off by default after 5 seconds.

So that’s it, that’s the basic overview of an if function. You might know it, but the best way to understand it is to try it out yourself.

Understanding LEDs

January 5, 2012 Leave a comment

Ah, LEDs. To me, they are to electronics what fire was to the early man.

Such a simple thing. Take any coin cell battery – making sure the plus side of the battery goes with the longer leg of the LED – slide the legs of the LED over the battery and you have LIGHT!

Here’s a simple explanation on how LEDs work from reddit user speedstix:

LED’s are semiconductor technologies that are really good at converting electricity to light. There are two types of semiconductors. N-type silicon and P-type silicon. N-type silicon has excess electrons in it. P-type silicon has extra holes that electrons are drawn to. This is important to remember. Now if you sandwich N-type silicon and P-type silicon together you get something called a diode. Hence the name Light Emitting Diode (LED). Now when these two materials are sandwiched together where they meet the holes from the P-type silicon attract the electrons from the N-type silicon. (think of north and south poles of magnets and how opposites attract) This attraction creates a barrier. Now if you connect a positive DC voltage to the P-type side and the negative part of this voltage to the N-type side this barrier gets smaller and smaller and eventually electrons will jump from the P-type side to the N-type side. Remember from before these jumping electrons are what creates light. Depending on how big or small this barrier is you will get different coloured light. Also if you reverse this voltage you make the barrier bigger and bigger and no electrons will pass. This is exactly what a diode is intended to do. Only allow current to flow in one direction.

For a more detailed explanation you can go here: HowStuffWorks.com

A nice macro image of an LED via wikipedia:

(Side Note: Remember that electrons flow Cathode (-) to Anode (+), and conventional electric current flows positive to negative.)

Protoshield

January 5, 2012 1 comment

This post is about the OLIMEX protoshield that I bought and assembled about a week ago.

Mfg Website: http://www.olimex.com/dev/proto-shield.html

The User Manual: Datasheet (.pdf)

It’s a funny story that this turned out to be a great alternative to the SparkFun Protoshield Kit I was going to buy for $17. The only reason that I have it now instead of the one from SparkFun is because I accidentally left it out of my order form when I submitted it, and I didn’t feel like going through he hassle of contacting customer service to change the order.

Anyway, the only issue I had was that it had two extra pins that wouldn’t fit the Arduino.

I ended up just clipping the two pins since they didn’t seem to have a necessary function. Works just the same without them. I also added a simple tiny breadboard so that I can do rapid prototyping and experimenting right on top of the Arduino.

This gives it a very simple and clean look AND function. Makes it easy to see exactly whats going on with a quick glance.

Definitely recommend one if you plan on working on more that one project at a time, as you don’t have to worry about matching up the pins correctly every time you switch over to a different project, simply attach a different shield and you’re good to go. Got mine from Mouser for $8, here’s the link to the product page.

Creation

January 3, 2012 Leave a comment

I can’t describe how immensely satisfying  it is to start with a blank sketch like this,

Applying my combined understanding of the Arduino, electronics, and programming to create this,

And have it compile and run flawlessly, and create a physical response:

It’s something so simple, and yet, it’s so empowering.