Week 3
Week 3: Software Development and IoT Integration
This week, we focused on refining and enhancing the functionality of our code, successfully implementing and testing several key features. By the end of the week, most of the essential software components were completed.
1. Wi-Fi Connection Function
To enable Wi-Fi connectivity, we defined the SSID and password of the target wireless network. The following steps were implemented:
- The
WiFi.begin(ssid, password);
function was used to establish a connection with the specified Wi-Fi network. - A validation check was added to confirm whether the connection was successful:
- If the connection was established, the system prints "Connection successful".
- If the connection fails, it prints "Failed to connect. Please check Wi-Fi information."
- A while loop was introduced to check the connection status every 1 second, with a maximum of 10 attempts.
- An additional note was considered: for unstable networks, the checking interval should be shorter, and the number of connection attempts should be increased to improve reliability.
2. Automatic Humidity Control Function
This function was developed to enable automated humidity regulation by comparing real-time humidity readings with a predefined threshold. The logic was implemented as follows:
- The system continuously monitors the current humidity level.
- If the humidity falls below 50% (the set threshold), the Arduino outputs a LOW signal to the relay, activating the humidifier.
- If the humidity reaches or exceeds 50%, the system outputs a HIGH signal, deactivating the humidifier.
- The status information is displayed on the serial monitor in real-time, allowing users to track system behavior.
3. Sending Data to ThingSpeak (IoT Platform)
To enable real-time monitoring, we integrated ThingSpeak, an IoT analytics platform, to display humidity data remotely. The key implementation steps were:
- The API key was used for authentication, allowing ThingSpeak to recognize the device sending the data.
- The server address was defined to specify the destination for data transmission.
- The following process was implemented for data transmission:
- Wi-Fi Connection Check: Before sending data, the system verifies whether the Wi-Fi connection is active. If not, an error message is printed.
- Constructing the HTTP GET Request: A request string is generated, embedding the API key, humidity (field1), and temperature (field2) into the URL.
- Establishing a Connection: The system attempts to connect to the ThingSpeak server using
client.connect(server, 80);
. - Data Transmission: If the connection is successful, the HTTP request is sent along with the necessary headers (such as Host and Connection headers). A blank line is sent at the end to signal the end of the request.
- Response Handling: The system waits for the server response, reads the returned data, and then closes the connection.
Upon successful execution, users can view real-time humidity data from their environment on ThingSpeak, enabling remote monitoring and data logging.
With these advancements, the software is now capable of Wi-Fi connectivity, automated humidity control, and IoT-based data monitoring, marking significant progress in the development of the humidifier system.
Comments
Post a Comment