Switching Relays whilst connected to sensors

Hi,

I'm really stuck so any help would be really really appreciated!
The idea of the code is to switch between two TDS sensors (Gravity: Analog TDS Sensor/Meter for Arduino - DFRobot) to measure the TDS level before and after I put a salt solution into a pipe. If you have both TDS sensors powered at the same time, they affect each other's readings so I'm trying to get it so that they are powered separately using a relay.
I am using a double relay where the RY-VCC is powered by a separate breadboard (https://www.amazon.co.uk/gp/product/B07DK4RX8R/ref=ppx_yo_dt_b_asin_title_o06_s00?ie=UTF8&psc=1) and the ground is also from this power supply.

The Arduino 5V is connected to the VCC on the relay and also powers both TDS sensors and two temperature sensors (Waterproof DS18B20 Sensor Kit-DFRobot). So the circuit goes Arduino 5V power, TDS in series, TDS in series, 2x temperature sensors in parallel. A breadboard schematic is included if that helps.

The problem is that the Arduino seems to disconnect often immediately after the code is uploaded, or if it does work it does not follow any pattern. I isolated just the relay switching part as shown below and even this simple pattern is not reflected in the switching of the relays. Sometimes one side turns on and off three times in a row, sometimes they alternate as expected and sometimes there is no delay between each side turning on and off.

PLEASE HELP I'M LOSING THE PLOT

const int A = 3;
const int B = 4;


void setup() {
  Serial.println("setup");


  Serial.begin(115200);
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
}


void loop() {
  digitalWrite(B, HIGH);
  Serial.print("A on");
  delay(1000);
  digitalWrite(A, LOW);
  Serial.print("B LOW");


  //Serial.println("HIGH");
  delay(1000);
  digitalWrite(A, HIGH);
  delay(1000);
  digitalWrite(B, LOW);


  Serial.println("b HIGH, A LOW");
  delay(1000);




}

First I have no idea how much 5.0 volt load you are placing on your Arduino Uno?

Next the entire TDS scheme outputs a voltage proportional to the TDS level in ppm. The specifications should look like this:

  • SPECIFICATION
    Signal Transmitter Board

  • Input Voltage: 3.3 ~ 5.5V

  • Output Voltage: 0 ~ 2.3V

  • Working Current: 3 ~ 6mA

  • TDS Measurement Range: 0 ~ 1000ppm

  • TDS Measurement Accuracy: ± 10% F.S. (25 ℃)

  • Module Size: 42 * 32mm

  • Module Interface: PH2.0-3P

  • Electrode Interface: XH2.54-2P

TDS probe

  • Number of Needle: 2

  • Total Length: 83cm

  • Connection Interface: XH2.54-2P

  • Color: Black

  • Other: Waterproof Probe

So you get a dc level of 0 to 2.3 volts proportional to 0 to 1,000 PPM. The Arduino is only looking at a DC level from each sensor which should be no problem being read on two analog input channels. The code for a single TDS channel should be able to be modified to read two channels. I would put a short delay between the analog reads.
A picture of a board is not quite a schematic. Maybe someone else can sort it out?
Ron

Your picture does not help. Please post a schematic, not a frizzy thing showing all power, ground and interconnections as well as all power supplies and their ratings. Include links for each piece of hardware. I suspect you have both hardware and software problems. The two work together and we need to know both.

The things you put in the Serial.print() do not seem to match the actions you take with the digitalWrite() calls (code is quoted; comments mine):

  digitalWrite(B, HIGH);
  Serial.print("A on"); // You just set B!
  delay(1000);
  digitalWrite(A, LOW);
  Serial.print("B LOW"); // you just set A!
  delay(1000);
  digitalWrite(A, HIGH);
  delay(1000);
  digitalWrite(B, LOW);
  Serial.println("b HIGH, A LOW"); // That's the exact opposite from what you set the pins to...
  delay(1000);

Hi,
We need a proper circuit diagram.
Please include power supply and all interconnections.

Thanks.. Tom... :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.