This folder contains the Arduino code for [Your Project Name]. The Arduino sketches handle the system's hardware interaction, such as sensors, actuators, and communication with the backend (server).
The Arduino code is responsible for:
- Reading sensor data (e.g., water level, TDS sensor).
- Controlling actuators (e.g., water pump, LEDs, buzzer).
- Communicating with the backend server via [choose method: Serial, Wi-Fi, Bluetooth, etc.].
- Managing system logic based on sensor inputs and control commands.
Make sure you have the Arduino IDE installed. You can download it from here.
- Open the Arduino IDE.
- Go to Tools → Board and select the correct board (e.g., ESP32).
- Go to Tools → Port and select the correct port.
To use the required libraries, you need to install them via the Arduino Library Manager:
-
ArduinoJson: Used for parsing and generating JSON data.
- Go to Sketch → Include Library → Manage Libraries.
- Search for ArduinoJson and install it.
-
LiquidCrystal_I2C: Used to interface with an I2C-based LCD.
- Go to Sketch → Include Library → Manage Libraries.
- Search for LiquidCrystal_I2C and install it.
Ensure the communication between the Arduino and the server is correctly set up (e.g., Serial, Wi-Fi). Check the code for the connection method and make any necessary adjustments (e.g., network credentials, IP address).
-
Output Pins
- Water Pump Relay:
GPIO 14
- Red LED:
GPIO 13
- Green LED:
GPIO 12
- Buzzer:
GPIO 25
- Water Pump Relay:
-
Input/Output Pins
- Ultrasonic Sensor
- Echo (Input):
GPIO 27
- Trigger (Output):
GPIO 26
- Echo (Input):
- Ultrasonic Sensor
-
Input Pins
- TDS Sensor:
GPIO 35
- TDS Sensor:
To configure the server IP, follow these steps to modify the connection settings in the sketch_oct6a.ino
file:
-
Open the
sketch_oct6a.ino
file in your project. -
Locate the
serverUrl
variable and update it with the IP address of your Flask server. Example:const String serverUrl = "http://xxx.xxx.xxx.xxx:5000"; // Replace with your server IP address
- Replace
xxx.xxx.xxx.xxx
with your server's IP address. - The default port for the Flask server is
5000
. Ensure that your Flask server is running on this port, or modify it if necessary.
- Replace
-
Ensure that your server and the Arduino board are connected to the same Wi-Fi network to enable proper communication between them.
To connect your Arduino to a Wi-Fi network, you need to set the SSID (network name) and password in the sketch_oct6a.ino
file:
-
Open the
sketch_oct6a.ino
file. -
Find the lines where the Wi-Fi credentials are set:
const char* ssid = "YOUR_SSID"; // Replace with your Wi-Fi network name const char* password = "YOUR_PASSWORD"; // Replace with your Wi-Fi network password
-
Replace
YOUR_SSID
with the name of your Wi-Fi network andYOUR_PASSWORD
with your network’s password.
- Open the
sketch_oct6a.ino
file in the Arduino IDE. - Ensure that the
Functions.ino
file is also included in the project folder as it contains all the functions used in the main code. - Click the Upload button to upload the code to your Arduino board.
The Arduino sketch consists of two files:
- sketch_oct6a.ino: The main Arduino sketch file, where the setup and loop functions are defined.
- Functions.ino: Contains all the functions that handle sensor readings, actuator control, and communication with the backend server.
- Sensor Reading: Code for reading sensor values from the TDS sensor and ultrasonic sensor.
- Actuator Control: Code to turn on/off the water pump, LEDs, and buzzer based on system requirements.
- Communication with Server: Code to send sensor data and receive control commands from the backend server.
- ArduinoJson: A library used for parsing and generating JSON data.
- LiquidCrystal_I2C: A library used for interfacing with an I2C LCD.
You can install these libraries through the Arduino Library Manager or download them from the official repositories.