Go Down

Topic: Ard Mega - testing 10 bulbs - odd timing errors (Read 413 times) previous topic - next topic

Vampyrewolf

I'm making a set up to test the life span of a certain type of halogen bulb. Each bulb will be on for 1 second and then off for 4 seconds. The Arduino Mega is enabling this solid state relay:

https://www.digikey.com/product-detail/en/digilent-inc/410-342/1286-1170-ND/7560227

A rocker switch would turn the respective pins HIGH which would "start" the process.

To test the basic circuit (no counters added), I'm using a jumper wire to go right from the 5V to the enabling pin to set it HIGH.

The problem I'm experiencing is that initially the circuit does what's its supposed to but after a while ("a while" varies) the timing of the circuit changes to on for 1 second and off for about 10 seconds. I haven't touched anything or moved anything. If I unplug the USB going to the Arduino and plug it back in, the program runs properly again. My code is below.

Code: [Select]

int pin23 = 0; // Channel 1
int pin25 = 0; // Channel 2
int pin27 = 0; // Channel 3
int pin29 = 0; // Channel 4
int pin31 = 0; // Channel 5

int pin33 = 0; // Channel 6
int pin35 = 0; // Channel 7
int pin37 = 0; // Channel 8
int pin39 = 0; // Channel 9
int pin41 = 0; // Channel 10


void setup() {
pinMode(22,OUTPUT); // Channel 1
pinMode(24,OUTPUT); // Channel 2
pinMode(26,OUTPUT); // Channel 3
pinMode(28,OUTPUT); // Channel 4
pinMode(30,OUTPUT); // Channel 5
pinMode(32,OUTPUT); // Channel 6
pinMode(34,OUTPUT); // Channel 7
pinMode(36,OUTPUT); // Channel 8
pinMode(38,OUTPUT); // Channel 9
pinMode(40,OUTPUT); // Channel 10

pinMode(23,INPUT); // Channel 1
pinMode(25,INPUT); // Channel 2
pinMode(27,INPUT); // Channel 3
pinMode(29,INPUT); // Channel 4
pinMode(31,INPUT); // Channel 5
pinMode(33,INPUT); // Channel 6
pinMode(35,INPUT); // Channel 7
pinMode(37,INPUT); // Channel 8
pinMode(39,INPUT); // Channel 9
pinMode(41,INPUT); // Channel 10

}

void loop() {
  pin23 = digitalRead(23); // CHANNEL 1
  if (pin23 == LOW) {
  digitalWrite(22, LOW);
  }
  else {
  digitalWrite(22, HIGH);
  delay(1000);
  digitalWrite(22, LOW);
  delay(4000);
  }
 
  pin25 = digitalRead(25); // CHANNEL 2
  if (pin25 == LOW) {
  digitalWrite(24, LOW);
  }
  else {
  digitalWrite(24, HIGH);
  delay(1000);
  digitalWrite(24, LOW);
  delay(4000);
  }

  pin27 = digitalRead(27); // CHANNEL 3
  if (pin27 == LOW) {
  digitalWrite(26, LOW);
  }
  else {
  digitalWrite(26, HIGH);
  delay(1000);
  digitalWrite(26, LOW);
  delay(4000);
  }

  pin29 = digitalRead(29); // CHANNEL 4
  if (pin29 == LOW) {
  digitalWrite(28, LOW);
  }
  else {
  digitalWrite(28, HIGH);
  delay(1000);
  digitalWrite(28, LOW);
  delay(4000);
  }

  pin31 = digitalRead(31); // CHANNEL 5
  if (pin31 == LOW) {
  digitalWrite(30, LOW);
  }
  else {
  digitalWrite(30, HIGH);
  delay(1000);
  digitalWrite(30, LOW);
  delay(4000);
  }

  pin33 = digitalRead(33); // CHANNEL 6
  if (pin33 == LOW) {
  digitalWrite(32, LOW);
  }
  else {
  digitalWrite(32, HIGH);
  delay(1000);
  digitalWrite(32, LOW);
  delay(4000);
  }

  pin35 = digitalRead(35); // CHANNEL 7
  if (pin35 == LOW) {
  digitalWrite(34, LOW);
  }
  else {
  digitalWrite(34, HIGH);
  delay(1000);
  digitalWrite(34, LOW);
  delay(4000);
  }

  pin37 = digitalRead(37); // CHANNEL 8
  if (pin37 == LOW) {
  digitalWrite(36, LOW);
  }
  else {
  digitalWrite(36, HIGH);
  delay(1000);
  digitalWrite(36, LOW);
  delay(4000);
  }

  pin39 = digitalRead(39); // CHANNEL 9
  if (pin39 == LOW) {
  digitalWrite(38, LOW);
  }
  else {
  digitalWrite(38, HIGH);
  delay(1000);
  digitalWrite(38, LOW);
  delay(4000);
  }

  pin41 = digitalRead(41); // CHANNEL 10
  if (pin41 == LOW) {
  digitalWrite(40, LOW);
  }
  else {
  digitalWrite(40, HIGH);
  delay(1000);
  digitalWrite(40, LOW);
  delay(4000);
  }
}



Hopefully I can get this resolved without pestering you fine folks too much.

PaulRB

Please don't take offence. Thanks for using code tags. But... That is terrible code! But I can see nothing in it that would cause it to stop running. Is the Mega overheating? Or the power supply? Can you post a schematic?

