Vous êtes sur la page 1sur 24

LEDS

An LED (Light Emitting Diode) is an energy-efficient, reliable, and long-lasting lamp.


An LED is a type of diode that glows when current flows through it from the anode (+) to the
cathode (-).

Main characteristics

Voltage drop V F V

Rated current I A

Intensity (brightness) IV Cd

Wavelength (color) Nm

Typical wiring diagram

LEDs internal resistance after saturation is too low, and without a resistor that limits the
current flowing through the LED, the diode will burn out.
The place of the installation of the resistor in the circuit before or after the LED is not
important.

Finding the right resistor


Lets calculate which R-resistor in the circuit we will need to use to get the best results. Lets
imagine that we have the following LED and power supply unit:
V = 2.3 V
F
I = 20 mA
V =5V
CC

Lets calculate the optimal resistance of the R-resistor and the minimum permissible voltage
of the PR resistor. First, we will need to figure out the optimal voltage for the R-resistor:
U = V V = 5V 2.3 V = 2.7 V
R CC F

Using Ohms law, we shall calculate the resistance value that we will get thanks to this
voltage drop:
R = U /I = 2.7 V/0.02 A = 135
R

Thus:
With resistance more than 135 Ohm, the brightness will be lower than the initially
stated one.
With resistance less than 135 Ohm, LEDs life expectancy will be shorter.

Now we shall calculate the power that the resistor will be dissipating:
P = I * R = 0.02 A * 135 = 0.054 W
R
2 2

This means that if power is less than 54 megawatt, the resistor will burn out.

Simple rule
In order not to calculate values for the resistor during every experiment, you can simply
remember a rule for a most typical scenario.
To power 1 20 mA LED from 5 V, you need to use a 150 to 360 Ohm resistor.

Resistor
A resistor is basically an artificial "barrier" for the current, i.e. resistance in pure form.
Resistors limit the current, transforming part of the electricity into heat.

Main characteristics

Resistance rating R Ohm

Measurement accuracy tolerance %

Power P W

Color code of resistors


Marking resistor rating on its body with numbers is expensive and unpractical, since the
numbers always appear to be too small and unreadable. That is why resistance rating and
measurement accuracy tolerance are always marked with colored stripes.
Different series of resistors contain a different number of stripes, but the main decoding
principle is the same. The color of the body can be beige, light blue, white, or whatever it
does not matter. If you are not sure whether or not you have decoded resistor markings
correctly, you can double-check it with a multimeter.
Typical ratings for experiments

Practicum
A current-limiting resistor in the "Light Indicator" experiment
A resistor in a voltage divider and a photoresistor in the "Thereminvox" experiment
A pull-up resistor in the "Noisome piano" experiment

Switch
A tact switch is a simple and well-known mechanism to close the circuit while there is
pressure applied to the push button.
Switches with 4 contacts should be considered as 2 pairs of rails that are connected once
the push button is pressed.

The bounce effect

During the make/break between the plates of the button, there are sparks that trigger up to
ten switchings within a few milliseconds. This phenomenon is called bounce. It is
necessary to consider if you want to record the "clicks".

The wiring diagram


You must be thinking of a direct connection, but this wont be the best idea.

While the button is pressed, the output voltage Vout = Vcc, but while it is released, Vout 0.
The button and the wire in this case function as an antenna, and Vout will be getting some
random values depending on the noise in the system.

Diagram with a pull-down resistor

The switch is on: Vout = Vcc


The switch is off: Vout = 0

Diagram with a pull-up resistor

The switch is on: Vout = 0


The switch is off: Vout = Vcc

Practicum
Switches in the "Noisome piano" experiment
Switches in the "Mixer" experiment
Switches in the "Switch cowboys" experiment

Bipolar transistor
A transistor is an electronic switch. The button is pressed with a finger, whereas with a
transistor, a flow of current is applied. Transistors are used to control larger loads with weak
signals sent from the microcontroller.

The header that serves as a button is called the base.


While the flow of the electric current through the base is low, the transistor is open:

o A heavy current can flow into the collector


o And then flow out of the emitter

