Using External Power Supply as Input and Output triggers

HI All

Project Description:
Need to read 12 voltage signals from 5v smps and trigger to 2 8 channel relays , alsopoweredby the 5v smps.

Issue:
The 12 analog signals are being read but cant trigger the relays consistently. Also on checking with multimeter we found 9v coming into analog pins when there is no triggers. It reduces to 4.7v when 5v trigger is supplied by smps.

Hardware Used:
Arduino Mega 2560 board
5v smps
2 - 8 channel relays

Circuit Diagram:
Attached- .jpg

Arduino Code:
Attached .ino

Ard_triggers.ino (8.47 KB)

Hi,
Welcome to the forum.

We need a bit more detailed circuit diagram please.
Have you got the "Cam Trigger" SMPS gnd connected to the Mega gnd?
What is the "Cam Trigger"?

What relays are you using, link to spec/data.
Do you mean you have output to 2 lots of 8 channel relay modules?
Reading 12 different 5V inputs from SMPSs?

delay(10) is a delay of 10 milliseconds, your relays will not be able to respond reliably at that speed.

Can you please tell us your electronics, programming, arduino, hardware experience?

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Hi Tom
So the setup is :
There are 14 wires coming from SMPS.

  • 12 are “cam triggers”. By that I mean if they switch on a button for a particular camera that wire will have 5v (4.67 approx) running through it .
  • 2 are 0v and +5v from SMPS

I connected the SMPS Gnd (0v) to arduino GND.

Here is the concise version of the code (It was too big to put in forum directly earlier

int sensorpin1 = A1;
int sensorvalue = 0;
int sensorpin2 = A2;
int sensorvalue2 = 0;

int outpin = 2;
char val;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(sensorpin1, INPUT_PULLUP);
  pinMode(sensorpin2, INPUT_PULLUP);

  pinMode(outpin, OUTPUT);
  digitalWrite(outpin, HIGH);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.setTimeout(1000);
  while (Serial.available()) {
    val = Serial.read();
    if (val == '1') {
      digitalWrite(outpin, LOW);
      delay(1000);
      digitalWrite(outpin, HIGH);

    }
  }

  sensorvalue = analogRead(sensorpin1);
  sensorvalue = analogRead(sensorpin1);
  if (sensorvalue < 50) {

    Serial.println(String(sensorpin1) + "_1");

  }
  if (sensorvalue >= 50) {
    Serial.println(String(sensorpin1) + "_0");
  }
  sensorvalue2 = analogRead(sensorpin2);
  sensorvalue2 = analogRead(sensorpin2);
  if (sensorvalue < 50) {

    Serial.println(String(sensorpin2) + "_1");

  }
  if (sensorvalue >= 50) {
    Serial.println(String(sensorpin2) + "_0");
  }

}

TomGeorge:
What relays are you using, link to spec/data.
Do you mean you have output to 2 lots of 8 channel relay modules?

Yes, there are 2 lot of 8 channel relays which I have to trigger.

Hi,
Why are you analog-reading a digital signal, the "camera" signal is either 0V or 5V.
digital-read and you can use more input pins, you will then not need to double read the analog pins.
This should work better;

int sensorpin1 = A1;
int sensorvalue1 = 0;
int sensorpin2 = A2;
int sensorvalue2 = 0;

int outpin = 2;
char val;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(sensorpin1, INPUT_PULLUP);
  pinMode(sensorpin2, INPUT_PULLUP);
  pinMode(outpin, OUTPUT);
  digitalWrite(outpin, HIGH);
}


void loop() {
  // put your main code here, to run repeatedly:
  Serial.setTimeout(1000);
  while (Serial.available()) {
    val = Serial.read();
    if (val == '1') {
      digitalWrite(outpin, LOW);
      delay(1000);
      digitalWrite(outpin, HIGH);


    }
  }

  sensorvalue1 = digitalRead(sensorpin1);
  if (sensorvalue1 == LOW)
  {
    Serial.println(String(sensorpin1) + "_1");
  }
  else
  {
    Serial.println(String(sensorpin1) + "_0");
  }

  sensorvalue2 = digitalRead(sensorpin2);
  if (sensorvalue2 == LOW)
  {
    Serial.println(String(sensorpin2) + "_1");
  }
  else
  {
    Serial.println(String(sensorpin2) + "_0");
  }
}

