External +12VDC power supply changes the voltage on digital input pin.

The problem in short: using +12VDC power supply on Vin vs. USB power gives me very different voltage on the digital input pin.


I am using Arduino to control a relay that in turn controls a valve. The simplified connection diagram looks like this:

Computer---MC PCIe-DAS1602/16 digital output pin---Arduino D2---Arduino---Arduino D10---Relay---Valve

The MC multifunction card that is also used for other tasks sends the TTL pulse from the computer. Arduino seems redundant here. The reason why I need an Arduino is to automatically shut down the valve after e.g. 5 min if the input voltage remains high forever.

If I connected the Arduino with the computer with an USB cable, everything works perfectly. I measured the voltage at D2. It was 5V when the MC digital pin is HIGH, and 0V when LOW.

However, if I powered the Arduino with 12VDC power supply (which is also connected to the relay to power the valve), the voltage changed. Voltage at D2 was 2V no matter what state the MC digital pin is, and the valve keeps opening and closing intermittently all the time. I cannot read the serial output because connecting it to the computer would power Arduino differently. But the TX light was on forever, indicating that the interupt is triggered all the time.

What is wrong?

Attached is the simplified code with irrelevant parts removed.

Thank you!

int inputPin = 2;
int outputPin = 10;
boolean inputChange = false;
boolean portInput = false;

void trig()
{
  inputChange = true;
  portInput = digitalRead(inputPin);
}

void setup() 
{
  Serial.begin(9600);
  pinMode(inputPin, INPUT);
  digitalWrite(inputPin, LOW);

  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin, LOW);
  attachInterrupt(digitalPinToInterrupt(inputPin), trig, CHANGE);
}

void loop() {
  if (inputChange) {
    inputChange = false;
    if (PortInput) {
      Serial.println("Remote Triggered ON");
      digitalWrite(outputPin, HIGH);
    } else
    {
      Serial.println("Remote Triggered OFF");
      digitalWrite(outputPin, LOW);
    }
  }
  // Auto shutoff valve
  //AutoShutoff();
}

In almost all cases Relays should have thier own supply as the Arduinos are not really capable of supplying the current needed.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.