The “Hello, World!” program is a tradition in programming, often the first written by beginners to demonstrate basic syntax and output. It originated in the early 1970s with the C programming language and was popularized by Brian Kernighan in his book “The C Programming Language”.
Initially a simple example in C to show output, “Hello, World!” has become a symbol of a programmer’s first steps.
Since Arduino is based on C, let’s make it our first official program.
Code
Explained
The line is a command in your Arduino code that tells the computer to include a special set of instructions (called a library) needed for your program to work with the development board hardware. This library provides functions (commands) to control things like turning on/off pins, reading sensors, and using the Serial Monitor.
In the Arduino IDE, you don’t have to write this line of code because the IDE automatically adds it for you behind the scenes. This makes it easier to start coding without worrying about extra lines of code.
The setup function runs once when the Lonely Binary Arduino or ESP32 board is powered on or reset.
Inside setup(), we initialize the serial communication with the command Serial.begin(9600). This tells the Arduino to communicate with the computer using the serial port at a speed of 9600 baud (a measure of data transfer rate) to communicate with Arduino IDE’s serial monitor.
The loop() function runs continuously after setup() finishes. It repeats forever, allowing the Lonely Binary Arduino or ESP32 board to keep doing the same thing over and over.
Inside the loop(), we use Serial.println(“Hello, World!”) to send the text “Hello, World!” to the Serial Monitor. This is like printing the message to the screen of your computer.
The delay(1000) command pauses the program for 1000 milliseconds (1 second) before the next iteration of the loop. This introduces a pause between each message printed to the Serial Monitor. Without the delay, Serial.println would print messages to the Serial Monitor too quickly. Try adjusting the delay time to observe how it affects the speed of output in the Serial Monitor.
Serial Monitor
The ESP32 development board includes a USB-to-Serial chip, which facilitates communication between the ESP32 and your PC. This allows you to upload code from the PC to the ESP32 and retrieve information from the ESP32 to the PC.
The Serial Monitor in the Arduino IDE is a tool for sending and receiving data between your computer and the ESP32. It’s particularly helpful for debugging by displaying messages, values, or sensor readings from your program.
