Sending Temperature & Humidity Data From Arduino (Ethernet Shield) to Public MySQL Database Using Ngrok & PlatformIO

by embedotronics in Circuits > Arduino

276 Views, 1 Favorites, 0 Comments

Sending Temperature & Humidity Data From Arduino (Ethernet Shield) to Public MySQL Database Using Ngrok & PlatformIO

title.png

In this tutorial, you will learn how to send temperature and humidity data from an Arduino equipped with an Ethernet Shield to a public MySQL database using ngrok for tunneling and PlatformIO as the development environment. This setup allows remote monitoring of environmental conditions from anywhere in the world.

Supplies

a.jpg
c.jpg

Prerequisites:

  1. Hardware:
  2. Arduino UNO or compatible microcontroller
  3. DHT11 or DHT22 Temperature & Humidity sensor
  4. Ethernet Shield (compatible with Arduino)
  5. Jumper wires
  6. Breadboard
  7. Software:
  8. PlatformIO IDE (or PlatformIO extension in Visual Studio Code)
  9. Arduino Libraries: Ethernet, DHT
  10. MySQL Database (publicly accessible, hosted on a server)
  11. PHP Script for handling the incoming data
  12. ngrok for creating a secure tunnel to your local server

How to Download Software

platformio.png

Installation of XAMPP server:


If you're working on a Windows platform, we recommend using the XAMPP server, which can also be used on Linux systems. However, for Linux users, it's often better to use a LAMP (Linux, Apache, MySQL, PHP) stack for simplicity and performance. Since we are focusing on Windows in this guide, we will proceed with XAMPP. You can download the XAMPP server here

For Linux users, here's a quick guide on setting up a LAMP server:

  1. Install Apache: sudo apt-get install apache2. This will install the Apache web server.
  2. Install MySQL: sudo apt-get install mysql-server. This installs the MySQL database server.
  3. Install PHP: sudo apt-get install php5 libapache2-mod-php5. This command installs PHP and the Apache module required to run PHP.
  4. Restart Apache Server: sudo /etc/init.d/apache2 restart. Restart the Apache server to apply the changes.
  5. Verify Apache Installation: Visit http://localhost/ in your browser. If you see the Apache default page, the installation was successful. If not, something may have gone wrong during the setup.

Installing phpMyAdmin:

phpMyAdmin is a web-based interface for managing MySQL databases. To install it, use the following command:

sudo apt-get install phpmyadmin

This will install phpMyAdmin and configure it with your Apache and MySQL setup.

By following these steps, you can easily set up a LAMP server on a Linux machine, or alternatively, use XAMPP for Windows if you're on that platform.


Steps to Install PlatformIO in VS Code:


  1. Install Visual Studio Code: First, if you don't already have VS Code installed, you can download it from here. Choose the version compatible with your operating system (Windows, macOS, or Linux).
  2. Install PlatformIO IDE: Once you have VS Code installed, follow these steps to set up PlatformIO:
  3. Open VS Code.
  4. Go to the Extensions tab on the left sidebar (or press Ctrl + Shift + X).
  5. In the search bar, type PlatformIO IDE.
  6. Click on the PlatformIO IDE extension and click Install.
  7. Verify Installation: After installation, PlatformIO will automatically configure itself. You should see the PlatformIO icon in the sidebar. Click on it to open the PlatformIO Home screen, where you can manage projects, boards, and libraries.
  8. Create or Open a Project:
  9. To start a new project, click New Project from the PlatformIO Home screen.
  10. Select your board (e.g., Arduino, ESP32) and the framework (Arduino, ESP-IDF, etc.).
  11. Choose a directory for your project and click Finish.
  12. Managing Libraries:
  13. You can install and manage libraries directly from the Library Manager in PlatformIO.
  14. Use the platformio.ini file to customize your project settings, including board configurations and dependencies.

By following these steps, you will have PlatformIO set up in VS Code, ready to work on IoT and embedded development projects.


Circuit Diagram:

IMG_20240524_211401.jpg
d.png

To begin with, you should first connect the Ethernet Shield to the Arduino as shown in the provided circuit diagram. Once the Ethernet Shield is properly attached, proceed to connect the DHT11 sensor by following these steps:

  1. DHT11 Sensor Connections:
  2. VCC (DHT11) to 5V (Arduino)
  3. GND (DHT11) to GND (Arduino)
  4. Data Pin (DHT11) to any digital pin on the Arduino (e.g., D2)

Ensure all connections are secure before powering up the system. This setup allows the Ethernet Shield to handle network communication, while the DHT11 sensor measures temperature and humidity.

Code:

You can get the Source code on below provided link:


Source Code

Video

Send Temperature & Humidity Data from Arduino(Ethernet Shield) to Public MySQL by ngrok & PlatformIO

In this video, we provide a detailed explanation of the project, covering all essential aspects.

If you have any questions or need further clarification, feel free to drop a comment below.

For more insights and tutorials on embedded systems, be sure to visit and subscribe to our YouTube channel.

Stay updated by following us on Facebook, where we share frequent updates and more exciting content.

Thank you for your support!

Best Regards,

Embedotronics Technologies