PaulRB

I feel I should also tell you that I already know the answer to your question:
Quote
test the life span of a certain type of halogen bulb
They have all reached the end of their life span.

Vampyrewolf

#3
Mar 14, 2018, 03:41 pm Last Edit: Mar 14, 2018, 03:47 pm by Vampyrewolf
Thanks for the input so far! This is definitely a learning experience for me as this coding and electronic stuff is not in my usual skillset. I'm basically patching things together as I learn them.

I drew out the schematic that is my current test set up. Instead of running 120 and powering the halogen, I'm simply using and LED to verify the function. Instead of using the rocker switch at this point, I just ran a jumper wire from the 3.3 (and at one point the 5V) to the signal input (pin 22).

In the drawn schematic, the switches would exist between the 3.3 (or 5V) and the Inputs (23,25,27,29,31,33,35,37,41). Turning these switches on would enable that channel to proceed with the pulsing.

I'm definitely open to constructive criticism regarding my coding. I'm not sure what is good code or bad code. I just know that my code worked....somewhat.

Vampyrewolf

In response to another member, I did attempt to add a pull down resistor to the input signal pin (23). It seemed to work fine for a while (on for 1 sec, off for 4 sec) but then it reverted back to it's "error state" (on for 1 sec and off for 10 sec).

Is it bad code? bad wiring?

Each channel is intended to be operated independently of the others. Each channel will eventually have their own counters (cycles driven, cycles completed). I'm not going to bother with the counters until I get the functionality correct.


PaulRB

#6
Mar 14, 2018, 08:22 pm Last Edit: Mar 14, 2018, 08:34 pm by PaulRB
Code or wiring? As a test, forget the SSRs. Wire the LEDs + series resistors direct to the Mega. This should help you figure out if the problem is hardware or software related.

I said your code was bad, but this was from a style/readability/maintainability point of view. It is long, repetitive and "dumb" but not actually incorrect, given its purpose. So I hope that my suggestion above will prove that the problem is related to the SSRs, wiring or power supply.

I was unaware of the existence of DC SSRs until recently. I thought all SSRs were AC. I still don't understand the point of DC SSRs, frankly. What do they do that a logic level FET does not do?

Vampyrewolf

I think you tried to post pictures but they just show up as black X's

Instead of the blue LED. the final product will have 120AC going through the SSR. I just used the LED's to keep things safe while I test out the function of the circuit and code.

I did reduce the over all testing unit to just 3 channels and adjusted the code. So far everything is running properly.

Code: [Select]

int pin23 = 0;      // Channel 1
int pin25 = 0;      // Channel 2
int pin27 = 0;      // Channel 3


void setup() {
pinMode(22,OUTPUT); // Channel 1
pinMode(24,OUTPUT); // Channel 2
pinMode(26,OUTPUT); // Channel 3


pinMode(23,INPUT); // Channel 1
pinMode(25,INPUT); // Channel 2
pinMode(27,INPUT); // Channel 3

}

void loop() {
{
  pin23 = digitalRead(23); // CHANNEL 1
  pin25 = digitalRead(25); // CHANNEL 2
  pin27 = digitalRead(27); // CHANNEL 3
 
  if (pin23 == HIGH)
                digitalWrite(22, HIGH);
  if (pin25 == HIGH)
                digitalWrite(24, HIGH);
  if (pin27 == HIGH)
                digitalWrite(26, HIGH);
 
delay(1000);

digitalWrite(22, LOW);
 digitalWrite(24, LOW);
digitalWrite(26, LOW);

 delay(4000);

}
}

PaulRB

#8
Mar 14, 2018, 11:50 pm Last Edit: Mar 14, 2018, 11:55 pm by PaulRB
Odd. I simply posted the pics you attached to your previous post. They look fine to me. A hand drawn schematic and two views of the Mega, breadboard and SSR.

AC SSRs will not operate correctly with only a DC current running through them, as I understand. They incorporate triacs, which may not switch off without the regular instants of zero voltage & current you get in an AC signal.

Grumpy_Mike

#9
Mar 15, 2018, 12:20 am Last Edit: Mar 15, 2018, 12:24 am by Grumpy_Mike
Quote
. I still don't understand the point of DC SSRs, frankly. What do they do that a logic level FET does not do?
Nothing, they are just a package with an optically isolated FET in them. It is just marketing.

Quote
Instead of the blue LED. the final product will have 120AC going through the SSR
I hope you nave progressed from a Solderless breadboard by then, and also added some decoupling and perhaps a snubber circuit. You problem is almost certainly to be one of radiated interference.

Vampyrewolf

I hope you nave progressed from a Solderless breadboard by then, and also added some decoupling and perhaps a snubber circuit. You problem is almost certainly to be one of radiated interference.
Of course! The solderless breadboard was to make sure that I had the function of the Arduino program working correctly. The next stem is to get everything soldered on to a protoboard.

I'm not sure what a snubber circuit is but I can google it. I'll probably be googling "radiated interference" as well.

I probably be using an appropriate bus bar to route the 120VAC to the 3 bulbs and the SSR. The bulbs themselves don't take a lot of power. 120V @ 200 Watts.

Wawa

I probably be using an appropriate bus bar to route the 120VAC to the 3 bulbs and the SSR. The bulbs themselves don't take a lot of power. 120V @ 200 Watts.
? In post#0 you linked to a 60volt peak SSR.
Leo..

Go Up