System Overview
The Aqua-IoT hardware system consists of three main components:- Arduino - Sensor interface and data collection
- Raspberry Pi - MQTT bridge and network gateway
- Sensors - Environmental and water quality monitoring
Complete Pin Connection Map
Arduino Uno Pin Assignments
Based onsensores.ino configuration:
| Component | Arduino Pin | Pin Type | Notes |
|---|---|---|---|
| DHT11 Data | Digital 2 | Digital I/O | Temperature & humidity sensor |
| HC-SR04 Echo | Digital 4 | Digital Input | Ultrasonic distance sensor |
| HC-SR04 Trigger | Digital 6 | Digital Output | Ultrasonic distance sensor |
| DS18B20 Data | Digital 10 | OneWire | Waterproof temperature sensor |
| LDR Signal | Analog A0 | Analog Input | Light-dependent resistor |
| TDS Sensor | Analog A4 | Analog Input | Water quality sensor |
| 5V Power | 5V | Power | Power supply for all sensors |
| Ground | GND | Ground | Common ground (multiple GND pins available) |
Arduino Uno has limited 5V current output (~400mA). If powering multiple sensors, consider using an external 5V power supply.
Detailed Sensor Wiring
DHT11 - Temperature & Humidity Sensor
Pin Configuration:DHTPIN 2 (sensores.ino:16)
- Use 3-pin or 4-pin DHT11 module
- Built-in modules often include pull-up resistor
- If using bare sensor, add 10kΩ pull-up resistor between VCC and DATA
DS18B20 - Waterproof Temperature Sensor
Pin Configuration:DS18B20 10 (sensores.ino:17)
- OneWire protocol requires pull-up resistor
- Waterproof probe version has 3 wires
- Can use parasitic power mode (2-wire) but 3-wire is more reliable
- Suitable for aquarium water temperature monitoring
Gravity TDS - Total Dissolved Solids Sensor
Pin Configuration:TdsSensorPin A4 (sensores.ino:18)
- Probe must be fully submerged in water
- Keep probe clean for accurate readings
- Temperature compensation is applied using
media = 25(25°C average) - Outputs PPM (parts per million) for water quality
TDS sensor requires calibration. Use EEPROM to store calibration values for consistent readings across power cycles.
HC-SR04 - Ultrasonic Distance Sensor
Pin Configuration:echo=4, trigger=6 (sensores.ino:19-20)
- Measures distance: 2cm to 400cm
- Used for water level monitoring
- Mount sensor above water surface pointing downward
- Speed of sound constant: 0.0343 cm/µs at 20°C
- Returns distance in centimeters
LDR - Light Dependent Resistor
Pin Configuration:sensorPin = A0 (ldr.ino:9)
Voltage Divider Circuit:
- 10kΩ fixed resistor creates voltage divider
- Output range: 0-1023 (10-bit ADC)
- Converts to lumen for light intensity measurement
- Used for plant environment monitoring
Arduino Power Considerations
Current Requirements
| Component | Current Draw | Notes |
|---|---|---|
| DHT11 | 1-2 mA | Low power |
| DS18B20 | 1-1.5 mA | Low power |
| HC-SR04 | 15 mA | During pulse |
| TDS Sensor | 5-20 mA | Variable |
| LDR Circuit | <1 mA | Minimal |
| Total | ~25-40 mA | Safe for USB power |
-
USB Power (Recommended for development)
- 5V from USB port (computer or wall adapter)
- Current limit: ~500 mA
- Sufficient for all sensors
-
External Power Supply
- Use DC barrel jack (7-12V input)
- Arduino regulates to 5V
- Required for deployment without computer
-
Separate Sensor Power (For reliability)
- External 5V power supply for sensors
- Connect Arduino and sensor GND together
- Prevents voltage drops during sensor operation
Raspberry Pi Connection
USB Serial Connection
Configuration:/dev/ttyACM0 at 9600 baud (mqtt-arduino.py:27)
| Parameter | Value | Notes |
|---|---|---|
| Port | /dev/ttyACM0 | Auto-assigned by Linux |
| Baud Rate | 9600 | Must match Arduino: Serial.begin(9600) |
| Timeout | 1 second | Read timeout for ser.readline() |
| Data Bits | 8 | Default |
| Parity | None | Default |
| Stop Bits | 1 | Default |
The USB connection provides both data communication and power to the Arduino. For production, use external power for Arduino.
Network Architecture
Raspberry Pi Network Setup
Assembly Instructions
Prepare Arduino
-
Install Arduino IDE and required libraries:
- DHT sensor library
- OneWire
- DallasTemperature
- GravityTDS
-
Upload
sensores.inoto Arduino board -
Test serial output:
Connect DHT11 sensor
- Connect VCC to Arduino 5V
- Connect DATA to Digital Pin 2
- Connect GND to Arduino GND
- If using bare sensor, add 10kΩ pull-up resistor
Connect DS18B20 sensor
- Connect Red wire to Arduino 5V
- Connect Yellow wire to Digital Pin 10
- Connect Black wire to Arduino GND
- Critical: Add 4.7kΩ pull-up resistor between Yellow and Red wires
Connect TDS sensor
- Connect sensor VCC to Arduino 5V
- Connect sensor signal to Analog Pin A4
- Connect sensor GND to Arduino GND
- Submerge probe in water for testing
Connect HC-SR04 sensor
- Connect VCC to Arduino 5V
- Connect TRIG to Digital Pin 6
- Connect ECHO to Digital Pin 4
- Connect GND to Arduino GND
- Position sensor above water surface
Connect LDR sensor
- Build voltage divider:
- Connect 5V to one leg of LDR
- Connect other leg of LDR to Analog Pin A0
- Connect 10kΩ resistor from A0 to GND
- Position in plant area to measure light
Connect to Raspberry Pi
- Connect Arduino USB port to Raspberry Pi USB port
- Verify connection:
- Set permissions:
Safety & Best Practices
Electrical Safety
Cable Management
- Use appropriate wire gauge (22-24 AWG for sensors)
- Keep sensor wires under 1 meter when possible
- Label all connections for easy maintenance
- Use different colored wires:
- Red: 5V/VCC
- Black: GND
- Yellow/Green: Signal/Data
Grounding
- Critical: Connect all GND pins to common ground
- Arduino and sensors must share the same GND reference
- If using external power supply, connect GND to Arduino GND
Mounting
- Mount Arduino in dry, ventilated enclosure
- Position DHT11 away from heat sources
- Mount HC-SR04 perpendicular to water surface
- Secure TDS and DS18B20 probes in water flow area
- Position LDR in representative location for plant light
Troubleshooting
No Serial Data from Arduino
- Check USB connection:
ls /dev/ttyACM* - Verify baud rate: 9600 in both Arduino and Python
- Test with Arduino Serial Monitor first
- Check serial permissions:
sudo chmod 666 /dev/ttyACM0
Sensor Reading Errors
DHT11 returns NaN:- Check power connection
- Verify pin connection to Digital 2
- Add/check 10kΩ pull-up resistor
- Add 4.7kΩ pull-up resistor (most common issue)
- Check OneWire connection to Pin 10
- Verify sensor is not damaged
- Ensure probe is fully submerged
- Clean probe contacts
- Calibrate sensor
- Check connection to A4
- Verify Trigger on Pin 6, Echo on Pin 4
- Check if sensor is within range (2-400cm)
- Ensure no angled or sound-absorbing surfaces nearby
- Check voltage divider circuit
- Verify 10kΩ resistor value
- Test in different lighting conditions
- Check connection to A0
Power Issues
- Brownout/Reset: Use external 5V supply for sensors
- Unstable readings: Add 100µF capacitor across 5V and GND
- USB not detected: Try different USB cable or port
Reference Diagrams
For visual wiring diagrams, refer to:- Arduino Uno pinout: https://docs.arduino.cc/hardware/uno-rev3
- Individual sensor datasheets for specific wiring
Next Steps
Arduino Sensors
Configure Arduino sensor code
Raspberry Pi Bridge
Set up MQTT bridge software
