We definately see that there is a Serial thing going on, and it looks like there is a procedure call as well. This is a library procedure call. The library is called Serial and inside the library is a procedure called begin.
.
(input values)
Serial
begin
;

If there's no library name, it means that the procedure is in the 'default' collection of procedures we use. For example, delay() is so common, the designers of the Arduino software didn't bother putting it into a library.

So there's some mystery procedure that's called begin, well it's not too tough to figure out what it might do. It's the procedure that gets the Serial stuff ready. But what's the 9600 about?
The comment says 9600 bps, and just so you know bps stands for bits-per-second (we will refer to this as the baud rate)
If you have broadband connection, you may remember reading somewhere that it has, say 350 kbps download rate. This is how fast the connection can read and write bits on the wire. (Needless to say, your broadband connection can transfer data a lot faster than an Arduino!)

OK so Serial.begin sets up the Arduino with the transfer rate we want, in this case 9600 bits per second.
Lets move on to the next line.
This line also uses the Serial library, this time it's calling a procedure called println which is just a shorthand for 'print line'. Note that the 6th letter in println is the letter L not the number 1. This time the input is a quotation, the line of text we would like it to print. We use two ''s (double quotes) to indicate the beginning and end of a line of text.
Quick quiz!
Good, now compile the sketch and upload it to your Arduino....
And then...nothing???
It looks like not much is going on here. Somewhat disappointing since we had so much fun with blinking colored lights before. The trick here is that while you can see blinking lights quite easily, seeing serial data requires a monitor, which like your display monitor will show us what data is being transfered.
Lucky for us, there's a serial monitor built into the Arduino software!

I'm not quite sure what the icon means, but regardless if you click that button you will replace the black Program Notification area with a Serial Monitor.

So...click it!

What happens next is, sadly, quite dependent on which kind of Arduino you have

WindowsMac OS X Linux
NGArduino does not reset.Arduino does not reset.Arduino does not reset.
DiecimilaArduino resets, starts the sketch a few seconds later Arduino resets, starts the sketch a few seconds later Arduino resets, starts the sketch a few seconds later
In the very common case of having a Diecimila Arduino, the serial monitor will auto-reset the Arduino. The sketch will start up a couple of seconds later
Otherwise, the Arduino does not reset itself. Either way, once you've switched to the serial monitor, press the reset button. If you have an NG Arduino you'll have to wait 7 seconds for the sketch to start.

Voila! It is our sketch!

If you ever find that you're getting a whole lot of gibberish instead of proper text, make sure that you have the correct baud rate selected in the drop down menu of the Serial Monitor. Note that this communication baud rate is indepedent of the upload process, which is fixed at 19200 bps.

Next, try pressing the reset button a few times to make more Hello Worlds! appear. If you have an NG, this may be a bit annoying but do it anyways.

Each time you reset the Arduino, it performs the setup procedure, and prints out Hello again. If you look closely at the Arduino, you will also see the little TX LED blink just as it prints out this message. That's your indication that data was sent.

When you println you are sending data from the Arduino to the computer. The Send button (and the text input next to it) are used to send data to the Arduino. We aren't going to be using it in this lesson so don't be surprised that it doesn't do anything when you click it!

10 PRINT HELLO
20 GOTO 10
Our next sketch will be a minor modification of this one. Instead of printing out Hello World just once, we'd like it to print it out over and over and over again.
Quick quiz!
Perform this modification and then compile and upload the new hyper-hello sketch. Then start up the serial monitor. You will see Hello World! scroll by super fast!
Quick quiz!
Make the Arduino chill out a little by adding a one second delay to the sketch, so that it only prints out Hello World once a second.
Now you should spend some time playing with println and making it display a message of your choice! Perhaps add some more println statements in order to make the message longer?
Math is hard, let's try programming!
We've played around with printing out phrases, but it turns out we can also print out numbers pretty easily too.
Try out this sketch on your Arduino
Note that we're using 2 procedures here, the original println and now also print. The print procedure is just like println except it does not print out a 'carriage return' at the end, starting a new line. You can experiment with changing the print's to println's and looking at the Serial Monitor output to verify this for yourself.
Here's whats going on in the Arduino with this sketch. For example, lets look at this line:
We've seen that if you use a quoted line of text as input to println procedure, it will display that text. In this case you can see that if you use a variable to println it will look up what that variable contains and print that out!
It turns out that the Arduino is smart enough to also do math when asked:
In this case, the Arduino looks at what the input to println is, and finds its actually a calculation. It looks up what a is (5) and what b is (10) and then adds them together (+) and then uses that as the value to send to println
Note that for now, we can only do math using integers, which if you recall, are whole numbers. That means we can't yet print out numbers like 3.14 or 1.5.
I could go on and on about operators, its all very important stuff, but many people have written good tutorials on this topic already so I'm going to send you off to read them there!
Pythagorean party
Let's make our first simple calculator, to calculate a hypoteneuse. If you remember from grade school, if you have a right-triangle, the hypoteneuse h can be calculated from the lengths of the two legs, c1 and c2 (which we'll call a & b)

a2 + b 2 = h 2
h = (a2 + b2)

The first thing that's new here is this line at the very beginning of the sketch:

Pic16f690 Serial Communication C Code Tutorial

Which basically says 'We'd like to use the math procedures, which are in a library that requires us to include the file math.h where the sqrt procedure lives'. Just ignore it for now, it's not important.

The second thing that's different here is that when we create the variable h we don't assign it a value.

It turns out that this is totally OK, it just means that we don't know what h is going to store yet, because we're going to calculate it later. Since it's not assigned to a value upon creation, the Arduino just creates the box, the stuff inside is whatever was in left over in memory.

Default values

