Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 2 ■ INTERNET CONNECTIVITY


Once the wireless shield has been attached to Arduino, it should look similar to
Figure  2-5.


Figure 2-5. WiFi shield attached to the top of Arduino Uno


Code (Arduino)


Now that your Arduino is capable of connecting to a wireless network, you are going to
write the code that will allow your Arduino to send and receive data over the Internet.
Start your Arduino IDE and type the following code or download it from book’s site
and open it. All the code goes into a single source file ( *.ino ), but in order to make it easy
to understand and reuse, it has been divided into three sections.



  • External libraries

  • Internet connectivity (wireless)

  • Standard functions


External Libraries


The first section of the code, as provided in Listing 2-6 , includes all external libraries
required to run the code. Since you are connecting to the Internet wirelessly, the main
dependency of code is on <WiFi.h>. Your Arduino IDE should already have WiFi library
installed, but for any reason it is missing, you can download it from:




  • : https://github.com/arduino/Arduino/tree/
    master/libraries/WiFi

Free download pdf