Thanos Stantzouris Industrial Engineer & Web Developer

Hey y'all, welcome back to yet another article of Duthcode! I know that I am not the fastest gun in the west but I keep trying to put out some fresh content for all the curious-minded geeks and nerds out there.
I have decided to put out a series of Arduino tutorials and how-tos to spice things up a little! I am going to start with the basics and in future tutorials, I will try to raise the complexity and introduce some very cool and handy Arduino projects! Just be patient, a difficult skill, but a virtue.

Since this is the first part of the series let's clear out some basics about Arduino.

What is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino Boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino Programming Language (based on Wiring), and the Arduino Software IDE, based on Processing. You are always welcome to Google anything you don't know. That's how you learn.

Why Arduino?

Over the years Arduino has been the brain of thousands of projects ( Like these cool 10 Arduino Projects ). Once you get involved it just makes your mind expand and keep "downloading" new ideas, and it's also very fun. You don't need any electronics experience to construct your ideas but surely, in the end, you learn a lot of new stuff. I've seen Programmers, Hackers, Architects, Teachers, and even Musicians use it and the results were so different from each other but equally amazing.

There are many other microcontrollers and microcontroller platforms available for physical computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and many others offer similar functionality. All of these tools take the messy details of microcontroller programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems:

  • Inexpensive
  • Cross-platform
  • Simple, Clear Programming Environment
  • Open Source and extensible software and hardware

 

In these series, the structure will be as simple as possible

Part 1: Hardware you need to build the Project.
Part 2: Image of the circuit and instructions for definite success.
Part 3: Code Time!
Part 4: You never know... I haven't really thought this through! :) hehe...

 

Board Breakdown

To get started with Arduino you don't need to have extreme knowledge of electronics but you surely need to know your way around the Board. So without further ado, I present to you: 
The Arduino Uno board
Arduino Uno Board Explained

1 | RESET BUTTON - The reset button does pretty much the same as unplugging the board and plugging it back in. It restarts your program from the beginning.

2 | AREF - Stands for "Analog Reference" and is used to set an external reference voltage.

3 | GND (Ground) PIN - There are a few Gnd pins on an Arduino board, they are all used for the same purpose.

4 | DIGITAL I/O ( Input/Output ) - Pins 0-13 are used for digital input and output. 

5 | PWM - Some of the 13 digital i/o pins are marked with a tilde (~), these pins (11,10,9,6,5,3) are the ~PWM pins which are capable of simulating analog outputs.

6 | TX/RX - These two pins are used when data is transmitted. Ex. (For Receiving and Transmitting Bluetooth data from a Phone to a Bluetooth module).

7 | POWER LED INDICATOR - This LED lights up anytime the board is connected with a power source.

8 | ATmega MICROCONTROLLER - This chip is the brain. This is where we store our programs when we upload them from the IDE. (It can be removed from the board and replaced with a new one).

9 | ANALOG PINS - These pins can read the signal from an analog sensor and convert them to digital.

10 | MORE GND PINS - You know what these are.

11 | 5V PIN - From this pin, a power of 5v (Volt) is being supplied to the project.

12 | 3.3V PIN - From this pin, a power of 3.3v (Volt) is being supplied to the project. (Sometimes a power supply of 5V is a bit too much for some modules to handle).

13 | DC POWER BARREL JACK - This is used for powering the Arduino projects with an external supply (Like batteries).

14 | VOLTAGE REGULATOR - This controls the amount of voltage going into the Arduino board.