Main characteristics

Maximum voltage collector-emitter VCE V

Maximum current through the collector IC A


Gain ratio hfe

Typical wiring diagram

The transistor multiplies the maximum permissible current by h : fe

Example of calculation
If the control signal on the transistor base with h and a 1 kilohm resistor is 5 V:
fe

What will be the maximum current that can flow through the transistor?
What will the value of the drive current be?

Given
V =5V
B

R = 1 k
h = 50
fe

Find
I ,I
CE BE

Solution
I = V /R = 5V/1000 = 5*10 A
BE B
-3

I = I *h = 250*10 A
CE BE fe
-3

Conclusion
If the voltage of 5 V is applied to the base through a 1 kilohm resistor, the transistor will open
to such an extent that a current of 250 mA will be able to flow through it. In this case, the
drive current will only be 5 mA.

Practicum
Bipolar transistor in the Pulsar experiment
ADRINO UNO
Guide to choosing a development platform

So, you have a project idea, but you are not sure which board to choose that will serve as
the brain of your device? Let us help you decide.

If you just want to master circuitry, programming or Linux and you dont have any particular
purpose other than learning, the best option would be to pick one of the ready-made training
kits.

However, if you are already familiar with the subject and have a particular project to work on,
this guide will help you determine the right development platform and make an informed
choice.

Arduino or Raspberry Pi? A microcontroller or a microcomputer?

All development platforms can be divided into 2 categories:

Boards on the microcontroller Single-board computers


(MCU, MicroController Unit) (SoC, System on a Chip)

Typical board Arduino Uno Typical board - Raspberry Pi

Microcontrollers can simultaneously perform just one task, but they can perform it
impeccably. Single-board computers execute programs within their operating system (Linux
mostly). Besides, the latter have a higher productivity and more powerful multimedia
capabilities.

There are also hybrid platforms where the microcontroller and the processor are placed on
the same board. The idea is to leave all the hard work to the powerful processor, such as
access to the network or media processing. At the same time, the microcontroller is
assigned the function of fine motor control, as well as control of relays, sensors and other
peripherals. You can create hybrid platforms by yourself if you take a board from each
family. All of them will have common interfaces through which you can organize their
interaction.

You can find very specific boards in both families, which will stand out thanks to one single
feature. Nevertheless, the table below will help you compare the capabilities of average
microcontrollers and computers.

Microcontroller Single-board computer


Productivity 1 core, One or more cores,
tens to hundreds of MHz, hundreds to thousands of
tens of KB of RAM, MHz,
tens to hundreds of KB of ROM. hundreds of MB of RAM,
several GB of ROM.

Multitasking None. Can be emulated. Yes. Controlled by OS.


Convenience of
using the Internet
Usually some additional modules Easily connected from the
are required, as well as in-depth box, the network module is
knowledge of protocols. usually already on board.


Battery running
time
Up to tens of mA consumed. Hundreds to thousands of mA
Several weeks of battery running consumed. Large enough
time. battery power that can last up
to 10 hours.


Reaction rate in the
time-critical
projects 100% control over the time and Some critical processes might
the duration of signaling. be run later than they should
due to multitasking.


Choice of
programming
languages Limited. Python, JavaScript, Bash, and
Most often it is C/C ++. dozens of others available in
the OS


Possibilities to
work with video and
computer vision Not enough power. OpenCV, hardware video
codecs, HDMI-output.


Possibilities to
work with the
sound Sound synthesis is possible on Supports MP3/OGG/WAV at
powerful microcontrollers. To the OS level. HDMI audio
work with MP3/OGG WAV, output and/or a 3.5 mm jack.
additional modules are needed.

Thus, depending on your objectives, you determine whether you need a microcontroller or a
computer. How to decide what kind of board is best suitable for you?
Since there is not much point in comparing microcontrollers and microcomputers in detail,
we shall separately list the advantages and disadvantages of specific boards within their
families.

Comparison of microcontrollers

If we consider the microcontroller board apart from the goals of your project, it is difficult to
describe objectively and in a few words the advantages and disadvantages of different
platforms. Common disadvantages can play little role in your project or even turn out to be
great advantages.

