Featured post

# Welcome!

Our class is aimed at both students and teachers, young and old. Lessons begin with application. We will build a circuit and program the chip and then go back and look at what is happening. In order to give you the ability create your own projects these lessons will give you an understanding of what is going on behind the scenes.
Arduinos and other parts you will need are available in the webshop.

# 1.1 : Ground work

First lets quickly go over the basics. It all starts with electricity. Electricity is the flow of electrons through a conductor like metal. We can use electrical components to make a circuit that does things like lights up. One such component is the transistor. The transistor is a gate for electricity. We can set the gates to be opened or closed. Using lots and lots of these gates we can make complex interactions.

At the heart of the Arduino is a microcontroller. A microcontroller is a type of integrated circuit (IC). Which means it is an electronic circuit that has been shrunk down and covered in plastic. It is filled with transistors and when we program the Arduino we are setting the gates inside to be opened or closed. When we run the program through the chip we are running electricity through the gates to perform complex calculations. How can a bunch of gates perform complex calculations? Watch this video from Evil Mad Scientist Laboratories to get an idea.

# 1.2 Environment

Lets setup our programming environment. Our microcontroller thinks in binary. Binary means two. It thinks with transistors which are either open or closed, one or two. That may not seem like much but we use only 10 numerals (0-9) and can count pretty high. You do not need to know about binary right now because the Arduino application on our computer will translate into binary for us.

Follow the directions on the Arduino website to set up your programming environment.

You will connect your computer to the Arduino, open an example program and upload it to your Arduino. All the example program does is cause one of the LEDs on the Arduino board to blink.

Once you have your Arduino and computer working together lets take a look at the Arduino programming environment:

 Type your program in the Arduino application then press “upload” to send it to the Arduino. The application will translate into language the chip understands and then load it onto the chip. The program will begin to run right away. The Arduino does not need to be plugged into USB to work but it does need to receive power from somewhere. Create a circuit on the breadboard and connect it to the Arduino with jumper wires. Here is where the fun happens.

In the next section we will complete the environment by connecting the Arduino to a breadboard.

# 1.3 Distributing Power

First, lets connect our breadboard to Power and Ground on the Arduino board. The breadboard has two long strips for Power and Ground on each side. I put my Arduino right on top of the breadboard and hold it there with a rubberband or double-sided tape..

`Breadboards can be a little confusing at first. If you want to learn more about them look here: Solderless Breadboards`

• Connect the blue strip on the breadboard with the ground (GND) pin on the Arduino.
• Connect the red strip on the breadboard with the 5v pin in the Arduino.
###### This will run power and ground up and down both sides of the breadboard.

Original 3D Arduino model by Engineer Zero

Connect the two sides of the breadboard together.

Finally you need to connect power and ground to both sides of the breadboard.

• connect the two sides of the breadboard together as shown on the left. Make sure you connect ground to ground and power to power.

Now that power and ground are running up and down the breadboard it will be easier for us to set up circuits like the LED driver we create in the next section.

###### Most LEDs have a shorter lead and a flattened edge which indicate the cathode.

• Disconnect the USB cable from the arduino in order to remove the power.
• ### LED Driver Circuit

An LED circuit allows electricity to flow through an LED and create light. The Arduino can provide power to the breadboard from the USB cable. We will use a resistor to protect the LED from too much electricity. Take a look at this schematic which shows the circuit.

Power flows from Pin 13 on the Arduino, through the LED and resistor, to ground. It is important to note that electricity can flow through the LED in only one direction. The legs of the LED are called leads. The short lead goes towards ground. We call this lead the Cathode. The long lead, called the anode, goes to power. Many LEDs will also have a flattened edge to indicate the cathode.

• Connect Pin 13 to one of the numbered rows on the breadboard.
• Insert the LED into the breadboard with the longer leg in that same row.
• Insert one side of the resistor into the same row as the shorter leg of the LED.

Now the circuit is set up and ready to run.

• Reconnect the Arduino to the USB cable.

In the next section we will take a look an what is going on in that code we loaded.

There are some videos about these parts in the Discover Electronics Class:
LED Driver Circuit
The Light Emitting DiodeThe Resistor

[code lang=”arduino” firstline=”1″]
/*
Turns on an LED on for one second,
then off for one second, repeatedly.

This example code is in the public domain.
*/

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
[/code]

Here is the example Arduino blink code. We call the programs we write for Arduino “sketches.” The Arduino program comes with many basic example sketches available in the file menu. Lets take a look at what is happening in this sketch.

The text in grey are called comments. It is a good idea to comment your code as you write it. This is just to make the code easier for people to read. All text that appears in between /* and */ or after // becomes a comment. The computer strips out the comments when uploading the program to the Arduino.

Here is the same code without the comments:

[code lang=”arduino” firstline=”8″ gutter=”0″]
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
[/code]

Now lets take a look at the statements in the Blink code. The statements all end with “;”
[code lang=”arduino” firstline=”8″ gutter=”0″]
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
[/code]

### pinMode(13, OUTPUT);

The first statement is pinMode. When the Arduino reads this statement it changes what job a pin has. In this case we are telling pin 13 to be an OUTPUT pin. An output pin effects the flow electricity. It is like a switch that can be connected to power or ground whenever the Arduino says.

### digitalWrite(13, LOW);

Next we have digitalWrite. This tells the Arduino to connect an output pin to either power or ground. As with the previous statement, we need to give some information when we send the command. In this case, pin 13 and HIGH. HIGH means power and LOW means ground. When we created our circuit on the breadboard we connected Pin 13 to ground through our LED circuit. When we tell the Arduino to make pin 13 HIGH, power can flow to ground through the LED circuit. When pin 13 is LOW both ends of the LED circuit are connected to ground so electricity does not flow.

# Section 1 Exercises

In order to really learn you must use your knowledge. In this section you will complete assignments that use what you have learned in section 1.

Change the speed of the blink or introduce a pattern of blinking.
You can change the amount of time of the delay commands to keep the LED on or off as you like. You can also introduce more and more delay and digitalwrite commands.

### 2. More light.

Add a second LED circuit on pin 12.
This is just repeating what you did before but now you will have to code to blink both leds.

### 3. Alternating pattern

Make a pattern where the second LED blinks multiple times every time the first LED blinks.

===============================================================

## Solutions

There are many possible solutions. Here is one:
[code lang=”arduino” firstline=”8″ gutter=”0″]
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(400);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(100);
}
[/code]