Last Updated: 20/07/2021
Lesson 2 - Hello World
Lessons >> Basics >> Lesson 2 - Hello World
Lesson Contents
Why "Hello World" is important Structure of a line of code including the semi colon Functions learnt: Serial.begin(), Serial.print(), Serial,println() Printing Text, Numbers and Calculations Reminders and how to version code in a simple way User of Serial Window Setting Baud Rate and what it means
Example 1: SerialPrintv1.ino
Click to Download code:SerialPrintv1.ino
Print Hello World to serial monitor
/* 16/07/2021
* SerialPrintv1
*
* Purpose, print Hello World to serial
*
* After completeing lesson alter spelling case of functions to see error
*/
void setup() {
// Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second
Serial.begin(9600);
//Send Hello World
Serial.println("Hello World");
}
void loop() {
// put your main code here, to run repeatedly:
}
Example 2: SerialPrintv2.ino
Click to Download code:SerialPrintv2.ino
Print Numbers to serial monitorLearn the difference between numbers as a Variable and numbers as text print calculations
/* 16/07/2021
* SerialPrintv2
*
* Purpose, tp print numbers
*
*
*/
void setup() {
// Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second
Serial.begin(9600);
//Send script name
Serial.println("SerialPrintv2...");
//sends 123 as a text string to serial
Serial.println("123");
//sends 123456 as a number
Serial.println(123456);
//send 5+10
Serial.println(5+10);
//send 5+10 as text
Serial.println("5+10");
//send 5*10
Serial.println(5*10);
}
void loop() {
// print in the loop
Serial.println("Serial Print in loop");
}
Example 3: SerialPrintv3.ino
Click to Download code:SerialPrintv3.ino
The difference between Serial.print() and Serial.println()
/* 16/07/2021
SerialPrintv3
Purpose, to use function Serial.print does not put a carriage return at the end of the line
*/
void setup() {
// Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second
Serial.begin(9600);
//Send script name
Serial.println("SerialPrintv3...");
//this will print a blank line
Serial.println(" ");
//Serial.print NOT Serial.println
Serial.print("Val X: ");
Serial.println(23);
Serial.print("Val X: ");
Serial.println(46);
}
void loop() {
// print in the loop
//line below has been commented out
//Serial.println("Serial Print in loop");
}
Example 3: SerialPrintv4.ino
Click to Download code:SerialPrintv4.ino
An example of how variables would be printed out from the loop()
/* 16/07/2021
SerialPrintv3
Purpose, to use function Serial.print does not put a carriage return at the end of the line
*/
void setup() {
// Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second
Serial.begin(9600);
//Send script name
Serial.println("SerialPrintv3...");
//this will print a blank line
Serial.println(" ");
//Serial.print NOT Serial.println
Serial.print("Val X: ");
Serial.println(23);
Serial.print("Val X: ");
Serial.println(46);
}
void loop() {
// print in the loop
//line below has been commented out
//Serial.println("Serial Print in loop");
}
Additional Resource Links
Don't forget to use the Reference in you Arduino IDE and look at Serial for more help on this lesson.Comments
This site has been designed to be child friendly, this means that comments cannot be added to videos or directly to the site. To add a comment or ask a question please email the address in this image: and use Lesson 2 - Hello World as a reference.