We have tried to compare the boards basing our comparison on the capacity of the DIY
flagship Arduino Uno platform, since the boards of this particular family have given an
incredible kick in the development of hobby electronics worldwide. Various companies
produce modules, sensors, extensions with Arduino compatible or Designed for Arduino
shields, etc. Behind it stays an electronic and software compatibility primarily with Arduino
Uno, and only then with the rest of the platforms.

Generally, using tricks or additional components can help you connect anything to anything.
However, you want to focus on your project rather than on your fight with electronics, dont
you? Therefore, the most sensible idea is to compare any board on the microcontroller with
Arduino Uno. So lets do it.

Arduino Uno

A 16 MHz processor, 32 KB ROM and 2KB RAM, 20 input-output ports, 6 analog


inputs, 6 PWM channels, and 2 hardware interrupts may not be impressive, but
without the support of the operating system and the interpreters, they allow to solve
almost any problem of controlling a variety of sensors and actuators. It will help you
deal with piles of documentation, lessons and libraries.
Arduino Uno represents a huge community and allows to easily master the Arduino
IDE environment with Arduino C ++ used as its major programming language. All
these features will make the process of your familiarizing with the platform much
simpler.
The voltage of 5 V, which is the de facto standard, and pads for installing expansion
cards, as well as analog inputs and all kinds of hardware interfaces will allow you to
connect almost any peripherals, sensors and actuators.

Arduino Leonardo

Its the same as Arduino Uno, but it has a different microcontroller, which is of the
same class and has some advantages over its Arduino Uno analog.
Arduino Leonardo has a larger number of analog inputs (12 vs. 6) for sensors, more
PWM channels (7 vs. 6), more pins with hardware interrupts (5 vs. 2), as well as
separate independent serial-interfaces for USB and UART.
Arduino Leonardo can act as a keyboard or a mouse (HID-device) for your computer.
This makes it easier to create your own input device.
The pinout is slightly different from Arduino Uno, which may cause possible
incompatibility with some expansion cards. However, such cases are rare, and in our
shop, we explicitly specify them.

Iskra Neo

Its the same as Arduino Leonardo, but is produced in Russia.


Its significantly cheaper than its original analog.

Arduino Mini

Its the same as Arduino Uno, but of a different form factor.


A space saver measuring only 3018 mm.
Because of its form factor, its not that easy to install Arduino expansion cards on it.
Connection with additional modules is performed with the help of wires or through the
breadboard.
There is no USB port included, so you will have to upgrade the firmware with a
separate USB-Serial adapter.

Iskra Mini

Its the same as Arduino Mini, but is produced in Russia.


Its significantly cheaper than its original analog.
You can get it with unsoldered pads and sealed holes.

Arduino Micro

Its the same as Arduino Leonardo, but of a different form factor.


A space saver measuring only 4818 mm.
Because of its form factor, its not that easy to install Arduino expansion cards on it.
Connection with additional modules is performed with the help of wires or through the
breadboard.

Arduino Mega
Its the same as Arduino Uno, but it contains a more powerful microcontroller of the
same architecture. Excellent choice for more serious projects or if your Arduino Uno
is no longer capable of performing more complex tasks.
It contains significantly more memory: 256 KB of ROM and 8 KB of RAM, as well as
more ports: 60, of which 16 are analog and 15 with PWM.
Its also a bit longer than Arduino Uno: 101 53 mm vs. 69 x 53 mm.

Arduino Due

One of the most powerful boards from Arduino with a Cortex-M3 microcontroller and
the form factor similar to Arduino Mega.
84 MHz processor and 512 KB of memory. 66 IO pins, 12 of which can serve as
analog inputs, 12 support PWM and all 66 can be configured as hardware interrupts.
Inbuilt CAN bus controller allows you to create a network with the help of Due or
interact with in-car electronics. Two DAC channels allow you to synthesize the stereo
sound with a resolution of 4.88 Hz.
The optimal voltage for the board is 3.3 V, rather than the traditional 5 V. Make sure
that the selected peripherals support the work on this level or try installing a voltage
converter.

