hi everybody and welcome to another
Arduino tutorial videos supported by RS
Components
today we're gonna look at the Arduino
Wi-Fi shield it's a module that you can
connect to your Arduino that allows the
Arduino board to connect to a Wi-Fi
network and then connect to the Internet
and we can make all sorts of devices
using this tool today the example I'm
going to show you it's a simple lamp
that changes color depending on messages
that are posted on Twitter so if
somebody posts a Twitter message that
begins with the hashtag Arduino RGB and
then followed by a color represented as
a six digit hexadecimal number this is
the way for example that columns are
represented within HTML pages the six
digits represents the amount of red
green and blue that goes into the color
the first two digits represent the
amount of red the second two green and
the last two blue so what do you have do
we know is gonna do is going to connect
to Twitter launch a search and you will
search for all the messages that contain
this hashtag and once it finds one it
will actually go search for the number
and then it will basically take every
number decode it and turn it into an
amount of color that will be represented
on the RGB LED that you see here on the
circuit let's have a look at the circuit
here we have an Arduino Uno with a Wi-Fi
module mounted on top of it and then
very simply we took us small RGB LED and
we connected three resistor and the
three resistor go to pin 3 5 & 6
there are PWM pins so these pins are
able to control the brightness of each
individual channel in the RGB
so the module do you see on the top here
is the Arduino Wi-Fi shield the Arduino
Wi-Fi shield is actually a quite
interesting device it's made of this
large chip in the middle it's a 32 bit
microcontroller that contains the whole
software that's needed to process the
Wi-Fi messages and connect to the
internet and provide you with the whole
networking stack and it speaks to this
little square module in the corner that
one it's essentially the the wireless
part that communicates with the actual
Wi-Fi network so by using a powerful
processor on board of the shield we can
actually save code space we can save
memory on the main Arduino board so
let's have a look at the code so in
order to use the Arduino Wi-Fi shield we
include the Wi-Fi library and then we
have at the beginning a couple of
strings that represent the name of the
wireless network were connected to so at
this moment we're connected to a network
that doesn't require a password so when
it says that the next parameter contains
just the word password that we're not
going to use later then I have three
pins pin RG and B these these variables
they contain the the number of the pins
where the different LEDs are connected
to then this constant max tweets
indicates the amount of tweets returned
by a search I have to specify that most
of the code that you see here actually
comes from an example that was written
by Lamar freed for the Adafruit
internet-of-things printer and I took
this code and I removed the part that
prints to the actual printer and I
replaced it with a simple piece of code
that parses the information there's
another number of parameters that
indicate how many times
the the frequency used by the Arduino to
connect to Twitter so in this case for
example we're going we're connecting
every 10 seconds and the time outs or
the maximum time we will retry to
connect the server before we stop
connecting and the time outs or the
maximum time to wait from from data from
the server so there's a number of
internal parameters that are maybe too
long to explain right now so we create a
Wi-Fi client we specify the server name
we specify the query string in this case
Arduino RGB then I'm gonna skip this
rest of the code just to show you
quickly how easy it is to connect to the
Wi-Fi so here we check if the Wi-Fi
shield is actually mounted on the board
then we check if we're connected and
then we just basically say Wi-Fi dot
begin SSID if I need to specify a
password here after the comment you see
I can put comma pass and that will
specify SSID and password and now we
wait for 10 seconds and that should be
enough for a connection and this is
going to try and retry to connect to the
Wi-Fi network until were connected print
Wi-Fi status will tell us okay you're
connected this is your IP number this is
the net while you're connected to one of
the girls and then shooting the loop
what we're gonna do we're just gonna
create a connection to the server we're
gonna send a requester this code I'm
highlighting now is the one that sends
the request to the server
oops and then later on once the data has
been received
it says here are processing results so
we go to this function called JSON
parsing JSON parts does quite a lot of
work in processing the data that comes
from the server but what's interesting
for us is here basically I'm saying if
the length of the message that we
received it less than 20 it means that
the message is short enough to be the
hashtag plus the color so I'm going to
decode the color print out the values
I'm gonna send to the
led and I'm using analog right to set
the color of each channel of the LED and
then we're just gonna print some other
debugging information if we want to know
that everything worked out and then
we're gonna reset that timestamp so that
we can check in again ten seconds so
here I'm gonna bring in the the
debugging message
so if EE can you please send a Twitter
so we're gonna ask our friend Davide to
send a Twitter with a color maybe send
ff0000 so that represent the full red
color so now the tweet has been sent
it's gonna take us a few seconds before
Twitter stores the tweet and makes it
available in the searcher so at the
moment you can see the log is just
saying that it's a waiting for results
there's no new result posing at the
moment is connecting every 10 seconds so
a message has been received and you can
see that there was a message Arduino RGB
ff0000 and our LED it's now red so based
on this code you can develop all sorts
of other applications so this could not
be a lamp this could be for example the
watering your plants in the garden or
this could be the heating in your
mountain home or something like that so
we could attach almost anything to this
Arduino and make it Wi-Fi enabled so
thank you for joining us I hope you
enjoyed this project and remember build
it hack it and share it because Arduino
is you