Moonbase Otago - Dunedin Arduino project - CPUs

CPUs and Prototyping Boards

The Arduino CPU

The Arduino CPU you have is a 'clone', a cheap copy, of the Arduino UNO - the circuits are different but they program the same.

The actual CPU is the square chip in the middle. The red button at the top left is the "reset" button, it stops the CPU and tells it to start again at the beginning.

There are 3 lights (LEDs) L, TX and RX - you can control the L led, turn it on or off - the TX and RX LEDs tell you when the Arduino is talking to the USB connector

On both sides of the CPU are connectors for "pins" - these are how you connect your Arduino to other circuits to make them do things. Or you can plug in another circuit board on top called a "shield".

On one side are the power pins and "analog input" pins. The interesting power pins are the "5V" (5 volts) and "GND" (ground) pins. We can use them to power our circuits. It's probably best to not use the other power pins unless you understand what they are for.

The analog input pins are used when we want sense a voltage that's somewhere between 0 volts and 5 volts - we'll use them with some of our input sensors

On the other side are digital pins - they can be outputs: they can either be turned "on" (have 5 volts on them), or "off" (have 0 volts on them - ie ground/GND). Or they can be inputs, can sense an "on" (close to 5V) or "off" (close to 0 volts) on them. The best pins to start with are digital pins D2 - D12

Programming the CPU

If you haven't read the "Getting Started" section and installed the Arduino software now's the time to go and do it

Plug you Arduino into a USB cable and into your computer, make sure your Start the Arduino program - there's a couple of minor setup things we need to do the first time - in the "Tools" menu choose "Board" and choose "Arduino Uno". Next in the "Tools" menu choose "Serial Port" and choose the port that your device is plugged into - if your device isn't there or the "Serial Port" menu is greyed out check your connections, are there lights on on the Arduino? maybe you need to reinstall the drivers you installed in "Getting Started"

So let's write a little program, there's probably already one running on your Arduino - it's why the "L" LED is flashing - let's make it flash a bit faster. Arduino programs are called "sketches" there's already a sketch called "Blink: you can find from the "File" menu - choose "Examples"->"01 basics"->"Blink". It looks like this:

	int led = 13;

	// the setup routine runs once when you press reset:
	void setup() {         
  		// initialize the digital pin as an output.
  		pinMode(led, OUTPUT);     
	}

	// the loop routine runs over and over again forever:
	void loop() {
  		digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  		delay(100);               // wait for a second
  		digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  		delay(100);               // wait for a second
	}

The delay() makes the CPU wait - how long is measured in milliseconds - one thousandth of a second - to make it faster change the two "1000"s to "100". Now load your sketch into your Arduino - press the right arrow "upload" icon at the top of the page - you'll see the RX and TX LEDs on the Arduino twinkle. Once the new program has been loaded it will automatically run - the L LED on the board will now flash faster. You've loaded a new program into your Arduino.

Notice how every Arduino sketch has two parts that must always be there:

Firstly "setup()" is called once when the Arduino starts a sketch - which is when the Arduino is turned on, the reset button is pressed, or a new program is loaded. This is where you put the code that only has to be called once to set the system up, things like choosing what a particular pin will do.

  	void setup() {
                // initialisation stuff goes here
        }

Secondly "loop()" is called over and over again as fast as possible after setup() has been called - this is where you put the code that will actually do things.

  	void loop() {
                // most of your program goes here
        }

Battery Power

Your Arduino can be powered two ways: from a USB cable, and from an external power source - anything between 6V and about 20V. We've included in the kit a connector you can use to run your Arduino from a 9V battery.

Simply plug it into the Ardiono this way:

Prototyping Boards

Prototyping boards are used for easily connecting wires and components together without solder - the one in your kit is a very simple one - it has rows of 5 holes - any wire or component pushed into a hole in a row will be connected to any other component pushed into another hole in the same row.

For example the black, green and blue lines on this diagram show rows of holes that are connected:

Be gentle with your proto boards - pushing wires or components with leads that are too big, more than one wire per hole, or forcing things into them can damage them and make them not work as well. You may find that trimming

Let's make something simple - connect an LED and a resistor between the "5V" and "GND" - first take a 1K (1000) ohm resistor and an LED and a couple of hookup wires and plug them into your proto board like this:

Really they are wired together like this:

Now hook one of the wires to "5v" pin on your Arduino and the other one to any of the "GND" pins. If the LED doesn't light switch the pins.