Subtitles section Play video Print subtitles Hi everybody and welcome to another Arduino tutorial video supported by RS components. Today we are going to look at the Arduino WiFi shield It's a module that you can connect to your Arduino and that allows the Arduino board to connect to a WiFi 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 is a simple lamp that changes color depending on messages posted on twitter If somebody posts a twitter message that begins with the ashtag #ArduinoRGB and then followed by a color represented as a six digit hexadecimal number This is the way for example, that colors are represents in HTML pages. The six digits represents the amount of Red, Green and Blue that goes into the color. The first two digits represent the Red, the second two the green and the last two the blue So what the Arduino is going to do is to connect to twitter, launch a search and it will search for all the messages that contain this hashtag and once it finds one it will search for the number then decode the number into the 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 WiFi module mounted on top of it t and very simply, we took a small RGB LED and we connected three resistors The three resistors go to pin 3, 5 and 6 that are PWM pins So these pins are able to control the brightness of each individual channel in the RGB LED. The module that you see on the top here is the Arduino WiFi shield. The Arduino WiFi shield is actually quite an interesting device It's made by this large chip in the middle it's a 32 bit micro controller that contains the whole software needed to process the WiFi messages and connect to the internet and provide you with the whole network keys tag And it speaks to this little square module in the corner that is the wireless part that communicates with the WiFi network So, by using a powerful processor onboard of the shield we can save code space we can save memory on the main Arduino board. So, let's have a look at the code: In order to use the Arduino WiFi shield we include the WiFi WiFi library and then we have at the beginning, a couple of strings that represent the name of the wireless network we are connected to At this moment we are connected to a network that doesn't require a password so the next parameter will contain just the word "password that we are not going to use Then we have three pins pin_r, pin_g and pin_b These variables contain the number of the pins the LED is connected to. Then we have the constant maxTweets that indicates the amoun of tweets returned by a search I have to specify that most of the code you see here comes from an example that was written by Limor Fried for the Adafruit of things printer I took this code and I removed the part that prints to the actual printer and I replaced it with a a simple piece of code that parses the information There are other parameters that indicate the frequency used by Arduino to connect to twitter in this case we are connecting every ten seconds and the time out the maximum number of times we will try to connect to the server to connect to the server and the timeout - the maximum time we will wait for the response of the server. There are a number of internal parameters maybe too long to explain right now. So, we create a WiFi client we specify the server name, we specify the queryString - in this case "ArduinoRGB. We can skip the rest of the code so that I can show you how easy it is to connect to the WiFi Here we check if the WiFi is actually mounted on the board then we check it we are connected we just say WiFi.begin(ssid) If I need to specify a password I can put it here after this code as you can see in the comment and we can specify user ID and password. Then we wait for ten seconds That should be enough for a connection and this is going to try and retry to connect to the WiFi network until we connect. printWifiStatus will tell us: ok you are connected, this is your IP number this is the network you are connected to, etc Then during the loop what we are going to do is to create a connection to the server We are going to send a request this code I'm highlighting now is the one that sends the request to the server and then later on once the data - once the data has been received it says here "processing results..." We go to this function called jsonParse jsonParse() does quite a lot of work in processing the data that comes from the server and what is interesting for us is here. If the length of the message that we receive is less than 20 that means the message is short enough to be so I'm going to decode the color print out the values that we are going to send to the LED I'm using analogWrite to set the color of each channel of the LED Then we are going to print some more debugging information if we want to know if everything worked out. Then we are going to reset the time start so that we can check again in ten seconds. Here I am going to bring in the debugging message window. "Davide can you please send a tweet" Our friend Davide will send a tweet with a color - let's say FF0000, that represents the full red color. Now the tweet has been sent it is going to take a few seconds before twitter stores the tweet and makes it available in the search. At the moment you can see the log is just saying it is waiting for results there is no new results, pausing... at the moment it it connecting every 10 seconds. Ah! the message has been received and you can see that there was a message #ArduinoRGB FF0000 and our LED is now RED. Based on this code you can develop all sorts of other applications. This could be a lamp or for example a system to water 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 WiFi-enabled. Thank you for joining us and I hope you enjoy this project. And remember: build it, hack it and share it, because Arduino is you.
A2 wifi arduino connect server network connected Arduino Video Tutorial 10: Twitter-controlled Mood Lamp 48 2 Chuan Zhe Lin posted on 2013/05/20 More Share Save Report Video vocabulary