15 | USB CONNECTION - This is used to power up the Arduino and to upload sketches (A project's code in the Arduino world is called a sketch, keep that in mind while googling).

 

Don't get discouraged, the breakdown was just because this is the first tutorial, you don't really need to know any of these details. While coding and building with Arduino you are going to tackle every single aspect of it and with the time you will find out that you have accidentally learned them. In other words...

Wax on Wax off

Great movie.

 

Getting the Software ready

Ok! Continuing to my favorite part. As you may know in order to upload your code to Arduino boards you first have to download the Arduino IDE, BUT! It's 2020 and every programmer nowadays use their own preferable code editor for multiple tasks. You can use your code editor to code python scripts, websites and solve simple C/C++ problems or create big projects using a plethora of different languages and frameworks, you name it. So who are we to not use an editor for programming our Arduino boards? Let's take it to the future!

 

Installing platform.io to Visual Studio Code for Arduino Development

A new generation ecosystem for embedded development.

  • Cross-Platform PlatformIO IDE and Unified Debugger - Static Code Analyzer and Remote Unit Testing
  • Multi-Platform and Multi-architecture Buil System - Firmware File Explorer and Memory Inspection

It also already supports over 700 boards from leading manufacturers, and constantly keeps adding new ones. You can also submit a feature if you want.

PlatformIO is independent of the platform, in which it is running. The only requirement is Python, which exists pretty much everywhere. What this means is that PlatformIO projects can be easily moved from one computer to another, as well as that PlatformIO allows for the easy sharing of projects between team members, regardless of operating system they prefer to work with. Beyond that, PlatformIO can be run not only on commonly used desktops/laptops but also on the servers without a Windows System. While PlatformIO itself is a console application, it can be used in combination with one’s favorite Cloud & Desktop IDE or text editor such as PlatformIO IDE for Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, Vim, Visual Studio, PlatformIO IDE for VSCode, etc.

Alright, so PlatformIO can run on different operating systems. But more importantly, from a development perspective at least, is a list of supported boards and MCUs. To keep things short: PlatformIO supports approximately 200 Embedded Boards and all major Development Platforms.

[Source: https://docs.platformio.org/en/latest/what-is-platformio.html#overview ]

 

Installation

Open the Visual Studio Code editor and find the extensions box on the left side menu or press ctrl+shift+x type "platformio" click on the platformIO IDE and press the install button. Wait for the installation to end and restart VsCode. When you open the editor again you should be greeted by platformio's welcome panel.

Platformio VsCode Home Panel

How cool and easy was this? Now you can easily create your Arduino projects from visual code, build them, and also upload them to your board just like with Arduino IDE but in a way cooler manner. And these are just simple applications, imagine what could happen if you also combine other abilities that VsCode extensions give you, like GitLens for example.

Future telling: I'll be using GitLens quite a lot for future more complex Duthcode Projects.

 

The Blink Project

Everything is going according to plan and we are finally ready to embark on our Arduino journey with our very first project. Are you excited? Of course, you are!
The blinking LED is the "Hello World" of Arduino, it's not much but you finally know that you have everything working appropriately and from now on the sky is the limit. The feeling is thrilling. 

First of all, we need our materials!

I recommend buying an Arduino Starter Kit because you will get many modules and useful stuff for a really small price.

 

Making a led Blink like a Boss!

Now that we have all the parts that we need let's create the circuit,

Simple Arduino Blink Schematic

The ballast resistor is used to limit the current through the LED and to prevent that it burns.

Read more http://www.resistorguide.com/resistor-for-led/

I am using Fritzing for drawing my circuits, in case you are wondering.

This schematic depicts the correct way to connect an LED to an Arduino board with no fear of it getting burned.

  • The digital pin 12 outputs 5v or 3.3v of current, depends on what power source we have connected with our board, and it is connected to one leg of our resistor.
  • The 220ohm resistor is used to limit the current through the LED and to prevent that it burns. It connects the wire coming from the digital pin to the long leg of the LED.
  • We then connect the short leg of our LED to the GND pin.

 

Schematic for the curious

 

Arduino Blink LED Schematic

 

The Code

The theory is complete, the hardware is bought and built, the only thing that remains is the Software. So let's create our project in our Editor.

Opening up VsCode we see the PlatformIO home panel.

  • Under Quick Access Column click + New Project.
  • Give your project a name, I named it Blink.
  • Select your Board, Arduino UNO.
  • The Framework should be autocompleted to Arduino. If not, complete it yourself.
  • Uncheck the Location Box and choose manually the path you want your project to be saved.
  • You know what's coming. Press Finish and wait until the Project is ready.

 

Arduino Blink Project Generated with PlatformIO

 

This is what should be on your screen. On the left the file structure created by PlatformIO and on the right your main.cpp file. Now copy and paste the following code :

 

/**
 * Blink
 *
 * Turns on an LED on for half a second,
 * then off for half a second, repeatedly.
 */
#include "Arduino.h"

// Set LED_BUILTIN if it is not defined by Arduino framework
 #define LED_BUILTIN 12
 #define BLINK_SPEED 500
  
void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}
  
void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  
  // wait for a second
  delay(BLINK_SPEED);
  
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
  
   // wait for a second
  delay(BLINK_SPEED);
}

 

After you paste this code to your main.cpp file press the check button on the blue footer bar of PlatformIO, it will build your code and tell you if it found any mistakes.

Finally, connect the Arduino to your pc and wait for it to be recognized. After the set up has been successfully completed press the small Right Arrow button on the blue footer bar to Upload the code to the Arduino board and see the light.

 

Conclusion

That was it, the theory, the tech talk, the hardware assembly ,and the software development are all done! And you hold in your hands your very first Arduino project. Not much but it's a start and you don't have to be great to start but you have to start in order to be great.
You can now start developing your own ideas one step at a time. I am going to put out more of these tutorials and hopefully combine them and create megatron!!! I am kidding. But I am seriously thinking about creating a puzzle tutorial in the future. We'll see.

Till then get your grind on with some cool books about Arduino:

 

 


You can show your support by liking our Facebook Page ! Support our efforts on Ko-Fi ! And you can get in contact with us either by sending us a message on Facebook or via the e-mail on the footer of the Page!

Thanks again! Have a lovely day... Or night!

The ballast resistor is used to limit the current through the LED and to prevent that it burns.

Read more http://www.resistorguide.com/resistor-for-led/