Arduino UNO-Based Water Flow Monitoring and Relay Control System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit involves an Arduino UNO microcontroller, a 12V single channel relay, a water flow sensor, a rocker switch, and a 12V power supply. The Arduino UNO controls the relay and reads data from the water flow sensor. The relay is toggled using a rocker switch connected to the Arduino. The water flow sensor is powered by the 5V pin of the Arduino.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
12V Single Channel Relay
- Description: A relay module that allows control of high voltage devices with a low voltage signal.
- Pins: NC, COM, NO, IN, GND, VCC
12V Power Supply
- Description: A power supply providing 12V DC.
- Pins: +, -
Rocker Switch
- Description: A switch that can toggle between two states.
- Pins: 1, 2
Water Flow Sensor
- Description: A sensor that measures the flow rate of water.
- Pins: Signal, Vcc, GND
Wiring Details
Arduino UNO
- 5V: Connected to Vcc of the Water Flow Sensor.
- GND: Connected to GND of the Water Flow Sensor and pin 1 of the Rocker Switch.
- A0: Connected to pin 2 of the Rocker Switch.
- D4: Connected to Signal of the Water Flow Sensor.
- D2: Connected to IN of the 12V Single Channel Relay.
12V Single Channel Relay
- IN: Connected to D2 of the Arduino UNO.
- GND: Connected to - of the 12V Power Supply.
- VCC: Connected to + of the 12V Power Supply.
12V Power Supply
- -: Connected to GND of the 12V Single Channel Relay.
- +: Connected to VCC of the 12V Single Channel Relay.
Rocker Switch
- 1: Connected to GND of the Arduino UNO.
- 2: Connected to A0 of the Arduino UNO.
Water Flow Sensor
- Vcc: Connected to 5V of the Arduino UNO.
- GND: Connected to GND of the Arduino UNO.
- Signal: Connected to D4 of the Arduino UNO.
Code Documentation
/*
* This Arduino sketch controls a 12V single channel relay and reads data from a
* water flow sensor. The relay is controlled via digital pin D2, and the water
* flow sensor is read via digital pin D4. A rocker switch connected to analog
* pin A0 is used to toggle the relay. The water flow sensor is powered by the
* 5V pin of the Arduino.
*/
const int relayPin = 2; // Relay control pin
const int flowSensorPin = 4; // Water flow sensor signal pin
const int switchPin = A0; // Rocker switch pin
void setup() {
pinMode(relayPin, OUTPUT); // Set relay pin as output
pinMode(flowSensorPin, INPUT); // Set flow sensor pin as input
pinMode(switchPin, INPUT); // Set switch pin as input
digitalWrite(relayPin, LOW); // Initialize relay to be off
Serial.begin(9600); // Start serial communication
}
void loop() {
int switchState = analogRead(switchPin); // Read the state of the switch
if (switchState > 512) { // If switch is toggled on
digitalWrite(relayPin, HIGH); // Turn on the relay
} else {
digitalWrite(relayPin, LOW); // Turn off the relay
}
int flowSensorState = digitalRead(flowSensorPin); // Read flow sensor state
Serial.print("Flow Sensor State: ");
Serial.println(flowSensorState); // Print flow sensor state to serial monitor
delay(1000); // Wait for 1 second before next loop
}
This code initializes the pins for the relay, water flow sensor, and rocker switch. In the loop function, it reads the state of the rocker switch and toggles the relay accordingly. It also reads the state of the water flow sensor and prints it to the serial monitor every second.