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
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
Prerequisites:
- Hardware:
- Arduino UNO or compatible microcontroller
- DHT11 or DHT22 Temperature & Humidity sensor
- Ethernet Shield (compatible with Arduino)
- Jumper wires
- Breadboard
- Software:
- PlatformIO IDE (or PlatformIO extension in Visual Studio Code)
- Arduino Libraries: Ethernet, DHT
- MySQL Database (publicly accessible, hosted on a server)
- PHP Script for handling the incoming data
- ngrok for creating a secure tunnel to your local server
How to Download Software
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:
- Install Apache: sudo apt-get install apache2. This will install the Apache web server.
- Install MySQL: sudo apt-get install mysql-server. This installs the MySQL database server.
- Install PHP: sudo apt-get install php5 libapache2-mod-php5. This command installs PHP and the Apache module required to run PHP.
- Restart Apache Server: sudo /etc/init.d/apache2 restart. Restart the Apache server to apply the changes.
- 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:
- 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).
- Install PlatformIO IDE: Once you have VS Code installed, follow these steps to set up PlatformIO:
- Open VS Code.
- Go to the Extensions tab on the left sidebar (or press Ctrl + Shift + X).
- In the search bar, type PlatformIO IDE.
- Click on the PlatformIO IDE extension and click Install.
- 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.
- Create or Open a Project:
- To start a new project, click New Project from the PlatformIO Home screen.
- Select your board (e.g., Arduino, ESP32) and the framework (Arduino, ESP-IDF, etc.).
- Choose a directory for your project and click Finish.
- Managing Libraries:
- You can install and manage libraries directly from the Library Manager in PlatformIO.
- 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:
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:
- DHT11 Sensor Connections:
- VCC (DHT11) to 5V (Arduino)
- GND (DHT11) to GND (Arduino)
- 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:
Video
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