Problem with constant 1.5V output although the 5V input changes

Hi there!
I've done some C# and Java before but this is my first time dealing with C++. Yes, call me a noob if you'd like.

I'm using an Arduino Nano ATMEGA328p as a microcontroller for a modular railway project. I'd like two relays to change depending on whether two turnouts are either straight or turned. The turnouts are controlled by a different control card which gives an output of 5V ( 8µA) for each turnout that's in a "turned" state.

I want to use these values (called X3 and X4) in an XOR and XNOR logic. If either X3 or X4 is true, relay 1 should be disabled and relay 2 activated. If none of X3 or X4 is true, disable relay 2 and activate relay 1.

~The problem~
The microcontroller doesn't seem to make my wishes come true. Whatever state X3 or X4 is, relay 1 is always 0V, and relay 2 at 1.5V (as measured with my multimeter).
I'm not receiving any errors when validating the code.

/*

*/
int sensorX3Val = 3;
int sensorX4Val = 4;
int relay1 = 5;
int relay2 = 6;

void setup() {
  Serial.begin(9600);
  pinMode(3,  INPUT);
  pinMode(4,  INPUT);
  pinMode(5,  OUTPUT);
  pinMode(6,  OUTPUT);
}

void loop() {
  sensorX3Val = digitalRead(3);
  sensorX4Val = digitalRead(4);
  delay (50);
  
  if ((sensorX3Val == LOW) && (sensorX4Val == LOW)) { //Turnouts are straight
    digitalWrite(relay2,  LOW); //Deactivate relay 2
    delay(500);
    digitalWrite(relay1,  HIGH); //Activate relay 1
  }  
      
  else if ((sensorX3Val == HIGH) && (sensorX4Val == LOW)) { //Turnout X3 is turned
    digitalWrite(relay1,  LOW); //Deactivate relay 1
    delay(500);
    digitalWrite(relay2,  HIGH); //Activate relay 2
  }   
      
  else if ((sensorX3Val == LOW) && (sensorX4Val == HIGH)) { //Turnout X4 is turned
    digitalWrite(relay1,  LOW); //Deactivate relay 1
    delay(500);
    digitalWrite(relay2,  HIGH); //Activate relay 2
  }
      
  delay(600);      
}

Any ideas on what to do is appreciated!

Post a link or data sheet to the relays you are using.
Show where you are measuring these voltages

2 Likes

I should've mentioned that I haven't connected the relays yet, they're bound to arrive tomorrow.
The relays doesn't seem to have a datasheet available but here's the link: Electronic utilities: Relay card
There's a description on how to use them

I'm measuring the outputs this way until I have the relay cards:
GND and pin 5
GND and pin 6

Then you should only see 0V or 5V at an output.
Why don't you do a test program and see what happens.
In your code set sensorX3Val and sensorX4Val to LOW and see what happens
Then try HIGH, LOW etc

2 Likes

Where did you get that spec from? The (8uA) is strange.

Post an annotated schematic showing exactly how you have wired this. Be sure to include all connections, power, ground, power sources and not voltages. Do Not connect those relays until you can confirm they are compatible with logic level devices. It states logic level voltages which is saying 5V and Ground. From what I could find they will destroy your Arduino. Here is what I found: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.Ow7LLKmrjc7a9Mvhv51_6gHaFP%26pid%3DApi&f=1&ipt=240cc5cc449a13d5bdd6f3e25728e30da82bfd92487dfabf075a539a667a3cfd&ipo=images I am not sure it will load for you but I used "MGP relay card schematic" as the search term. It showed the relays being driving by a buffer chip similar to the uln2803. If that is the correct representation of the relay connecting it will destroy your Arduino. If you plan on trying also order some spare Arduinos.

1 Like

The problem's solved. I tried doing some simple test programs and nothing still worked. Concluded that the programming tool never sent over sketches to the microcontroller, therefor nothing I coded made any difference. The solution was to change the programmer to an old bootloader and I could finally see some changes.
Skärmbild 2024-09-06 031625
Regarding the odd voltage values of 1.5V, I believe it was caused by some bad soldering work on my part.
Thank you all for your time! :smile:

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