Iskra JS

A board with an Espruino core programmed in JavaScript.


JavaScript a high-level language. Programs are easier to write, since they are more
compact and more informative, especially if we are taking about string operations,
large amounts of data and the web interface.
Powerful 168 MHz Cortex M4 microcontroller, 1 MB of Flash memory, 192 KB of
RAM, dozens of ports with PWM and analog inputs, 2 analog outputs, several ICs,
SPIs , and UARTs - all this allows us to connect and work simultaneously with a
variety of sensors and modules.
Although the optimal voltage for the board is 3.3 V, the pins are also tolerant to 5 V,
and the connection of 5 V peripherals is trivial.
There may be no existing library for the selected peripherals due to a different
ecosystem and development environment, so you will need to create it on your own.
Strela

This "all in one" robotic platform contains the majority of the things that are necessary
to create any light mobile robot. Strela, like any other Arduino, is programmed from
Arduino IDE, and it contains the same microcontroller as Arduino Leonardo.
Inbuilt driver for two motors, 4 jacks for servomotors, 4 switches and 4 LEDs that can
be used for any purposes, a buzzer, slots for an LCD screen and a wi-fi module.
A powerful power regulator allows to easily use several different batteries.
11 inputs and outputs appear as 3 contact pins for connection of additional sensors
and modules. The LCD, the switches and the LEDs are connected through the port
replicator, so they do not take any of the general purpose inputs and outputs.
There are no pads on the board to install Arduino expansion cards.
Since the pin numbering has been modified (as compared to Arduino Leonardo),
slightly different functions should be used to work with the board pins.

Arduino Yn

Unique hybrid of Arduino Leonardo and a microcomputer running on OpenWRT


Linux. An excellent choice for the IoT.
The board is equipped with Ethernet and WiFi, through which you can communicate
with the device and even jailbreak it remotely.
The power of Linux allows working with the multimedia, and its network capabilities
easily integrate with social networks and other web services.
OpenWRT is a cut Linux. However, you cannot install any of the Linux software on
the microcomputer. Only Bash and Python from the coding box software can be used
as script codes.

STM32 Nucleo F401RE

A board with a powerful Cortex-M4 microcontroller. The platform is programmed not


via Arduino IDE, but via the mbed.org online environment. Subjectively, it is thinner
and more powerful than Arduino IDE, although not as widely used. Itll be a great
choice for an inquisitive mind.
A 84 MHz processor, 512 KB of ROM and 96 KB of RAM, 50 input-output ports, of
which 16 are analog and 29 with PWM. Although the optimal voltage for the board is
3 V, there should be no problem of compatibility with Arduino peripherals.
The pads for expansion cards are the same in configuration as the pads for Arduino
Uno, therefore a lot of Arduino expansion cards can be installed on Nucleo.
There is no separate SPI port on the board. You will have to use special tricks to
make Arduino expansion cards work with SPI through the ICSP port.
There may be no existing library for the selected peripherals due to a different
ecosystem and development environment, so you will need to create it on your own.

Teensy 3.2

A compact board with a powerful Cortex-M4 microcontroller. The platform is


programmed via the usual Arduino IDE.
Smaller than Arduino Micro (35 17 mm), but almost as powerful as Nucleo: a 72
MHz processor, 256 KB of ROM and 64 KB of RAM, 34 input-output ports, of which
21 can be analog, and 12 support PWM.
Teensy 3.1 is very energy efficient. It does not have a voltage regulator, but the input
voltage can be any from 3.3 V to 5.5 V. The same voltage will be its data level. In
sleep mode, it consumes only 0.25 mA, which makes it possible to operate on battery
power for several months.
Inbuilt CAN bus controller allows you to create a network with the help of Due or
interact with in-car electronics. Two DAC channels allow you to synthesize the stereo
sound with a resolution of 4.88 Hz.
The board comes with unsoldered contacts. You will have to solder pin connectors or
wires on your own.
Because of a large difference in the architecture with classic Arduino, not all third-
party libraries for peripherals may work out of the box.
The operating voltage is equal to the input voltage, which is why it often changes as
the batteries discharge. This can be important when choosing a peripheral, especially
if it is designed for a specific voltage.
Netduino 2

The board follows the form factor of Arduino Uno, but has a powerful stuffing
sufficient for the execution of programs written in .NET. Netduino is programmed in
C# or any other .NET-language in the Visual Studio environment familiar to any
.NET-developer. .NET Micro Framework is provided with a standard library.
Autocomplete, tips, context help in MSDN and a full debugger all function in Visual
Studio. Breakpoints are available to you, as well as step-by-step execution of the
code and monitoring variables. Debugging is simple and does not involve any tricks,
you just need to connect a USB-cable. Thanks to all this, the speed of development
for Netduino at times exceeds the speed of development for any other platform.
There is no separate SPI port on the board. You will have to use special tricks to
make Arduino expansion cards work with SPI through the ICSP port.
There may be no existing library for the selected peripherals due to a different
ecosystem and development environment, so you will need to create it on your own.
Netduino Plus 2

The same as Netduino, but more powerful and with Ethernet. An excellent choice for
IoT projects.
It has the same drawbacks as Netduino 2.
Comparison of single-board computers
A trendsetter among the SBC is Raspberry Pi. This super popular platform once completely
changed the idea of the capabilities, size and cost of a full-fledged computer for DIY-
electronics.

Again, different SBCs may be suitable for a particular project, but due to the popularity of
Raspberry Pi, we will be comparing other platforms with it.
Raspberry Pi 3 Model B

One of the most popular SBCs. Four 1200 MHz cores, 1GB of RAM and full-fledged
Linux based on Debian will help you solve many problems concerning computing
power. Among them, we can name computer vision, real-time sound processing and
the creation of web services.
It will help you deal with piles of documentation, lessons and libraries. Raspberry
represents a huge community. All these features will make the process of your
familiarizing with the platform much simpler.
The usual HDMI ports, 3.5mm audio, and 4 USB ports will help you easily connect a
monitor, speakers, a keyboard, a mouse, and other USB devices. BLE and WiFi
modules will help you perform a wireless connection of your computer to other
devices.
There is no ADC on the board, so the connection of analog sensors is only possible
with the help of external additional components.
There is only 1 hardware PWM channel available, which complicates the work with
the periphery controlled by PWM.

BeagleBone Black
A microcomputer similar to Raspberry Pi, which gives benefits that microcontroller
boards usually have. A great choice for IoT projects that need to be managed with a
variety of sensors and actuators.
A powerful environment for Cloud9 IDE development. You simply access
BeagleBone through your web browser and start programming in your favorite
programming language, be that Python, JavaScript (Node.js), Bash, or any other
Linux language. The result can be checked immediately and if something does not
work, you can use the inbuilt full-fledged debugger.
There is already 4 GB eMMC Flash memory installed together with the Linux
operating system. Memory can be increased with an external microSD card. A lot of
opportunities for connecting peripherals.
8 PWM outputs and 7 analog inputs. Hardware interrupts are possible.
A microHDMI port to connect a monitor, which is rather unusual. It is also used to
transmit sound.
Computational performance is lower than that of Raspberry Pi: there is 1 400 MHz
core and 512 MB of RAM.

Arduino installation and setup in


Windows
You have become a proud owner of an Arduino board. What to do next? Next, you need to
make sure that your Arduino is compatible with your computer. Lets try and see how
Arduino Uno works with the Windows operating system.

1. Arduino IDE installation

First, you need to install IDE Arduino on your computer.


Download Arduino IDE 1.6.3
This is a stable version of Arduino LLC.
There may appear a sign informing us of an unlicensed board because of the fact that
Arduino LLC and Arduino SRL are usually at odds with each other.
Installing Arduino IDE with an installer will secure you from most of the potential problems
with drivers and the software environment.

2. Running Arduino IDE


Once you have downloaded and installed Arduino IDE, let's run it.