If you don't assign a value to a variable, it could be any value. Make sure you don't try to use the variable before you assign it a value!
Later on in the sketch, we assign it the value.
In this line, we square a and b and then add them together, then we call the sqrt() procedure (which does exactly what you may think), to take the square root. Then we assign that to the variable h.
=
;

Whatever was in h before is lost, replaced by the new value.

You can nest procedures and functions all you want, calling a procedure on the return value of another procedure.

Quick quiz!

Now its your turn to create a calculator.
You'll create a Ohm's law calculator. Ohm's law says that Voltage = Current * Resistance. (This is a pretty useful law which forms the basis of electronics, and we'll study it in depth more later.) Starting with two variables, i for current and r for resistance, have it print out the amount of voltage that can be measured accross the resistor.
Let's write a program that will do that hard drive size calculation we did before. We'll start with the hard drive size in GB, and print out how many MB there are.
We'll start simple, just printing out the drive size in GB
Copy and paste this sketch into Arduino software and name the sketch DriveCalc. Then compile and upload it.
OK, lets add a section of code that will print out the number of Megabytes in the hard drive.
This time if you compile and upload it you should get

Which is correct, yay! Now try a few different whole numbers for the drive size, from 1 GB to 100 GB.

You may notice that if you put in a 100GB drive size, something very, very strange happens:

A 100GB drive should have 102400MB in it, not some negative number. What's going on here?

What's happening is that we have an overflow problem. Think about your car odometer. The odometer has only 4 digits, it can display 0 miles to 9999 miles travelled. If you travel 10000 miles, the odometer will 'roll over' to 0 again, and from then on it will display an incorrect value.

Keeping that in mind, remember in lesson 2 we said that when we define a variable we also define the box-type of the variable? The box is where we store the data, in this case the type is int. It turns out that an int type can store only 2 bytes.

Quick quiz!
How many bits are in 2 bytes?
Highlight the text below for the answer
There are 8 bits in 1 byte so 2 bytes is 16 bits

To figure out how big a number we can store in a 2 byte-sized box use a calculator and take 2 to the power of the number of bits (since each bit can store 2 values, 0 or 1). Then we subtract 1 because like in the car odometer, you can't actually display the final value, 10000. So, in this case the largest number is 216 - 1 = 65535. Since the number we're trying to store (102400) is larger than that, we see that 'rollover.'

OK let's fix it! All we need to do is change the variable type so that it can store more than 2 bytes of data. Here is a short list of types we can use.

It looks like we want to use the long type. So lets make that change

Compile and upload this sketch....then run the Serial Monitor....
Uh oh, we didn't actually fix the problem!
How frustrating, we did the right thing and it still didn't work. The problem we have now is although the boxes are the right size, we're not handling them well.
If you look at this line, what's happening here is that the Arduino looks up the value of the variable drive_gb to get 100. Then we multiply 100 by 1024 to get 102400 and put that in the drive_mb box. Except the way that the Arduino software does this is that it creates a temporary variable the same size as drive_gb to store that calculation result before it sticks it into drive_mb. So basically we are still getting an overflow, except now its happening as we do the calculation.
Here is one way to fix this insiduous bug:
Now when we do the calculation, the temporary result is stored in a box the same size as drive_mb (a long) instead of an int.

Compile and upload this sketch to try it out

There you go, now its working!

It turns out that I wasn't completely honest in the previous section when I described all the different types. There's another important fact to know, and that has to do with storing negative numbers.
We know that a variable that is 2 bytes large (16 bits) can store 216 different values. We assumed before that these values were 0 - 65535 inclusive. But then how do we store negative numbers? It turns out that there are two kinds of variables, signed and unsigned.
Signed variables can have a positive or negative value, so you can store negative numbers.
Unsigned
variables can only store positive numbers.

By default, variables are signed.

TypeSize (bits)Size (bytes) Minimum Value Maximum Value
8
0
byte
1
127
16
0
int
2
32767
32
0
long
4
2147483647
Quick quiz!
Why Types?

OK so you're probably wondering: 'This is such a pain, why bother with different size types? Lets just have every variable be as big as possible and we'll never have roll-over problems.'

Well, on your desktop computer, with gigabytes of memory (RAM), this is a reasonable thing to do. However, the tiny tiny computer in the Arduino has a grand total of 1 Kilobyte of memory. And some of that is used for background stuff you don't see. For small sketches sure you can make everything a long and be done with it, but if you have a bigger sketch, you'll run out of memory really fast and then you'll have major problems. So in this case, every byte counts!

What's weird about signed numbers is that if you reach the end of the positive value range you'll rollver into the negative values.
For example, lets say you have a signed int. If you have the value 32767 in that variable, and you add 1 to the variable, you'll actually rollover to -32768.
This sketch will test out this fact:
Compile and upload to run the test.

Quick quiz!

Now it's your turn!
Write some sketches that will help you understand variable sizes, try creating variables of different types and signedness and adding and subtracting.
Although this lesson part seems quite boring, and severely lacking in blinky lights, understanding this stuff now will save you from a lot of headaches later when you have data overflows and your program is all wonky and you're really frustrated because you can't figure out why. (Trust me on this one!)
Wrapping up, the final project!
Now its time for you to expand the drive size calculator. Starting with the DriveCalc sketch, modify it so that it will also calculate how many KB are stored in the hard drive. Test it out with a couple different drive sizes.
Once you've got that working, modify it again so that it will also display how much space the drive actually holds thanks to the sneaky math-trick that manufacturers use. Have the sketch display how much storage space is 'missing' (in KB) as well.
Here's one possible solution:
Conclusion
Good work, you got through one of the more boring lessons. In this lesson you learned how to print text and data to the Serial Monitor. This is essential for debugging future projects! You also learned about data types and storage and how to use the Arduino to calculate stuff.