ArduinoBlocks en
ArduinoBlocks en
rduinoincorporatesaledontheboardconnectedtopin13througharesistor.Thuswe
A
can make afirsttestoftheoperationoftheboardwithouthavingtoconnectanyother
component to the Arduino board.
Built-inLED equivalent circuit:
hefollowingprogrammaketheledconnectedtopin13blinkusingavariabletosetthe
T
delay time and using the “Led” block.
LED sequence
ewillconnect5ledstotheArduinoboardonpins2,3,4,5,6byconnectinga220Ω
W
resistor before the ledanode(longpin)andallthecathodesoftheleds(shortpin)will
be joined directly to GND.
ractice 3: odd and even
P
Switch on even leds and then odd leds after a while and start over again.
ractice 8:functions
P
Functions allow us to group blocks under a singlenameandtobeabletoexecuteall
the blocks simply by adding the block to call the function.
Definition of a function: Function calling:
reate a function “all off” to start switching off all the leds, another function for
C
“sequence 1”, another for “sequence 2” and one for “sequence 3”. In the main loop
execute 3 times the sequence 1, 4 times sequence 2 and 5 times sequence 3
continuously.
PWM outputs
ulse width modulation (also known as PWM) of a signal or power source is a
P
techniqueinwhichthedutycycleofaperiodic(cyclic)signalismodified,tocontrolthe
amount of energy sent to a load. With this technique we can control the intensity of
LEDs, speed of motors, etc.
This is the way Arduino generates a pseudo-analog signal on its outputs from digital
pulses to vary the energy that it sends through the relevant pin.
Charts of PWM from 0% to 100% of intensity Pins that allow PWM operation are marked with the symbol ~
The values that we can write to the pin using PWM are from 0 to 255 (from 0 to 100%):
ractice 9:Switching on a led in several steps ofintensity
P
Switching on a led in several steps of intensity.
Calculate the table with the values to write to the PWM output pin
ractice 10:Switching on and off a Led slowly
P
SwitchingonandoffaLedslowly:Thevaluesfrom0to255willbewrittenonpin3so
that theLEDilluminatesslowly.Whenreaching100%(255)theprocesswillbecarried
out in reverse until reaching 0.
Modify the delay value to speed up or slow down the process.
Example of connection of a common cathode RGB LED to pins 9~, 10~ and 11~:
e can control the RGB led in several different ways from ArduinoBlocks:
W
-Digital outputs (ON/OFF):
odisplaytheinformationreceivedonthePCandbeabletosenddatatotheArduino
T
the easiest is to use a serial terminal or serial console.
erialconsoleallowsdatatobesentfromthePCtotheArduinoboard.Andviceversa,
S
it allows to receive and visualise the data received from the Arduino board.
Analog inputs
rduino incorporates 6 pins that can function as analog inputs. Let's try how we can
A
read data from external sensors through them.
The analog inputs allow you to read the voltage that is applied to itasaninput.That
voltage may varybetween0and5v.Thevoltagevaluereadisconvertedtoanumeric
value between 0 and 1023.
The reading blocks of an analog input will return a value between 0...1023.
Input voltage Read value
0 V 0
2.5 V 512
5 V 1023
nother interesting block is“map”,whichallowschangingtherangeofthevalueread.
A
Forexample,ifIwanttochangetherangereadfrom0...1023to0..100Ican"map"itas
follows:
Relay
relay is an electromagnetic device. It works like a switch controlled by an electric
A
circuit in which, by means of a coil and an electromagnet, a set of one or more
contacts can open or close other independent circuit.
he connection of the relay will be made through a digitaloutput,sinceweonlyhave
T
two states ON/OFF (relay active or not).
The most common is to connect a relay module thatsimplifiestheconnectionsinceit
alreadyhasalltheelementsnecessaryfordirectconnectionoftherelaytoArduino.We
only have to connect 5V (VCC), GND and the signalrelayactivationinputthatwillbe
connected to the corresponding Arduino pin.
Ifweuseanordinaryrelay,connectoneofthepinsofthecoiltoGNDandtheotherpin
of the coil to the corresponding Arduino pin to control the relay.
ToactivatetherelayintheArduinoprogramwewillsimplyusetheinstructiontoactivate
the pin digitally connected to the relay module (ON/OFF)
Intheoutputsectionwehavearelaymodulethatinternallyperformsthesamefunction
as the “write digital” instruction,
These two instructions perform the same function: Activate the output of pin 2.
ractice 34: intermittent relay
P
Carry out an assembly with the relay module connected to pin 8, we will carry out a
program that activates and deactivates the relay in periods of a 1s.