Your sensor input is either HIGH or LOW, so only one if statement with ..else...

Tom... :slight_smile:

Hi,
Is this how you have your inputs wired?


Tom... :slight_smile:

TomGeorge:
Hi,
Why are you analog-reading a digital signal, the "camera" signal is either 0V or 5V.
digital-read and you can use more input pins, you will then not need to double read the analog pins.
This should work better;

int sensorpin1 = A1;

int sensorvalue1 = 0;
int sensorpin2 = A2;
int sensorvalue2 = 0;

int outpin = 2;
char val;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(sensorpin1, INPUT_PULLUP);
  pinMode(sensorpin2, INPUT_PULLUP);
  pinMode(outpin, OUTPUT);
  digitalWrite(outpin, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.setTimeout(1000);
  while (Serial.available()) {
    val = Serial.read();
    if (val == '1') {
      digitalWrite(outpin, LOW);
      delay(1000);
      digitalWrite(outpin, HIGH);

}
  }

sensorvalue1 = digitalRead(sensorpin1);
  if (sensorvalue1 == LOW)
  {
    Serial.println(String(sensorpin1) + "_1");
  }
  else
  {
    Serial.println(String(sensorpin1) + "_0");
  }

sensorvalue2 = digitalRead(sensorpin2);
  if (sensorvalue2 == LOW)
  {
    Serial.println(String(sensorpin2) + "_1");
  }
  else
  {
    Serial.println(String(sensorpin2) + "_0");
  }
}




Your sensor input is either HIGH or LOW, so only one if statement with ..else...

Tom... :)

Hi Tom
Tested this but issue is when nothing is triggered I am getting 0 and 1 fluctuations. However when button is triggered then constant 1 is coming. I also tried using pullup resistor but in that case when camera button is triggered its not going 0

Hi,
You need to draw a diagram of your input circuit and switch and SMPS so we can see your config.
Is it like in the diagram in post#5?

Can you also post a picture of your project so we can see your component layout?
Do you have a DMM?

Thanks.. Tom.... :slight_smile:

Hi Tom
This is the actual circuitry (circuit 1) which was present. When the camera button is switched on the PLC sends 24v which triggers a 24v relay. This in turn connects the 5v smps to the normally open connection of the relay. That wire we supply it to the arduino pin.

We used both digitalRead and analog read but the read where in consistent. In case of digitalRead the readings were fluctuating between 0 and 1 when the button was switched off (no volts in A1). In case of analoRead value ranged from 0-1023.

We then modified the circuit as circuit 2 to stablize the reading. However we noticed that when camera button is switched on we get 1 (HIGH) reading on A1 but after 1-2 seconds it goes to 0(LOW). On Further investigation we found that the voltage on the 5v Realy also drops to millivolts between Gnd(Arduino) and NO pin of 5v realy. We also checked the voltage on the Vcc pin of 5v relay but that is coming constant at 4.67v.

Dont know why the 5v Relay switch is losing contact after a while. Nor I am able to figure out why direct reading in circuit 1 is giving fluctuations.

Thanks & Regards
SGN

Hi,
Is the 5V SMPS really necessary?
Why can't you use the 5V from the Mega and just 1 5V SMPS to power the Mega and the relays you want the Mega to control.

Now I think you mean that you are just getting 12 PLC outputs to interface with a Mega and the output of the Mega to control 2 x 8 relay modules.

You should only need the 24V coil relay connected to the PLC and the relay contacts switching a Mega DIGITAL mode input to gnd with software INPUT_PULLUP configured in the software for each input.
That way you do not need the 5V SMPS for each PLC relay and have a simpler circuit to debug.

Instead of a relay on the Mega input you could have used an Opto-Coupler on each input, less bulky and more efficient.

Look at my diagram in post#5, you don't need the 5V SMPS to provide input signal, just gnd the DIGITAL input of the Mega with PULLUPS configured.
Adding a 0.1uF capacitor to each of the digital inputs that you use will help also.

Tom.... :slight_smile: