Connected House Publishes Amount of Light and Temperature on Adafruit.io

34

Ngo active in the field of digital mediation, based in Toulouse, France

In this tutorial we will create a connected house using the ESP32 board, that publishes the values recorded by a photoresistor and an internal temperature sensor online, specifically on https://adafruit.io.

Step 1: Set Up an Account on Adafruit.io

Step 2: Create a New Feed on Adafruit.io

Create a new feed by reaching https://io.adafruit.com/ > Feeds > Actions and then name it, for example “lightsensorvalue”.

Step 3: Install Arduino IDE

You will need to use Arduino IDE to code and upload the firmware onto your ESP32 board.

Download the software by visiting Arduino IDE > Scroll down until you see the “Download the Arduino IDE” section and choose the version based upon your operating system (e.g. If you have Windows 7, choose “Windows Installer” / if you have Windows 10, choose “Windows app”) > On the next page choose “Just download” and run the installation files.

Step 4: Prepare the ESP32 Board on Your Computer

Follow the instructions provided on GitHub for your Operating System. For example, if you have Windows 7 or 10, choose “Instructions for Windows” / if you have a MacBook, choose “Instructions for Mac”

Step 5: Check That the Board Is Correctly Configured

Launch Arduino IDE and select “ESP32 Dev Module” from the Tools menu > Board.

Fetch the Blink example from File > Examples > 01.Basics > Blink.
write int LED_BUILTIN = 2; at the top of the code

/* ESP 32 Blink Turns on an LED on for one second, then off for one second, repeatedly. The ESP32 has an internal blue LED at D2 (GPIO 02)

*/int LED_BUILTIN = 2;

void setup()

{ pinMode(LED_BUILTIN, OUTPUT);

}

void loop()

{ digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second}

Finally, upload the code by using the right arrow (→) button at the top right corner of the window, by choosing Sketch > Upload or by pressing Ctrl+U on the keyboard.

Step 6: Wiring the Photoresistor and the Temperature Sensor to the ESP32

The shorter leg of the photoresistor is connected to 3V on the ESP32. The other leg is connected to pin VP (or 36) and at the same time to a 1kohm resistor, which in turn is connected to GND on the ESP32.

Note: if it’s the first time you’re using a breadboard, check out this video to understand how a breadboard works.

There is no need to do any wiring to connect the temperature sensor to the ESP32, simply because the ESP32 has an internal temperature sensor.

Step 7: Programming on Tuniot

Let’s create a program that registers the values recorded by the photoresistor and the internal temperature sensor and publishes them online.

For that we need to reach: http://easycoding.tn/esp32/demos/code/

Choose the appropriate blocks to create the code displayed below:

  1. “Variables” section - Declare ‘i’ type ‘int’ Value + “Math” section - the actual value “0”
  2. “IOT” section > “Web services” subsection - Adafruit MQTT Setup (User Name and Key are retrievable from https://io.adafruit.com/ > View your AIO Key)
  3. “Various” section - Delay Ms 3000
  4. “Serial” section - Print on new line ‘Start’ “IOT” section >
  5. “IOT Station” subsection - Connect Network ssid… password… (the ssid is the name of your local wifi network connection and its password)
  6. “Loops” section - repeat while.. do + “Logic” section - not + “IOT” section >
  7. “IOT Station” subsection - Is Connected “IOT” section > “IOT Station” subsection - Local IP

The “User Name” and “Key” are available here (just click on View AIO Key):

Step 8: Install Adafruit_MQTT.h and Adafruit_MQTT_Client.h Libraries on Arduino IDE

For that we need to run Arduino IDE and go to Sketch > Include Library > Manage Libraries… > Search for “Adafruit mqtt library” and install the first result.

Step 9: Programming on Arduino IDE

To upload the code on Arduino IDE, click on the “Copy Arduino code into clipboard” button.

then paste the code onto Arduino IDE, and upload it to the ESP32.
If you click on Serial Monitor (top right of the Arduino IDE screen, below the “X” button), you should see the values recorded by the light sensor and by the temperature sensor:

It means that your ESP32 is connected to the internet, and that it’s sending the value recorded by the photoresistor and by the internal temperature sensor online, on https://adafruit.io.

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest

    Discussions