We can see an Arduino IDE window. Please note that we still have not connected our
Arduino Uno board to the computer, but we already have the inscription Arduino Uno on
COM1 in the bottom right corner. In such a way, Arduino IDE informs us that it is ready to
work with the target Arduino Uno board. And when the time comes, Arduino IDE will be
searching for Arduino Uno on the COM1 port. Later we shall change these settings.
Something went wrong?
Arduino IDE does not start? Probably JRE (Java Runtime Environment) is incorrectly
installed on your computer. Make sure you refer to step (1) to reset Arduino IDE: the installer
will perform all the work on the deployment of JRE.

3. Connecting Arduino to your computer

After installing Arduino IDE, it's time to connect Arduino Uno to your computer.

Connect your Arduino Uno with the computer via a USB-cable. You will see how the ON
LED turns on and the L LED starts to blink. This means that the board is powered, and
Arduino Uno microcontroller has begun to run the threaded Blink program (the flashing
LED).
To configure Arduino IDE to work with Arduino Uno, we need to know which COM-port
number has been assigned to Arduino Uno by the computer. To do this, go to Windows
Device Manager and open the "Ports (COM & LPT) tab. We shall see number of COM-port.
(e.g. 7)
4. Setting Arduino IDE to work with Arduino Uno

Now we need to inform Arduino IDE, that the board with which it is about to communicate is
located on the COM7 COM-port.

For this purpose, we need to go to the "Tools" menu, then the Serial port" tab and then
select port "COM7". Now Arduino IDE knows that something is located on the COM7 port,
and that it will have to interact with this device soon.

So that there is no doubt left, you must explicitly state that you shall be using Arduino Uno.
To do this, go to the "Tools" menu, click on the Board tab and choose Arduino Uno.

Something went wrong?


The list of serial ports is empty? This means that Arduino Uno is connected the
wrong way. Make sure you get back to step (3) to fine-tune the connection.
Does Arduino IDE run incredibly slow when navigating through the menu? Disable all
peripheral devices in the Device Manager, like Bluetooth Serial. For instance, the
virtual device connected with your mobile phone via Bluetooth can cause such
behavior.

5. Downloading the first sketch

The environment is configured and the board is connected. Now you can proceed to
downloading the sketch.

Arduino IDE contains a lot of ready-made examples in which you can quickly look up for a
solution of any problem. There is also the simple Blink sample, which we shall pick for now.
We shall slightly modify the code to see the difference with the factory settings of the
flashing LED.
Instead of the line:
delay(1000);
We shall write:
delay(100);
The complete version of the code will be as follows:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.


*/

// Pin 13 has an LED connected on most Arduino boards.


// give it a name:
int led = 13;

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
}

Now the L LED should go on and off for one-tenth of a second. That is 10 times faster than
in the original version.
Lets upload our sketch in Arduino Uno and check whether this is so. After the upload, the
LED will blink more rapidly. This means that everything is going well. Now you can turn to
the "Experiments section.
Something went wrong?
After the upload, there is the following error: avrdude: stk500_get sync (): not in sync: resp =
0x00? This means that Arduino is not configured correctly. Go back to the preceding steps to
make sure that the device has been recognized by the operating system and that there are
correct settings installed in Arduino IDE for the COM-port and the board model.

Programming languages
So, you have a processor. You probably know that a processor can be programmed to do
what you want. In order for the processor to be productive, you need to (a) write a productive
program and (b) make sure the processor runs it.

In general, it does not matter what processor you have, be that the last Intel Pentium version
in your laptop or an Arduino microcontroller. The principles of writing programs, i.e. coding,
are the same in both cases. The only difference is in the speed and the number of
opportunities when interacting with other devices.

What is a program and where to write it


A processor despite the complexity of its production, in essence, is quite a simple thing. It
cannot think, but it can blindly execute the instructions that you give it. Here is an example of
a sequence of instructions:
Instruction What it means for the processor
byte

00001001 It means taking the next byte and storing it in cell 1

00000110 ... This is the next byte number 5, which we store in cell 1

00011001 It means that we subtract 1 from the value in cell 1 and place the result
there

