The flow rate sensor (YF-S201) and 8 channel relay 5V are supplied by an external power supply, while the Arduino Mega is powered using a 12V power adaptor, both are connected to a common ground.
when there is no water flowing through the flow rate sensor, the value obtained from the sensor is 0. But if a relay is activated and nothing flows through the sensor, the value obtained from the sensor will spike up and drop back to 0.
may I know why the value spike and is there any solution to it?
The relay modules should be powered externally, without shared ground.
The Mega should be powered from the PC/laptop, or with a 5volt cellphone charger connected to the USB socket. The YF-S201 (hall sensor) must be powered (5volt and ground) from the Mega.
Inductive loads connected to the relays must have snubber circuits.
If not, then there could be random resets of the Mega.
Read the "how to post" sticky if you want more help.
Leo..
Can you please post a circuit diagram of your project?
A hand drawn image will be fine..
Please include power supplies, component labels and pin names.
Do you have the flow sensor wiring anywhere near the relay module and the relay output wiring?