How to Write Arduino Programs - Lesson #3

by lucascreator in Circuits > Arduino

45 Views, 2 Favorites, 0 Comments

How to Write Arduino Programs - Lesson #3

lesson-2-thumbnails(1).png

Welcome to the third lesson of the Arduino for Beginners series - a complete, beginner-friendly journey into the world of electronics and programming.

In this tutorial, I'll explain how Arduino programs are created and, in the end, I'll guide you at writing, line by line, a simple program that blinks the built-in LED of an Arduino UNO.

Supplies

These are the tools and components we'll use in this tutorial:

  1. Arduino UNO
  2. DFRobot MindPlus Arduino Coding Kit
  3. Arduino Cloud Editor
  4. DFRobot Mind+

Video Tutorial

Write Your First Arduino Program in 10 Minutes - Lesson 3

I've recently posted a video on YouTube explaining everything you can read in this article. You can watch it right above.

Introduction

1.png
2.png

Have you ever wondered how we actually tell an Arduino what to do?

In this tutorial, you'll learn to program an Arduino using two beginner-friendly platforms: the official Arduino IDE and Mind+, a block-based coding environment (see images 1 and 2).

By the end of this guide, you’ll have written, line by line, your very first program to blink the built-in LED on your Arduino board every second.

Whether you prefer writing code or using drag-and-drop blocks, this guide covers both approaches. Best of all, both platforms are free and run directly in your browser.

What Is an IDE and Why Do We Need Code?

3.png
4.png
5.png
6.png

An Arduino board is essentially a small computer, or microcontroller, designed to perform specific tasks - like turning on LEDs, reading sensors, or controlling motors (see image 1).

However, the microcontroller doesn’t do anything on its own. It needs code - a set of instructions - to function.In reality, a computer only understands sequences of 0s and 1s (binary code).

But writing down programs by typing millions of zeros and ones is not an pratical approach (see image 2). Instead we use higher-level programming languages. These tools are nothing more than a set of English commands that makes easier the task of telling computers what to do (see images 3 and 4).

Any software, including Arduino programs, can be made inside an Integrated Development Environment (IDE). The IDE takes care of translating the programming language into binary code.

But not only that. It also helps developers improve their productivity by providing debugging and autocomplete tools, for example.

An IDE, or Integrated Development Environment, is where you write, test, and upload code to your Arduino board.

Think of it like a special notebook and translator combined: you write in English-like commands, and the IDE translates it into binary instructions your microcontroller can understand.

The Arduino IDE is the official coding environment for Arduino, but there are also third-party tools you can use to write programs - like Mind+, developed by DFRobot.

I'll cover both on this article.

Getting Started With Arduino IDE (Cloud Version)

7.png
8.png
9.png
10.png
11.png
12.png
13.png
14.png
15.png
16.png
17.png
18.png
19.png

To begin:

  1. Visit arduino.cc (see image 1)
  2. Click on Products > Arduino IDE (see image 2)
  3. Instead of downloading, click Go to Cloud Editor (you may need to sign in or create an account - see image 3)

Once inside the Cloud Editor:

  1. Click Create New > Sketch to open the code editor (see image 4)

You’ll see the default structure of image 5.

Now, let's analyze what Arduino IDE has created for us.

Every Arduino program follows this same structure. The first part - /**/ - marks the start and end of a comment.

A comment is any text that will be ignored by the IDE when converting the code into machine instructures.

At the top of your code, add this:

/*

This program will turn on and off the built-in LED every one second.

Lesson #3 of the Arduino for Beginners series.

*/

It should look like this (see image 6):

/*
This program will turn on and off the built-in LED every one second.
Lesson #3 of the Arduino for Beginners series.
*/

void setup() {

}

void loop() {

}


Congratulations! You wrote down you first comment in Arduino.

Now it's time to go deeper. The second part is the setup function. I won't dive into what a function is because I'll explain that on lesson #6, but for now you need to understand that all setup commands should be inside the setup structure

So add the following code (see image 7):

/*
This program will turn on and off the built-in LED every one second.
Lesson #3 of the Arduino for Beginners series.
*/

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {

}


The pinMode() instruction tells Arduino how a digital pin will behave, either as input or ouput.

The first parameter is the name or number of the pin and the second is the reserved words INPUT or OUTPUT.

So the command pinMode(LED_BUILTIN, OUTPUT); declares that the pin associated with the built-in LED, usually pin 13, must be set up as output (electric current can now flow from it).

