[PDF] Mastering Arduino Programming - Free Book
[PDF] Mastering Arduino Programming - Free Book
Arduino Programming
A Quick Guide to Arduino Programming with Simple
Do it yourself Projects
Daniel Stone
Copyright
Daniel Stones
ChurchGate Publishing House
USA | UK | Canada
© Churchgate Publishing House 2020
Introduction
What Is Arduino?
Arduino is an open-source electronics creation platform, which is based on
free hardware and software. It is flexible and easy to use for creators and
developers. This platform allows the creation of different types of single-
board micro computers that can be used by the developer community for
different types of use.
To understand this concept, you are first going to have to understand the
concepts of free hardware and free software. Free hardware is the device
whose specifications and diagrams are publicly accessible so that anyone
can replicate them. This means that Arduino offers the bases so that any
other person or company can create their boards, being able to be different
between them but equally functional when starting from the same base.
Free software is computer programs whose code is accessible by anyone so
that anyone who wants can use and modify it. Arduino offers the Arduino
IDE (Integrated Development Environment) platform, which is a
programming environment with which anyone can create applications for
Arduino boards so that they can be given all kinds of utilities.
The project was born in 2003, when several students from the Institute of
Interactive Design of Ivrea, Italy, tried to facilitate the access and use of
electronics and programming. They did it so that electronics students would
have a cheaper alternative to the popular BASIC Stamps, plates that were
worth more than a hundred dollars at the time, and that not everyone could
afford it.
The result was Arduino, a board with all the necessary elements to connect
peripherals to the inputs and outputs of a microcontroller and which can be
programmed in Windows, macOS, and GNU / Linux. A project that
promotes 'learning by doing' philosophy, which means that the best way to
learn, is tinkering.
1. make robots
2. manage cameras
3. control motors
4. water your plants after some time
5. distribute kibble if your dog's bowl is empty,
6. know the temperature of your rooms
7. turn on or off a lamp according to a presence
8. automate a mailbox
9. retrieve consumption information via EDF remote computing
10. Make your alarm
Arduino boards can be found alone or sometimes sold in a pack like the
“Inventor” kit we had already mentioned here, which includes a whole
bunch of components allowing you to quickly start various projects, just to
familiarize yourself with this area.
CHAPTER ONE
Advantage
1. Arduino is “Open Source”. This means that you can take the original
drawing, modify it, and use it to produce the map and sell it without paying
copyright fees. "Open Source" has made it possible to quickly distribute
Arduino boards around the world to form a huge community that improves
and designs new boards that are always more efficient.
2. The price. As the scheme is free and you do not pay any duty on its use,
industries have taken the opportunity to produce the various cards. Some
respect the official diagram, as well as the components, originally
recommended which gives a price of around 20-25 Euros in Europe for the
most popular model, the UNO. Others produce it by using lower quality
components which allows them to lower the cost of the card enormously (it
is possible to have it for less than 10 Euros by looking well). They are
called clones. In terms of use, the clones and the official ones are very
similar whatever it is necessary with certain clones to carry out certain
technical manipulations to be able to program them, but the main difference
lies in the quality of the card. A little advice: if you want to start with
Arduino, invest in an official rather than a clone. It will save you a bad
experience and a waste of your time. You can take clones later when you
master the map.
3. The community. A community is very important in this kind of project.
This facilitates exchanges between users on different cards. There are many
forums and documentation online to help you use the map and overcome
any issues you may encounter.
4. Simplicity. Arduino rhymes with simplicity. The project was designed so
that beginners in electronics and programming can design prototypes very
quickly of what they have in mind. In a few hours of learning, you will be
able to design your prototype.
5. The multiplatform. To program an Arduino board and make it do what
you have in mind, you have to connect it to a computer and use the Arduino
IDE, the software allowing you to program all the Arduino boards. The IDE
is cross-platform by being available on Windows, Mac OSX, and Linux.
6. The “shields”. These are additional cards that connect directly and easily
to an Arduino card to increase its possibilities by adding for example a
GPS, an Ethernet or Wifi interface, an LCD screen, a sensor, etc. Of course,
it is possible to add its functionalities through components which have the
advantage of being less expensive but much more tedious to use.
7. No limit. To use an Arduino is to adopt it. You will have no limits in your
design projects on Arduino. Finally if only one: your imagination. For
example, many 3D printers work based on Arduino. This is particularly the
case with the BCN3D + which is powered by an Arduino Mega. You can do
all kinds of projects with this little card.
Projects you can do using Arduino :
A home automation project in Arduino
Arduino can allow you to prototype and complete many projects regardless
of your chosen field. Designing a connected object for home automation
has several advantages that the Arduino already has.
Chapter Two
Types of Arduino Boards
1. Arduino Uno
Arduino UNO Rev3 is the last revision that exists at the moment of this
board. It is a small electronic board with a programmable microcontroller
on its PCB. In addition to the said chip, it also includes a series of pins as
inputs and outputs that can be used by programming the chip to do different
things. In this way, electronic projects can be created very easily.
This board arises from the Arduino project, an Italian project started in 2005
that focused on developing open hardware and software for students mainly.
The first designs were directed at an institute in Ivrea, Italy. At that time the
students of this educational center used the famous BASIC Stamps that I
have already mentioned previously. These had a considerable cost, and they
weren't that open.
Before all that, Hernando Barragán had created a development platform
called Wiring, a project inspired by the famous Processing programming
language. With this as a basis, they went to work to develop low-cost and
simple tools for students. So they set about creating a hardware board with
a PCB and a simple microcontroller, as well as creating an IDE (Integrated
Development Environment).
As Wiring already used a board with an ATmega168 microcontroller, the
following developments followed in the same direction. Massimo Banzi
and David Mellis would add ATmega8 support for Wiring, which was even
cheaper than version 168. And so the first germ of what is now Arduino
UNO arises. The Wiring project was then renamed Arduino.
The name of the famous project originated in a bar in Ivrea, where the
founders of the project met. The bar was called Bar di Re Arduino, which in
turn was named after Arduino from Ivrea, king of Italy until 1014.
Given the potential of these plates, more support was added from the
community to move forward and create more plates. Additionally,
electronic component suppliers and manufacturers began designing specific
Arduino-compatible products. As is the case with Adafruit Industries. From
here arose numerous shields and additional modules for these plates.
Given the overwhelming success, the Arduino Foundation was also created,
to continue promoting and grouping the efforts of the Arduino project. A
similar model to other similar organizations such as the Linux Foundation,
the Raspberry Pi Foundation, RISC-V Foundation, etc.
As of this moment, many variants of Arduino have been generated, with
different form factors and diverse microcontrollers, as well as many
accessories:
1. 28BYJ-28
2. Gyroscope
3. ACS712
4. ESP8266
5. etc
Arduino UNO detailed information
This Arduino UNO board has some characteristics that make it unique, and
it has a series of differences concerning other Arduino boards that we are
going to highlight.
The pinout and technical characteristics of the Arduino UNO Rev3 board
are important to know how to use it properly; otherwise you will not know
the limits and the correct way to connect all the electronic components to
their available pins and buses.
Starting first with its characteristics, you have:
4. Arduino Leonardo
Arduino has several boards, several flavors with which to satisfy different
needs. One of the most popular development boards, along with the
Arduino UNO, is the Arduino Leonardo. This board with a programmable
microcontroller hides one of the most powerful features of the board line
when compared to one of its sisters.
Of course, this official board of the Arduino Foundation is compatible with
all the electronic components. This will give you the freedom to combine
the Leonardo plate with a multitude of components to create the most
varied projects you can imagine.
This Arduino Leonardo board has great similarities to the Uno, even in
appearance. But you should not confuse them, since there are notable
differences between the two.
Technical characteristics, scheme, and pinout
One of the main characteristics that you should know about Arduino
Leonardo is its pinout, that is, the pins or connections it has. As you can see
in the image above, it is not the same as the UNO Rev3 board. There are
some differences between the quantity, limits, and buses.
On the other hand, you should also know its technical characteristics, which
are summarized in:
1. 28BYJ-28
2. Gyroscope
3. ACS712
4. ESP8266
5. etc
Detailed information on Arduino Mega
Mega Pinout
Micro pinout
Pro Mini Pinout
The Arduino Mega board has everything you can find on the Arduino Uno
Rev3 board, but with some additions that make it more powerful, as I have
already mentioned.
Technical characteristics, scheme, and pinout
The technical characteristics of the Arduino Mega board that you should
know are:
In this image courtesy of Arduino, you can see the pinout or the
predisposition of pins and connections that you can find on this
development board. As you can see, Arduino Nano does not have as many I
/ O pins as its sisters, but it does have a considerable number for most
projects.
Differences with other Arduino Mini and Micro boards
Within the official Arduinos, you can find those versions that we have been
talking about in this section, such as UNO, Mega, etc. One more is this
Arduino Nano, which has the following differences that you have seen in
the previous sections.
However, to summarize the most prominent ones, these are the most
important concerning the other official reduced-size plates:
1. It was designed with the same goal as the Arduino Mini, only
that the Nano has a miniUSB port to program it and power it.
2. Its price is between the Arduino Mini and the Arduino Micro.
Compatibility
The Arduino Nano board is compatible with all kinds of electronic
components like the rest of the boards. There is no limitation of any kind
beyond its maximum current and voltage limitations.
5. Arduino Mini
This is a board microcontroller board developed by Arduino.cc and is based
on Atmega328. Performs almost the same functions with other Arduino
boards, however, it is different from the Arduino Uno in terms of the design
of the PCB, size, voltage regulation, and clock speed. The Arduino Uno
comes with two voltage regulators, that is to say, 5V and 3.3 V, while the
Arduino Pro Mini comes with a single voltage regulator. Arduino Pro mini
is widely available in two versions, the 5V, and 3.3 V to operate at 16MHz
and 32 MHz, respectively. However, you can get both versions as they are
available separately, with a single voltage regulator in comparison with the
Arduino Uno which comes with two voltage regulators, 5V and 3.3 V
which runs at 16 MHz. The Arduino boards play a vital role in the
development of integrated systems and other electronic projects. These
plates were developed to provide an easy combination of hardware and
software that give a fast way for people without technical knowledge to get
practical experience with the plates. These boards come with everything
you need to develop projects that have some connection with the
automation.
Technical Characteristics of the Arduino Pro Mini
1. GND . There is more than one pin built on the board that can be
used according to the needs when you need more pins of land for
the project.
2. TXD AND RDX. Also you can use these pins as a means of
serial communication. TXD represents the transmit data in the
series. RXD is used to receive the data.
3. AIN0 and AIN1. These pins are connected to the comparator
procedure.
4. VCC. This refers to the regulated voltage which one can easily
regulate to 5V or 3.3 V depending on the version of the board.
5. RAW . This pin is used to supply the voltage to the crude oil to
the board. Is connected to a power source not regulated that goes
from 5V to 12 V.
6. PWM . It features 6 digital pins labeled as 11, 10, 9, 6, 5, and 3.
These pins are specifically placed on the board to offer pulse
width modulation (PWM). This procedure is often used to create
results analog with digital resources.
7. RESET . The plate Pro Mini comes with a pin reset which is
very useful when the plate hangs while you are still running your
program. You can comfortably reset the board by making the pin
to appear low.
8. Head of programming. The head of the six pins of the FTDI is
connected in these pins and is used to program the board.
9. SPI . Represents the Interface Peripheral Serial that is primarily
used for the transmission of data between the microcontroller
and other peripherals such as sensors and records. For this
purpose, you can use four pins which include 13(SCK), 12
(MISO), 11 (MOSI), and 10(SS),.
10. Analog pins. A0-A7 are the descriptions used to label the 8
different analog pins that are present on the arduino board. With
a full resolution of up to 10 bits, you can use these pins to input
analog signals.
11. External switches. There are two switches available. They are
called T1 and T0 and they are referred to as external switches.
Hardware interrupts is also another term used to label these
switches.
12. I2C . A4 and A5 are used to develop the I2C communication. A4
is referred to as a line of serial data (SDA) that contains the data,
and A5 shows the clock line serial (SCL) which provides the
synchronization of data between the devices.
Differences with other Arduino boards
The most common thing with many of the Arduino boards is that they can
send the program from your computer to the board with the help of a USB
port present on them. However, in the case of the Arduino Pro Mini, all
USB circuits are removed to make them as little and compact as they
possibly can. Using a cable converter from USB to serial, you can also
program the board. The module serial USB FT232RL is very handy and
preferable to program this board. You can connect a head FTDI six-pin to
USB converter series that provides power to the USB.
If you've already worked on the Arduino One, then it is not necessary to buy
a converter cable USB to serial because you can program Pro Mini using
the plate One. Make sure that the version Pro Mini with which you are
working comes with an up-regulation of 5V it works at 16MHz as the
Arduino One. The programming board for the Pro Mini 3.3 V lacks
compatibility with the Arduino One. This makes programming of the 3.3V
version of the Pro Mini board to appear difficult.
Another huge distinction is the form factor and thus makes the board stand
out. Like we’ve mentioned a couple of time, the Arduino Pro Mini comes in
small and compact design. This also makes the board great for most
projects. Howeve, there is a limitation to its compact and small size. It is
not compatible with Arduino Shields unless you wire the board with
Arduino Shield.
1. Projects hobby.
2. Systems of energy supply.
3. Applications of IO.
4. Display systems.
Chapter 3
Arduino programming fundamentals
In the tech world, there is always a sense of uncertainty and you must learn
to live with it. There is a premise that you must apply when you are doing
an Arduino task. You have to be willing to assume that even if you don't
understand what you are doing, you must continue towards your goal.
You must be able to move forward, not get stuck in some concept. It doesn't
matter if you don't understand it, the important thing is to move on.
You will see how over time, what you did not understand will be seen more
clearly from another perspective.
The syntax of programming with Arduino
In this section, as in any other, I like to put analogies so that everyone can
understand. It is a way of explaining something in ordinary words so that
you can learn Arduino. Contrary to what it may seem, there is a close
relationship between the grammar and punctuation of a language and the
syntax of programming.
I like to say that if you can read and write, you can program. You are
probably familiar with punctuation and grammar. You will know what a
period, a comma, hyphens, accents, or semicolons are. In addition to all
this, a language has verb forms, nouns, and all kinds of grammar.
The goal of punctuation and grammar is that people can communicate
through the written word. We use the comma to pause, a period to end a
sentence, and the bold to emphasize.
In programming languages, the syntax is required to communicate with the
compiler. The same goes for a language, punctuation marks and grammar
are essential to understand each other.
The compiler will read that code and translate it into machine code for the
microcontroller to understand.
We can say that the compiler will be your high school language teacher. The
difference is that this teacher is the most demanding you have ever met
since he always requires a 10 in your programs :).
He won't let you pass a single one. It's not like writing an email to a friend
where it doesn't matter if you put an extra point or don't put an accent. The
compiler will always demand that you have everything perfect.
Don't worry if it costs you at first, it's normal. Little by little you will
understand what the compiler is telling you and where the errors are. I
assure you that if you show interest, it will become your second language
after your mother tongue.
Now we are going to see the most important particularities within the
syntax of programming with Arduino.
Comments in an Arduino program
The comments are nothing more than notes that the programmer leaves
within the code. It helps you understand part of that code. An important
notice. It is not about making a complete report on what something in the
code does, it is about putting something descriptive to help understand it. It
is a fundamental part when we are writing a program for Arduino. However,
it is not compiled, that is, it is not translated into machine code. Every time
the compiler encounters a comment, that line is skipped.
There are two ways to write a comment.
Semicolon
In the programming language C ++, the semicolon (;) is like a full stop.
Basically what it is saying is that we have finished a sentence and from that
moment, we start something new without relation to the previous at the
syntax level.
Surely it may not mean anything to you if you have never programmed
before. The compiler interprets that from that semicolon everything you
write will be a new statement, with nothing to do with the previous one.
At this point, we can do a test to see how the compiler works. Open a new
program in the Arduino IDE and copy the following code. You don't even
need to connect the board to your computer.
Now click on the verify button, it is the first shortcut in the editor. What
happened?
Let's analyze it to see how to solve it.
If you look at the message area, the error is very descriptive, “ expected ','
or ';' before void ”that is, we need to put a comma or a semicolon before the
word void.
In the console, it gives us even more information. It indicates the file where
the error has occurred (sketch_may29a you may have another name) and
the line where 4 has occurred.
Finally in the editor, we get a red stripe indicating the line where the error is
and where it is referenced in the console. Now change the code and put the
semicolon at the end of line 2 and you will see how it compiles.
As you can see, you are not alone. The compiler is very demanding but it
also helps us to correct errors.
Reserved words
Surely you have already copied and pasted some of those Arduino codes
that you find on the Internet. In doing so, you may have noticed some
words change the text color within the Arduino IDE.
They are words reserved by the C ++ language. Each of them has a specific
function and is reserved by the programming language. This means that we
cannot use those names to name a variable for example. There are more
keywords than we have seen. Little by little you will become familiar with
them as you need them. The important thing is that if it changes color in the
development IDE, it is a reserved word.
The functions in an Arduino program
Functions are one of the essential parts of a program. Although it seems
somewhat advanced for this Arduino guide.
A function is nothing more than a piece of code that is used frequently
within a program. The objective is to facilitate the use of this piece of code
and to make the program cleaner and more readable. Imagine that in a
program you are developing you need to know the area of a circle. You use
this operation in many places within the code. To calculate it you just have
to multiply pi by the square of the radius.
Now suppose you have to use this line of code many times in your program.
You may be interested in turning it into a function. Arduino incorporates a
lot of functions. They are quickly located in code because they change
color, like reserved words.
Now we are going to focus on syntax when calling a function. All function
calls begin with the name of the function itself. It is then followed by an
open parenthesis and if the function has parameters they would be included
below, separated by commas.
Finally, we close the parentheses and do not forget the semicolon indicates
that we have finished with the sentence. Also Parameters are information
that we pass to the function to do its job. In the example we have seen to
calculate the area of a circle, the function needs to know the radius. So we
pass it on as a parameter.
If the function does not accept parameters, it is necessary to put the
parentheses. And this is all you need to know, in principle, about functions.
Variables in an Arduino program
One of the most important concepts in programming is variables. I assure
you that when you understand how they work, you have one of the keys to
learning Arduino. A variable is nothing more than a programming tool that
helps us store and retrieve information in our programs. And when we talk
about information, what comes to mind? Well that is, memory :)
Using Arduino memory
I have already told you that we have to store two data: the current water
level and the maximum level that it has reached. So on this shelf; we are
going to reserve two holes for those two data.
For example, we select slot 1 for the current level and 5 for the maximum
level.
What we have done is change the value from 100 ml to 120 ml. Here is the
most powerful function of a variable: we can change the value of a variable
and the name remains the same since the variable only contains the
information.
We must stop for a moment and reflect on what we have just seen. What
this comes to say is that what we are changing is the content of the shelf
space but the name always remains.
The same is true for variables. You access the content of the variable and
modify it but the name is always the same. That is, the name does not refer
to the content that is inside, the name refers to the memory space that is
reserved for storing information. If you know the name of the variable, you
can put things inside that variable to later make use of that information.
Remember, the name refers to the location, not the content inside
Type of data
Declaration of variables
When I talk about declaring, what we are doing is creating a variable. To
declare a variable you will need two things: a name and a data type.
In C ++ you always put the data type first and then the name.
In the previous code, I have declared a variable of type integer (int) whose
name is switchstate. The int data type allows you to store whole numbers
between -32,768 and 32,767. This is called the range.
You do not need to memorize this information :). The word int is reserved
by the C ++ language and as we have seen before it changes color in the
Arduino IDE.
By the way, don't forget the semicolon at the end to indicate that you are
done with declaring the variable.
To name a variable you have to follow certain rules. I've been programming
for many years (more than 15 years) and I've seen everything.
Here are some basic rules that you have to follow to name a variable:
Boolean (boolean)
It is the type of data that occupies the least memory, 1-bit. The reserved
word in C ++ is boolean and can take two values or 1 or 0. I have put
several examples to explain one thing. First of all, 1 equals true and 0
equals false. On the other hand, this type of data is the only one that does
not comply with the rule when it goes out of its range. As we have seen
before, when we go from the top or the bottom we would start over. With a
Boolean type variable what happens is that whenever it is 0 it will be false
and otherwise it will always be true.
Character (char)
The last type of data that we are going to look at in this Arduino guide is the
character. It is represented by the char keyword in C ++ and uses 1 byte of
memory (8-bit). It allows us to specially store a letter. We are storing a letter
as if it were a number using ASCII. Thanks to a table where the
correspondence between letter and number comes, we can know what
character it is.
In an example, we see how we can assign a value to the variable of type
char in two ways. With the letter in single quotes ('') or with the ASCII
code.
And with this, we finish the basic data types in Arduino. They are not the
only ones but they are the most used and the ones that you will work with
the most, especially when learning Arduino.
Program Arduino with functions
I have already told you that functions are one of the most important parts of
an Arduino program. Although it seems somewhat advanced, it is what you
are going to face first in any Arduino course.
A program starts with two empty functions, setup () and loop (). The sooner
you face them, the sooner you will learn Arduino.
Where we check that this function can only return HIGH or LOW.
Ok, so far we've seen functions that take parameters but some functions
don't have any parameters. What this function does is calculate the
milliseconds that have elapsed since the Arduino board started executing
the program. It doesn't need any parameters. By itself, it knows what to do.
Returns the number of milliseconds that have elapsed in a long unsigned
integer as we can see in the language reference.
But we can also create our functions. Imagine that you create one that
allows us to turn on a light in the living room.
In this case, we do not pass any parameters and it does not return anything.
The important thing in this section is that the functions have something
more behind than the simple call. We can see it as if it were an iceberg. We
only see a part of the function but below there is much more information.
However, at first, you just have to know how to make function calls. Later
you will be able to program yours.
CHAPTER FOUR
Arduino IDE
What is Arduino IDE
The software that allows you to program your Arduino board is called IDE,
which stands for Integrated Development Environment. Indeed, this
application integrates the editing of programs, uploading to the Arduino
board, and several libraries. The IDE exists for all three operating systems
and this article shows you how to install it on your computer. As of the
publication date of this guide, the most recent version of the IDE is version
1.8.13.
Arduino IDE is a text editor and compiler to program and transfer the
content of the instructions to the Arduino board in your machine language.
The programming language used is processing. The Arduino IDE Software
consists of 3 main parts:
Windows
The IDE requires the presence of the Java Runtime Environment to
function. To find out which version of Java is installed on your computer,
you can visit this site: https://java.com/en/download/installed.jsp and
optionally install or update Java. The software is suitable for Windows XP
to Windows 10. If this is the first installation of the IDE on your computer,
we advise you to choose in the "Software" tab the option "Windows
Installer" which is an installable version; you just have to follow the various
steps and the drivers for the Arduino boards will also be installed. This
requires having administrator rights on the computer you are using.
Another possibility is the “Windows ZIP” option for those who are not
computer administrators. You will get the download of an “Arduino-1.8.13-
windows.zip” file that you save wherever you want; then you just have to
right-click "Extract all ..." to obtain an "Arduino-1.8.13" folder in which the
arduino.exe executable program is located (not to be confused with
arduino_debug). Create a shortcut to get the IDE icon on your desktop.
Please note, if the installation by Zip file makes it possible to coexist
several versions on the same machine, this is no longer possible with the
installer. If an older version is already present on your machine, you will
have to uninstall it before upgrading to the new one! On the other hand, an
installed version can very well coexist with one or more versions deployed
by the Zip file. For this reason, the installation by the ZIP file is interesting
if it is not the first installation and allows us to install a portable solution.
At the first launch, the IDE will create an 'Arduino' directory in your 'My
Documents' (or 'Documents' folder on Windows 10) which will contain
your future projects.
MacOS X
The file to download is a .zip archive. Once this archive is decompressed,
which is done automatically if your browser settings have not been
changed, the Arduino application icon is located in the download folder (the
desktop most often if it is Safari).
You get the Arduino app which you can put anywhere you want. We
recommend that you place it in the 'Applications' folder, and then add the
application icon to the Dock, to access it as easily as possible.
At the first launch, the program will ask you to accept the fact that you
downloaded this application from the web (and not from Apple which
securely protects its applications). Click on the 'Open' button. You will not
be asked the question again.
Then, the IDE will create an 'Arduino' directory in your 'Documents' folder
which will contain your future projects as well as the libraries that you will
add as and when you need it.
Warning! The Arduino 1.8.x application contains the Java 1.8 runtime. It
does not use the Java that you may or may not have installed in your Mac
previously. Sometimes it is desirable to keep the original Apple JRE 1.6 for
compatibility with other Mac OS X applications. So don't change anything
to Java in your Mac for the Arduino.
If you have used previous versions of Arduino and are having problems, we
recommend that you delete the old preferences which are in the folder:
/ Users //Library/Arduino15/preferences.txt And restart the Arduino
application again. If you have an older Mac that only supports an older OS
X system, you will find the Arduino version that is suitable for your Mac
and its systems.
GNU / Linux
Usually, Arduino can be found in various Linux distributions but you won't
have the latest version of the IDE. The best is therefore to download it from
the Arduino site, choosing the one that corresponds to your version of Linux
(32 or 64 bits). The installation steps can be a little different from one
distribution to another. The download retrieves a compressed archive
"Arduino-1.8.13-linux64.tar.xz" in the download directory "Downloads".
Right-click on this archive and then select “Extract here” (extract in this
directory). We then obtain an "Arduino-1.8.13" folder which includes a
"shell script" file called "install.sh" which will allow you to install the
Arduino IDE. From there, your best bet is to switch to Terminal mode. Go
to the "Downloads" directory by typing: cd downloads (+ Enter), then in the
same way in the "Arduino-1.8.13" directory by typing: cd Arduino-1.8.13
(+ Enter).
Once in this directory (where the script is located), type: ./install.sh (+
Enter). After a very short time, you will see that the operation has been
carried out (done!); you just have to type: ./arduino (+ Enter) to start the
Arduino IDE.
At the first launch, the IDE will create a 'sketchbook' directory in your
'home' which will contain your future projects.
Driver installation in Windows
The installation of the drivers is done at the same time as the installation of
the IDE and the original Arduino boards are generally well recognized as
soon as they are connected via USB. However, Arduino board clones can
use different electronic components which may require the installation of
additional drivers. This is particularly the case for clones that use a CH340
interface to communicate via USB.
Check after installation
Launch the freshly installed IDE. In the File menu, find the Blink program
given as an example (File -> Examples -> 01. Basic -> Blink). Connect
your Arduino board by USB to your computer. If your board is an Uno
board, you should read at the bottom right of the IDE "Arduino/Genuino
Uno on COM4" (Uno and 4 are examples). Before uploading this program
to your Uno card, check in the Tools that the type of card is indeed Uno and
that the port is COM4, otherwise change the options. Upload the program
and observe the LED flashing at a frequency of 2 Hz (one second on and
one second off). If this is the case, the IDE is perfectly installed and you
will be able to program your cards.
Arduino IDE Online (Arduino Create)
Arduino Create is an online tool that allows you to program any Arduino
board using a simple web browser (Chrome, Explorer, Firefox, etc.),
without the IDE having been installed on your computer. Arduino Create
also includes a storage space for your sketches, tutorials, a place to see
projects made by other users, tools to facilitate the realization of IoT
projects (Internet of Things), etc.
For this section, we’ll limit ourselves to signing up for the service and using
the Arduino Web Editor.
Signing up for Arduino Create
I hope this is only temporary, but signing up for Arduino Create seems
unnecessarily complicated to me: you need to request an email invitation to
be sent to you (which should reach you within 24 hours). ) before you can
do anything. No question, therefore, to start programming within minutes of
your registration: you must wait several hours.
You start by accessing the Arduino Create site.
You must first have an account on the Arduino.cc site. If you already have
one (for example, because you happen to participate in the discussion
forum), you are fine. Otherwise, click on the "SIGN IN" button at the top
right of the page.
You access the page that allows you to log in when you already have an
account. To create a new account, you click on "Sign Up". Fill out the form
choosing a username and password.
You will be presented with a very long text listing the conditions of use of
the site. You must of course click on the "AGREE" button.
Installing the plugin
Hopefully ( which isn't always the case ), you should now be offered the
option to download the plugin. The Arduino Web Editor allows you to
program the Arduino without having installed the IDE, but you still need to
install some files locally on your computer; otherwise you will be unable to
upload anything to your board. So click on the "NEXT" button, then on the
"DOWNLOAD PLUGIN" button
Find the installation file in your computers download directory (it is titled
"ArduinoCreateAgent-1.1-windows-installer") and run it (a few dialogs will
appear to let you confirm the installation of various components).
After a while, your web browser should confirm that the plugging has
indeed been detected. You must then restart the browser.
Using the Arduino Web Editor
So you can close Chrome, start it again, and then go to the Arduino Create
home page. Click on the "Arduino Web Editor" button and you are finally
in the online editor!
Not the same interface as the IDE, but you’ll be able to find your way
around anyway.
Plug a card into the USB port (a Chinese clone ... if it works with that, it
will work with anything!). Click on "- Select Board or Port -" at the top of
the screen, a list of available card models appear.
In the "Examples" section, select "Blink", click on the button which has the
shape of a right arrow. If it works, the LED integrated with the card starts
blinking.
Now for the serial monitor ("Serial Monitor" button). In this interface, the
serial monitor is displayed in the same window as everything else. You can
try writing a little sketch that displays increasing numbers in the serial
monitor: it works great too.
About libraries, click on the "Libraries" button to see that the usual libraries
are present. You will also see a button "ADD.ZIP LIBRARY" which should
allow installing specialized libraries in the same way as is done in the
conventional IDE.
CHAPER FIVE
Turning crazy or practical ideas into reality is something you can do with
the help of the Arduino and the many compatible boards and accessories.
And in a quite affordable way and with a DIY touch that ends up lifting
your spirits.
The limit is your imagination and the desire to learn because the Internet
takes care of the rest, as well as the Arduino accessories stores that flood the
network,
Here are few Arduino Projects You Can Try :
Photo booth for your wedding or social event
Putting a photocall and allowing guests of a social event to take photos is
fashionable. And there is a business around, as much as to cost about 600
euros to rent a booth to take photos.
With Arduino, a Dropbox account, and a webcam, you already have the
basis to build your photo booth. And if you enlarge it so that it can print the
photos that are taken instantly, success is assured.
Bubble making machine
A perfect example that, first and foremost, with Arduino is the imagination
of power. Who would want a machine to make bubbles automatically?
Surely who has a cat to piss off with this creation.
This does not mean that as a project with Arduino it is a little wonder and
something to show off without a doubt. And once with the base, there are no
limits to taking full advantage of a system where the protagonist is a robotic
arm.
Your automated garden
One of the advantages of Arduino is the modularity that it allows us.
Controller board and sensors that abound on the Internet and let your
imagination fly. With temperature, light and humidity sensors we can
configure an automated garden that is very attractive.
Back to the Future sneakers
It is not the most practical project that you are going to see in this selection,
but it is the one that you might like to carry out the most. If you've ever
dreamed of Back to the Future sneakers, Arduino lets you create them
yourself by adding motors. They are not very wearable but what the hell!
They tie themselves and that is more than enough.
An indicator jacket for cyclists
Leah Buechley created a version of a special Arduino board to implement
her idea: a jacket with lights to indicate the direction that we are going to
take to cars or other cyclists thanks to the movement of our arms. Its plate,
called LilyPad, is specially prepared to be sewn and integrated into
garments without making them uncomfortable.
Shutter for high-speed photography
Taking the perfect photo at high speed can also be done with the help of
Arduino. In this project, you will be able to build your self-timer to freeze
the action at the precise moment, which will determine a system that will
activate the camera at the time you have programmed it.
Home alarm
One of the most affordable and striking projects is the construction of a
home alarm. With the help of motion detectors and many lights and sound,
if we want, we can build our own, not very valid to protect the house but to
be alert in case our pet decides to invade a protected area of the house.
Your affordable Ambilight
After managing to implement a basic Ambilight system a few years ago, the
creator of this project has updated the system to get from the hand of
Arduino a more faithful response to the home lighting system. Analyzing
and detecting color changes in the source, mainly software that acts as a
multimedia center on a computer, we can get a system that is quite faithful
to the original Philips. And all for about $60.
A spy camera
It is not very discreet but it can strain. And whether you use it as a spy or
not, just getting to work to create this coffee cup with a camera is already an
adventure that you will surely enjoy. And quite a challenge to be able to fit
the components in such a small space.
The spy camera uses an accelerometer module that detects when we turn a
part of the coffee glass to activate the shot and voila, a photo without
anyone (almost) noticing.
Intruder alarm in Minecraft
In Minecraft you cannot get lost or when you return to your favorite server,
someone will have entered your territory. So that you find out if that
happens there is a project that uses the Spark Core board and its WiFi
connectivity.
With the ComputerCraft mod, we can generate a warning in the game when
someone enters our territory and a "real" alarm is generated.
Build an Infrared Shooting Arcade
If you can finish it and make it work, this is one of those projects that all
your visitors should see. It is a fairground attraction where you make even
the gun with the help of LED lights. The rest of the elements allow you to
unleash your imagination and show how far you can go. Oh, and of course,
it’s an Open Source project.
Notification of a new email
Although there are already commercial solutions that do it (the combination
of IF and Philips HUE, for example), in this selection, you can try to make
yourself a system that visually or audibly indicates the arrival of a new
email to your account on the computer.
With the ubiquitous Arduino board, in this case the most basic one serves
us, a USB connection with the computer and two small programs (one to
check the incoming email and the other to activate the notification), you can
create a new email notification system that can be made up of a simple
LED, a speaker or whatever you want.
If this luminous cube falls short and you want something cooler for your
desk, the next level is to have a robot that raises its hand every time you
receive that long-awaited email.
Arduino Microcontroller Process Automation Example
Automation in modern society is a necessary measure because in the digital
age, it is extremely important to exclude the human factor in various
industries to standardize and improve the quality of products. There are
some areas where people simply cannot control what robots are capable of
producing, for example, nanomaterials and chips.
However, not only does automation help production, but it also helps the
layman. For example, automating an Arduino brewery can make the
production process much easier. Let's see how automating rectification on
Arduino and other things can help, and consider some examples.
The main advantages of automated systems based on the Arduino
microcontroller
Nobody forbids you to solder your board and program it yourself using
low-level languages. However, automation on Arduino and finished
microcontrollers will make the whole process much easier and save time.
After all, it is much easier to buy an already finished product with a set of
libraries and adapt it to your tasks. And the affordable automation of the
Arduino Mega 2560 can be useful in many areas of life, from voice
switches for a smart home to the electric devil with a motion sensor. The
main advantages of Arduino automation are famous:
1. Opening procedure.
2. Customer service procedure.
The two procedures are in the restaurant so that employees know what to do
at those times.
The opening procedure tells the worker what to do when the restaurant
opens. For example, raise the lock, open the doors, put the open sign,
remove the ingredients, etc … This procedure is only done once a day when
the restaurant opens. Once finished, it is put on the shelf for the next time
the restaurant opens.
The second procedure indicates what an employee has to do when a new
customer arrives at the restaurant. It is an enumeration of steps.
For example, ask how many they are, find a free table, take note of the
drink, take note of the food, etc … Therefore an employee will resort to the
opening procedure once a day, and the customer service procedure each
time a new customer comes to.
Right now you are thinking, what does a restaurant have to do with
Arduino? Well, now you'll see, but an Arduino program has to do similar
things to what is done in this restaurant.
The setup function
In an Arduino program, some things only have to be done once. Things like:
The setup function is the first thing that runs when we launch the Arduino
program. Once the setup function is executed, the program will go line by
line executing each one of them.
The most important thing about this function is that it ONLY RUNS ONCE.
This is very important; the code between those two braces will only be
executed once.
It is like the employee who opens the restaurant, looks for the opening
procedure, follows it strictly and once he has finished saves it and goes on
to the next procedure.
The loop function
In an Arduino program, the next thing that runs after the setup function is
the loop function. Its meaning is repetition and the function resembles the
setup function.
It does not require any arguments but has the opening and closing
parentheses. It does not return any value so it has the word void on the left.
Next, you have the opening and closing curly braces ({}). As with the setup
function, when the loop function is executed, it runs line by line.
The big difference between the setup function and the loop is that when all
the code in the loop function is executed, the program returns to the
beginning and executes everything again. Get into an endless loop over and
over again.
It is the same as in the restaurant with the customer service procedure.
When the first customer arrives, all the tasks are executed to serve him.
Then another client comes and the same tasks are executed again, like this
indefinitely.
One of the most common questions is how fast does this function run? This
is determined by each microcontroller. In the case of Arduino UNO, the
microcontroller it uses is the ATmega328P and it has a speed of 20MHz
(megahertz).
This equates to 20,000,000 instructions per second. Yes, you read that right,
20 million :). This is not to say that there are 20 million lines of code. I
remind you that the code that you write is then translated into machine
code.
Each line of code that you write can be translated into multiple instructions
but even so, if we have 1,000 instructions it would take 0.00005 seconds.
Can you imagine how fast it goes?
However, the restaurant analogy does not fit perfectly with the loop
function. The employee will always wait for a new client to arrive to start
the procedure. This does not happen in the loop function.
In the Arduino program, whenever the last line of code in the loop function
is reached, it will go back to the beginning to rerun everything. It is not
waiting for any external input to do it.
CHAPTER SIX
More Projects to Try
DIY Thermal Image
Introduction
How to take thermal photographs? This small inexpensive assembly
compared to the price of a camera dedicated to thermal photography, is
based on the technique of "light painting".
Step 1 - The assembly
Carry out the assembly as described.
Upload the attached program to your Arduino. To have visible results, i.e.
blue colors for cold areas and red for hot areas, with good contrast, take
measurements on your wall or object to have an order of magnitude of the
temperatures to be detected.
Once the assembly is done, tape the infrared temperature sensor well
parallel to the RGB led.
Check with your hand in front of the sensor that the LED changes color, if
this is not the case, control your assembly and/or modify the high and low-
temperature parameters.
Step 3 - Adjusting the SLR Camera
Set your camera to Manual mode, then the aperture to F7.1 and the
exposure time of 30 seconds ISO sensitivity 200
For firefighters
Search for victims during apartment fires and especially in large
volumes such as underground car parks, factories, storage halls,
forest fires, etc.
And this is it, we already have our Bluetooth control unit working.
Arduino Face Recognition and tracking system
Recently, as face recognition technology has developed a lot, many
technologies apply face recognition technology. One of them is a
technology called Face-Tracking that tracks faces and is widely used in
CCTV. This is because a CCTV capable of Face-Tracking can efficiently
show more ranges than a non-moving CCTV and can accurately capture a
face on the screen. It would be more meaningful to implement Face-
Tracking technology, which is applied in this way, and make it more
meaningful if you make a robot that does not have a rigid camera and
makes it look like a person.
1. Materials needed
Arduino board, Brad board, 2 servo motors, 2 brackets
What is a servo motor?
Servo motor is a motor that has three connection parts, one is GND
(ground), the other is 5V, and the other is used as a wire to receive the input
signal, and turns the motor in a specific direction as much as the input
value. Here, it is used to rotate the camera by connecting to the camera and
receiving the signal value from the Arduino.
What is a bracket?
To follow the connection face of the servo motor and webcam, you need to
attach a bracket to the servo motor and make a shape that attaches the
camera to the bracket. At this time, since the face moves on the screen of
the camera, you need to control both the x-axis and y-axis directions. So,
two servo motors are used, one for the x-axis and one for the y-axis. The
bracket and servo motor were connected with screws, and the bracket and
camera were connected with a wire. <Connection part between bracket
and the servomotor><Connection part between bracket and camera>
3. Code
The role of the software is to recognize the face from the image value input
through the camera, calculate the value of the motor that the camera should
rotate through the coordinates of the face, and transmit it to the motor. It
uses three programs: Processing, Arduino, and Open CV. Open CV is a
program already known as a program that processes images. The processing
uses this program to find a face in the image, calculate the coordinates, and
send the motor value to be changed so that the face is centered on the
Arduino using serial communication. Arduino transmits the motor value
received from the processing to the connected servo motor.
Open CV installation and setup
First, you need to download the Open CV 1.0 version. http://opencv.org
Download version 1.0, not the latest version here. If you look at the
attached file, there will be 2 XML document files. These two XML
documents are the primary sources for face recognition. In other words,
Open CV accepts the information of the video and judges whether it
corresponds to the value in this XML document and determines whether it
is a face or not. There are many numbers written in the XML document. If
you have installed Open CV, you need to set environment variables and put
the Open CV file in the processing file of my computer.
Arduino software
4. Finished picture
5. Conclusion
In the implemented hardware, by connecting the head of the robot to the
webcam part and the body part to the servo motor part below, we created a
robot whose body remains still and only the head turns toward a person.
The webcam was inserted into the robot's mouth and fixed with scotch tape,
and the motor below was inserted by drilling a hole suitable for the size in
the body. The lower part of the torso has a wide plate for the center of
gravity. Also, we used an algorithm that continuously rotates a certain value
so that the face is in the center, but it did not appear to follow the face
quickly. However, if too many rotations were given, the face was shaken
back and forth when the face was still. So, I used P control in proportion to
the error of changing the motor value more as the coordinates of the face
and the center of the screen are different, and the video above is a video
using P control. I felt good because I used P control in my project from PID
control that I learned in school information class, and it was interesting and
interesting because it was a work with cameras.
Create Radio with arduino
Surely you have in your storage room some RC radio of a Chinese drone
that has stopped working, or simply a relative has given it to you because as
you are makers you can surely take advantage of it. Well, you are in luck, in
this section we are going to see how to modify and adapt an RC radio, take
the guts out of it and leave our Arduino with the nRF24L01.
Making an RC radio ourselves with Arduino and nRF24L01 offers us
several advantages and disadvantages that we will see throughout the entry.
However, I can tell you that to control small home robots it is more than
enough. Also, in the course of the project, we will learn to handle PWM
signals, the Arduino ADC, and many other things!
How does a radio control system work?
Generally, all radio control systems work in a very similar way. All are
based on emitting a radio frequency signal that contains the information of
the signals to be received. The old radios emitted in VHF (around 35Mhz)
and the only way to make sure that the signals did not collide in the air (and
thus avoid interference) was to use quartz crystals. These were placed on
the radio to analogically configure the exact broadcast frequency. With this
technology, if two stations were broadcasting on the same frequency, the
receiver would not know which signal to pay attention to and the dreaded
interference would occur.
At present, signals in the 2.4Ghz range are mainly used, the same signals
that your home Wi-Fi uses. Also, luckily, there are very cheap modules that
allow us to send and receive signals on this frequency. The advantage of
using this frequency range is that the bandwidths are higher, and more data
can be sent per second.
The nRF24L01 module
Also, being well known, it has libraries available for the Arduino IDE, so
the first tests and prototypes can be done very easily.
The RC radio with Arduino
The system that we are going to use is very simple, we connect the
nRF24L01 to the Arduino, and on the other hand, we connect the analog
and digital inputs that are connected to our buttons and control knobs. We
read these signals and send them through the radio link.
The main advantages are the high possible customization of the command,
as well as the data to be transmitted; and the possibility of implementing
return messages to have some telemetry. However, on the other hand, the
range is more limited than radios that are a little more professional, and the
reliability of the system depends a bit on the programming. Soif your
software crashes; the system will stop receiving data and stop acting.
Create LED Cubes With Arduino
Today the process of making a 3x3x3 LED cube with Arduino is shown,
highlighting the electronics and programming. I have watched some videos
where you have 8x8x8 cubes. In this case, to make it accessible to people
who also wish to do so, it has only been done with 9 LEDs on three levels.
In this project, you will see some concepts of basic electronics and Arduino.
Let's do it!
Level : Basic
Cost : money> 20 USD.
Materials :
1. 27 LEDs
2. 3 NPN transistors (2N3904 or also 2N2222)
3. 3 10 kΩ resistors
4. 9 220 Ω resistors
5. 1 Breadboard
6. 1 Arduino UNO
7. Connection cables (4 ft will suffice) or Arduino Jumper Wires
Step 1: creating the circuit
When buying materials, look to buy LEDs that have sufficiently long pins.
For everything else, no problem. The first stage consists of the construction
of the cube. For this, it is recommended to have a wooden board and make a
template where the LEDs will go when they are to be welded.
The area of this template will depend on the length of the longest leg of
your led. To open the holes, the use of a drill with a 5 mm bit is
recommended, which is more or less the diameter of the LEDs.
Since you have the template, the cathodes of the LEDs are bent. In this
project, we will work on each level as a common cathode. This means that
all the cathodes of each LED must be united and facing inwards.
There are three ways to identify which is the cathode:
Use some threads to hold the common point between the two LEDs to be
welded together. When you have finished soldering all the LEDs, and then
repeat this procedure three times.
The next thing is to connect the levels, one on top of the other. For this, we
will bend the anodes of the LEDs out a little, for when they are going to be
welded, there is no problem.
We would have something like this.
Now to connect the cube to the Arduino, we will need several components.
One of them is resistors. As the Arduino provides each of its digital outputs
with a voltage of 5 V, we cannot subject such a voltage to the LEDs. For
that, a resistor is used that will decrease the applied voltage allowing our
LEDs to not burn out. In this case, we use a value of 220 Ω.
Now, to make the LEDs turn on, we need to use the transistor in switching
mode, that is, the transistors change their region of operation: from cut-off
to saturation. So when the Arduino sends a small current (no more than 40
mA), the transistor activates in saturation causing the collector to "connect"
with the emitter directing the cathodes to the ground.
In this case, to operate the transistor, switching it is necessary to connect the
base of the transistor through a 10 kΩ resistor with the Arduino's digital
pins, while the collector will be connected to the cathodes of the cube, and
finally the emitter to ground.
Step 2: Creating the program
Conclusion
As I said in the introduction, this beginner’s guide to Arduino is designed
for people who want to understand what is behind Arduino. It is the first
contact with free hardware.
After this extensive tutorial, there would be a lot to do with programming,
but with this, you already have a good foundation to build on.
Learning Arduino, like any other discipline, requires prior effort. You have
to go through a learning curve. However, if you have a passion for
electronics and programming, it seems even fun.