00101001 It means that we need to compare the value in cell 1 with 0, and if it is
0, we need to skip the number of bytes indicated in the next byte
00000100 If the result is 0, we need to skip 4 bytes and return to the second-from-
last instruction

10000011 It means that we want to output the symbol whose code is written in the
next byte

01000001 This code corresponds to letter A

00101000 Its the same number of bytes that is mentioned in the next cell that we
need to backwind

00000110 We shall backwind 6 bytes to return to step 3

10000011 It means that we want to output the symbol whose code is written in the
next byte

00100001 This code corresponds to the ! symbol

If we run this sequence of instructions, the screen will display a phrase somewhat filled with
panic: "AAAA!".
This would be quite a lot of code for such a simple goal. It is obvious that if all the programs
were written this way, the development of complex products would take ages.
Why do we need programming languages
Programming languages were invented to simplify our work a million times. There are so
many of them, and you can quickly recall a dozen of those that you constantly encounter:
Assembler, C, C ++, C #, Java, Python, Ruby, PHP, Scala, and JavaScript.
Programs in these languages are much closer to natural human languages. Therefore, they
are easier, faster and more fun to write, and most importantly, they are much easier to read,
be that immediately after their creation or much later.
The problem is that these languages are not understood by the CPU and before you transmit
the language to the CPU, it needs to be compiled, i.e. translated from the natural language
to a set of instructions in the form of zeros and ones. This is performed by programs called
compilers. Every language, unless it has not been created yet, has its own compiler. For
popular languages, there are usually several to choose from, from different manufacturers
and for different platforms. Most of them are available in the Internet for free.
Thus, there are programs written in quite an understandable human language: they are
called "source code", or simply "source". They are written in simple text files using any text
editor, even notepad. Then they are translated into sets of zeros and ones by the compiler,
so that the processor would understand them. The compiler gets the source code at the
input and creates a binary executable file at the output, the one which the processor would
be able to understand and digest.
Binary files are not readable, and are, in general, made to be later executed by the
processor. They may all have a different type, depending on their purpose: .exe is a program
for Windows, .hex is a program for execution by a microcontroller such as Arduino, etc.
So why are there so many programming languages and what is the difference between all of
them?
Why? Because there are a lot of people and different companies in the world, and many
believe that they could do this better than anyone else, and that their languages would be
simpler, more comprehensible, faster, and finer.
What the difference is: different languages represent a different writing speed, readability
and execution speed.
Let's look at the same program, which displays the song about 99 beer bottles in different
programming languages.
For example, in the Perl language. It is written quickly; it is impossible to understand what
the programmer had in mind, and it is executed slowly.
The Java language: it is written for a relatively long time; it is quite readable; it is executed
fairly quickly, but it takes a lot of memory:
The Assembler language: it is written for a long time; it is difficult to read; it is executed very
quickly:
In what language is Arduino programmed?
If we talk about the Arduino microcontroller or about microcontrollers from the Atmel
company, what language can we use to write programs for them? Theoretically, any
language. However, in practice, the choice of languages is limited to Assembler, C and C
++. This is due to the fact that in comparison with a PC, they have very limited resources:
kilobytes of memory, rather than gigabytes; megahertz processors, rather than gigahertz.
This is how you pay for a relatively low cost and energy efficiency.
Therefore, we need a language that can be compiled and executed efficiently. It needs to be
translated from the instructions into zeros and ones in the most optimal way without wasting
the precious instructions and memory. The languages that we have mentioned have this
efficiency. Using them even within the narrow confines of the microcontroller resources will
help you write feature-rich programs that work fast.
Assembler, as you have noticed, is not the most simple and elegant language and, as a
result, the flagship language for Arduino is a C / C ++.
Many sources state that Arduino is programmed in the Arduino language, or sometimes the
names of Processing and Wiring appear. This statement is not quite correct. Arduino is
programmed in C / C ++, and the above-mentioned languages only serve as a convenient
"kit", which allows us to solve many common problems without reinventing the wheel each
time.
Why are C and C ++ mentioned in the same sentence? C ++ - is a superset of C. Every
program written in C is a valid program for C ++, but not vice versa. You can use both. Most
often, you will not even think about the language you are using when solving a problem.
Getting to the point: the first program
Let's write the first program for Arduino and make the board execute it. You need to create a
text file with the source code, compile it and transmit the binary file to the microcontroller on
the board.
Let's move step by step. First, lets write the source code. You can write it in Notepad or any
other editor. However, in order for the work to be convenient, there are the so-called
development environments (IDE: Integrated Development Environment). They provide as a
single tool a text editor with highlighting and tips, a compiler that starts when you press the
button, and many other pleasures. For Arduino, this environment bears the name of Arduino
IDE. It is available for free download on the official website.
Try installing the environment and running it. In the window that appears you will see that
most of the space has been assigned to the text editor. This is where you write your code.
The code in the world of Arduino is also sometimes called the sketch.
So let's write a sketch, which does nothing. That will be the least effective program in C ++,
which simply kills time.
We shall not yet focus on the meaning of the written code yet. Lets compile it first. To do
this, you need to find the Verify button in the toolbar of Arduino IDE. Click it, and after a few
seconds, the binary file will be ready. This will be announced by the inscription Done
compiling that will appear under the text editor.
As a result, we have a binary file with the .hex extension, which may be executed by the
microcontroller.
Now we need to transmit it to Arduino. This process is called booting, jailbreak or upload.
There is the Upload button on the toolbar to perform the upload in Arduino IDE. Connect
your Arduino to the computer via a USB cable, press the Upload button and after a few
moments, the program will be uploaded into Arduino. The program, which was there before,
will be erased.
The successful upload will be announced by the message Done Uploading.
If you try experience any difficulties with the upload, make sure that:
In the Tools menu Board, the port to which the Arduino is really connected has been
selected. You can take the USB cable out and connect it again in order to understand which
port appears and disappears: this will be your Arduino.
You have installed all the necessary drivers for Arduino. This is necessary for Windows, not
required for Linux and only needed for boards older than Arduino Duemilanove on MacOS.
Congratulations! You have gone all the way from a tabula rasa to a program running in
Arduino. In spite of the fact that it actually does nothing, it's already a success.

