IoT Arduino YUN Ambient Sensor Adafruit I/O MQTT

by masteruan in Circuits > Arduino

3888 Views, 6 Favorites, 0 Comments

IoT Arduino YUN Ambient Sensor Adafruit I/O MQTT

Adafruit IO MQTT Based.png
P7090002.JPG
P7090003.JPG
[0lab] Adafruit IO MQTT IoT Arduino YUN ambient sensors

This Instructables show how you can connect Arduino YUN to the Adafriot IO platform for sharing the DHT-11 sensor value, the photoresistor value, and also control the led onboard, a relay, and a PWM output. The PWM outpout can control the brightness of a light or the speed of a motor.

For use an Arduino YUN with this Instructables, you must be connected the Arduino YUN to your lan and then to internet. If Arduino not's connected to internet, the Instructables not work.

Sign Up on Adafruit IO

Schermata 2016-07-09 alle 15.51.31.png
Schermata 2016-07-09 alle 15.51.48.png

The MQTT protocol is the best method for IoT now. It's simple, it's a complete method to connect the objects to the cloud, to the internet. Adafruit Industries have created a library and platform to use that protocol with Arduino ESP and other hardware.
For sfruttare this platform you must subscribe to Adafruit IO service. Go to Adafruit IO (http://www.io.adafruit.com/). Then Sign Up for free. Then follow the instructions. After you can see the Dashboard and try the functioning of Adafruit IO. Now you can create a new Dashboard using the button "Create Dashboard". You must naming the Dashboard "Arduino". After we add the values to the dashboard.

Download the Software

Schermata 2016-07-09 alle 15.53.14.png
Schermata 2016-07-09 alle 15.53.55.png
Schermata 2016-07-09 alle 15.53.43.png

For uploading the code on Arduino YUN you can download the official Arduino IDE.
https://github.com/adafruit/Adafruit_IO_Arduino and install it manually, or Install the library by "Manage Library". To install the library by manual process: First quit the Arduino application. Then uncompress the ZIP file containing the library. For example, if you're installing a library called "ArduinoParty", uncompress ArduinoParty.zip. It should contain a folder called ArduinoParty, with files like ArduinoParty.cpp and ArduinoParty.h inside. (If the .cpp and .h files aren't in a folder, you'll need to create one. In this case, you'd make a folder called "ArduinoParty" and move into it all the files that were in the ZIP file, like ArduinoParty.cpp and ArduinoParty.h.)

Drag the ArduinoParty folder into this folder (your libraries folder). Under Windows, it will likely be called "My Documents\Arduino\libraries". For Mac users, it will likely be called "Documents/Arduino/libraries". On Linux, it will be the "libraries" folder in your sketchbook.

To install a new library into your Arduino IDE you can use the Library Manager (available from IDE version 1.6.2). Open the IDE and click to the "Sketch" menu and then Include Library > Manage Libraries.

Then the library manager will open and you will find a list of libraries that are already installed or ready for installation. In this example we will install the Bridge library. Scroll the list to find it, then select the version of the library you want to install. Sometimes only one version of the library is available. If the version selection menu does not appear, don't worry: it is normal. Finally click on install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed. Once it has finished, an Installed tag should appear next to the Bridge library. You can close the library manager.

Now you can see the library Adafruit MQTT on the Arduino IDE.

Connect the Sensor to Arduino YUN

url.gif
LDR1-1-620x436.png

For use Arduino YUN with this Instructables, you must be connected the Arduino YUN to your lan and then to internet. If Arduino not's connected to internet, the Instructables not work.

Connect The photoresistor like in photo. Connect the photoresistor to input pin A0.
Now connect the DHT-11 to the Arduino YUN. See the photo. Pay attention to connect the sensor to the board, you can burn the sensor or the Arduino YUN board. Then connect the pwm (pin number 3) to the led, and pin number 4 to the relay. After connect the relay to the 5V of Arduino pin.

Upload the Code

There are two file in the Instructables. One is the example file by Adafruit MQTT library, the other is the file to use Arduino YUN with DHT-11 sensor. led, pwm and relay,

Copy the code and modify the Wifi SSID, PWD, and the Adafruit IO key.

Try first the first Adafruit Sketch, after you can try the DHT-11 code.

Upload the code then open serial monitor. You can see the debugger messages.

Setup Your Dashboard

Schermata 2016-07-09 alle 16.19.21.png
Schermata 2016-07-09 alle 16.19.37.png
Schermata 2016-07-09 alle 16.19.51.png

If that's ok you can surf to http://www.io.adafruit.com, and see your Dashboard called "Arduino".

Now you can populate the Dashboard with feeds, and add the relay, led and pwm controls.

For add the sensors blocks you can click + symbol, and after add the block that you want. For the value of sensors, you can use Gauge block, for the relay and buttons, you can create a button with "onoff" and "relay" name's. For the PWM output, you can create a slider with "slider" name.