Next we will code something that goes inside the loop function. This structure repeats itself continously.

Here we write down everything the Arduino board will perform, like reading sensors, controlling servos or motors, blinking LEDs, etc.

Open your Arduino IDE and type the following code (see image 8):

/*
This program will turn on and off the built-in LED every one second.
Lesson #3 of the Arduino for Beginners series.
*/

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}


This is the code that makes the LED blink every one second.

The digitalWrite() command is used to turn on or off the electric current that comes from an port set up as output.

The first parameter is the name or number of the port. The second one is the reserved words HIGH or LOW.The next command we used is the delay().

As the same suggests, this pauses the execution of the code during a specified amount of time. It gets time in miliseconds, so delay(1000) literally means "stop the code execution during a second".

Congratulations again! You coded your first sketch, line by line, and learned what each command does.

Now it's time to upload the code to your Arduino board.

Then, select your board in the top-left bar and upload it to your device (see images 9, 10, and 11).

If you are having trouble in this step, I explained how to set up the ArduinoIDE and connect it to your board on lesson #1.

After all, you should see the built-in led blinking. Even if you unplug the board and plug it back in, the program will still run because it’s saved in the board’s memory (see images 12 and 13).

I attached the coding file in this article library, but you can also download it from the official GitHub repository of this series.

Using Mind+ (Block-Based Coding)

20.png
21.png
22.png
23.png
24.png
25.png
26.png
27.png
28.png
29.png
30.png
31.png
32.png
33.png
34.png

We are going to create the same program again, but using another tool: Mind+.

Mind+ is a visual coding platform developed by DFRobot, ideal for beginners and kids.

To reach this goal:

  1. Visit mindplus.cc (see image 1)
  2. Click Code Online and sign in or create a free account (see image 2)
  3. Change the language to English - gear icon in the top right (see image 3)

To set it up:

  1. Click Connect Device and install the Mind+ Device Connector for your OS (similar to what we did in lesson #1 by installing the Arduino Cloud Agent). This little program will connect our computer to the Mind+ website so we can upload code from the cloud to our boards (see images 4, 5, and 6).
  2. Refresh the page and connect your Arduino on the USB port.
  3. Go to Extensions > Board > choose Arduino UNO (see images 7, 8, and 9).

You’ll now see green blocks specific to Arduino (see image 10).

To build the blink program:

  1. Drag a block: digital pin 13 HIGH
  2. Add a wait 1 second block
  3. Drag another block: digital pin 13 LOW
  4. Add another wait 1 second block
  5. Stack them inside the forever loop block (it's equivalent to the loop function in Arduino IDE)
  6. Then add a when clicked command at the top of all blocks

Your block structure should be similar to the image 11.

To run the code, connect the platform to your board (top-left menu) and click on the green flag on the top-right (see images 12 and 13).

Mind+ will convert the blocks into Arduino code and upload it to your board.

The LED will now blink on and off every second - just like with the Arduino IDE (see images 12 and 13).

A Word From Our Sponsor: DFRobot

6c1e2715-ab34-46b9-97fd-964322abe415.jpg
cddc4e2c-c4ba-4aaa-a572-b5d8c5853a8d.jpg
50fcfb77-4d0d-43cf-b11d-415f18d59277.jpg
923edd43-afa0-4125-8366-e7b5ea4e6f14.jpg

This lesson is brought to you with support from DFRobot, creators of the MindPlus Arduino Coding Kit.

This kit includes the black Arduino UNO board featured in this lesson, along with sensors, modules, and everything needed for future projects in this series.

DFRobot is a leader in the maker community, offering high-quality components for robotics, AI, and IoT applications.

I highly recommend getting a kit like the one I'm featuring - it’ll make following along with the series much easier and give you countless hours of practice and hands-on experience.

Be sure to check out their online store and explore everything they have to offer.

Big thanks to DFRobot for sponsoring educational content like this.

Conclusion

In this tutorial, you learned:

  1. What an IDE is and why it's essential for programming Arduino.
  2. How to write and upload your first sketch using the Arduino Cloud Editor.
  3. How to create the same program using Mind+, a block-based platform.

Stay tuned for lesson #4, where we’ll dive into electronics fundamentals like current, voltage, resistance, and Ohm’s Law.

Knowing this will be crucial for building more complex projects later in this series.

If you found this useful, follow the series and check out the full playlist here on Instructables or YouTube.

See you in the next lesson very, very soon!