I have built some controllers for fluorescent tubes.
The script is basically just writing high and low to the control pin.
The arduino stalls at random times. Sometimes straight away, sometimes after 10 minutes.
I have tried several minis as well as a duemilanove.
The duemilanove unfreezes when I pull the control pin, so there must be some kind of current rolling back through the circuit. Also, when I set the ons and offs to close, the stalls occur. Sometimes the minis even reboot. I am chasing the blinking on/off effect of the tubes. I am aware of fluorescent lights kicking back dirty when switching them on and off but I thought this circuit would be protecting the arduino.
Can't be sure because we need a little information. A relay offers good isolation between the circuit controlling the relay coil and the circuit that utilizes the relay's switching contacts, so I don't think it's an interferance path through the relay.
Related possiblities:
What is the power source you are using for the Arduino board?
What is the power source you are using for the relay coil power shown in your posted drawing?
If possible a complete drawing of all your wiring might be helpful for us as the 'generic' relay drawing you posted really doesn't reflect what you have built in total.
here's a quick and dirty of the duemilanove setup i have on my desk.
I realize the power supply is different in the boxes I built, but since the duemilanove hangs too (not with a bulb by the way) I presume the problem must be with the tubes.
Well nothing jumps out at me as being fundamentally flawed. It might be possible that you are just getting lots of EMI interference from the switching noise of the relay contacts. If you could temporarily remove the relay from the project box to give it some physical separation (say a foot or so) from the Arduino module and low voltage power supply so that all the 220vac wiring is out of the box and then see if the symptom continues or not.
Also the fact that you low voltage power supply may be sharing the same 220vac as the tubes may be a EMI path. As an experimate you might try powering the Arduino module with batteries or USB power or something that isn't sharing the same 220vac circuit that is being switched be the relay contacts.
While I don't know if that is causing your problem or not, it certainly could damage the Arduino's output pin or the transistors emitter/base junction as there is nothing to limit the base current.
The flouresent tubes are generating EM spikes that are crashing your arduino. You need more tight decoupling around the supply. I would also add decoupling to your transistor load (emitter / collector).
Maybe even a small quench cap across the relay contacts.
by the way, this solution is no problem for my little boxes, there is room. I am however building a 64 tube controller on a custom A3 sized PCB. There is no more room there, can this solution be added further down the line somewhere? On the cable coming in or going out for example...
Without looking with an oscilloscope you don't. However, too small and it won't work too much and it is just a big inductor.
can this solution be added further down the line somewhere?
No the point about decoupling is that it has to be physically close to the component that is being upset. On your A3 board this decoupling must be applied close to the ATmega chip itself. If you put it any distance away the interference still get in.
Are those 8 ATmega chips?. If so you must carefully decouple each of them close to the chip. The inductor is only going to be the size of a resistor at biggest.
nope, those are shift registers. so I could keep the arduino pretty far away from them. so if I put the decoupler with the arduino on it's own it could work