Components which appear in the


videos of the course "Building robots
and other devices on Arduino: from a
traffic light to a 3D-printer".
The items are assorted according to Amperka website. Before looking for an analogue, make
sure that the functional is the same. The components are available as part of the "Cyber
Physics" product line.

Arduino Uno Platform

Breadboard circuit Breadboard Half

220 ohm resistors

10k ohm resistors

Potentiometer

Photo resistor
Thermistor

Field transistor MOSFET

5mm LEDs, red

5mm LEDs, yellow

5mm LEDs, green

LED bar graph

7-segment indicator

Tact switch

Piezo tweeter

Output shift register 74HC595

Push terminal

Connection male-to-male wires

USB cable of A-B type

Troyka Shield

Potentiometer (Troyka module)

Buzzer (Troyka module)

Four digit display (Troyka module)

Force multiplier (Troyka module)

Light sensors (Troyka module)

Analog thermometer (Troyka module)

Switch (Troyka module)

Battery compartment 4AA

Micro servo motor FS90

Soil moisture sensor

Submersible pump with a tube


Ultrasonic distance sensor HC-SR04

2.1 mm power plug with a terminal block

Connection female-to-female wires

Potentiometer (Troyka module)

LED Piranha (white) (Troyka module)

Noise sensor (Troyka module)

Hall sensor (Troyka module)

Relay module (Troyka module)

Sharp IR distance sensor (4-30 cm)

Ethernet Shield

Twisted pair patch cable (0.5 m)

Multiservo Shield

Stepped motor driver (Troyka module)

Stepped motor 36HT20-0504MA

Motor shaft hubs ( 5 mm, a pair)

Bluetooth module HC-06

Motor Shield (2 channels, 2 A)

D-shaft wheels (3 mm)

Step-up voltage regulator (Troyka module)

Motor (12 mm)

Analog line sensor

Charging device SC200-4

Multimeter

Charging battery NiMH AA 2500 mAhrs

Vous aimerez peut-être aussi