Not sure if I'm posting in the right place... :-/
I've got an arduino which controls relays which in turn control motors, two for each motor (reverse and forward). Power supply comes from a battery. I am able to control it smoothly with Processing when the arduino is hooked up to a USB Cord, however when I switch over to the xbees, the relays go haywire and start switching like mad when I send the command over for the arduino to begin.
What I'd like to know, is there a way I can send the command over without having the arduino continue turning the relays on and off?
Have you tried increasing the size of the battery? If there isn't enough juice to supply whats being drawn then the relays can flicker.
That took me a week to figure out once with a similar problem.
But! there could be other reasons, its one to eliminate.
I'm sorry :-[, I think I didn't explain the situation well enough.
The battery isn't the problem. The connection between the computer and arduino however is the problem. When the arduino is hooked up via the USB Cable, I am able to keep a relay on without problem. However, when I switch over to the xbees, the relays turn off and on constantly. I'm guessing it has something to do with the way wireless works, but I'd actually like to know how to prevent the relay from turning off and on when I send the command to the arduino to turn the relay on.
I hope that was more helpful.
Could you post your circuit? Two questions, do you have a ground between all your units and are you trying to drive the relays directly from an arduino pin?
I do have a ground between all my units and yes I am driving my relays from the arduino pins, but the power for the relays come from the battery.
"I do have a ground between all my units and yes I am driving my relays from the arduino pins, but the power for the relays come from the battery. "
Any what is the battery voltage? If it is not 5vdc like the Arduino internal regulator and if you are not using a switching transistor between the Arduino digital output and the relay coil then that might be a problem.
The battery is 12v. I'm using the Arduino only to control the coil. Also, the Arduino currently doesn't get it's power from the battery.
"The battery is 12v. I'm using the Arduino only to control the coil. Also, the Arduino currently doesn't get it's power from the battery. "
Ok, so a Arduino output pin is wired to one of the relay coil pins, what is the other end of the relay coil wire to? And what is the current requirements for the relay coil? This can be figured out but all the specifications and details need to be known.
Ok, I'll try and post as much info as I can. Hope all of it's relevant.
The other end of the relay coil is hooked up to ground. I have six relays paired up (so 3 pairs). Each pair is wired together in such a way that I can reverse the polarity of the 12V motor which is hooked up to one of the relays.
The relays themselves are 5VDC (I think that's for the coil); 8A, 250V~, AC1.
I hope I made sense. :-?
"The relays themselves are 5VDC (I think that's for the coil); 8A, 250V~, AC1.
I hope I made sense. "
Ok, that means a digital output HIGH is suppose to energize the relay coil as the other end is wired to ground. The micro's output pin has a maximum current avaliblity of around 30-35 milliamps. You didn't state the coil current requirements so it's most likely not printed on the package, however any 5vdc relay with contact ratings that large is bound to require much more then 30ma.
If you can give us a manufacture name and model number then we may be able to search for a data sheet to confirm it's coil current requirements.
I know you originally posted that the relay works of when powered via USB and that would tend to say the relay is ok, but first one should be certain that the basic requirements for the relay are being met and that requires we know it's coil current requirement and if more then 30-35ma then use a switching transistor to control the relay coil.
Here's the data sheet for the relays:
Not that I can understand most of it ::), but it's the relay with 8 pins.
Well from the data sheet the 5vdc coil models are avalible in two versions, a high sensitivity model that requires 50ma and a general purpose version that requires 80ma. Neither of these can be driven safetly directly from a digital output pin, rated at 30-35ma maximum, and can damage the output pin.
It's been fine so far, I haven't seen any problems occuring because of it. Back to my original question. Why do the relays work perfectly with a USB cord, but when I switch over to xbee wireless the relays more or less go haywire?
"It's been fine so far, I haven't seen any problems occuring because of it. Back to my original question. Why do the relays work perfectly with a USB cord, but when I switch over to xbee wireless the relays more or less go haywire? "
I don't own a xbee nor familiar with them. Does the xbee take additional current draw from the Arduino board?
I suggest you deal with one problem at a time and it appears to me that you are overloading an Arduino digital output pin by trying to drive the relay coil directly and that should be addressed first. But I'll let anyone else jump in that wants to give further thoughts to your problem.
Well, thanks for your help Lefty!
I'll just continue experimenting...maybe I'll get lucky ;D.
Sorry if I'm bringing an old post back.
However I discovered what was making my relays go haywire. I was using the digital pins to control the relays, I quite stupidly had the ground hooked up to the analog ground. When I made the change, thus that ground from the relays was hooked up to the digital ground, the relays were working as they should through the xbee!
All in all I feel quite happy and dumb from this discovery. :-[