Relay shield for arduino problems

ebeowulf17

Joined Aug 12, 2014
3,274
The thing is the point of the project is to have the motor run on a recharable battery. Connecting a 9v or an external source similar to it might be counter-intuitive to what I am trying to accomplish you know? I appreciate the idea though thank you!
Well, you hadn't told us that yet, so how were we to know?

Anyway, when testing things, it's generally a good idea to work in small steps and test incrementally. In this particular case, you don't really know how well your Arduino/relay combination is working yet, you don't know if your rechargable battery setup is working yet, and you don't know if your new motor will work well on your rechargable battery.

Instead of mashing a whole bunch of unknown things together at once, why not change just one variable at a time and observe the results? That way, if it works you can proceed to the next step. If it doesn't work, you know the problem is in the one variable you changed. Otherwise, if you change everything at once and it doesn't work, you have no idea which change is the problem.

I think doing a quick test with the 9V battery is smart. That will prove that you have the Arduino relay control working properly, and that you understand which I/O terminals on the relay board you need to connect in order to have the relay successfully control the motor. Once you've established those things, add the new variable of trying to run this whole thing on the rechargeable battery system.

Of course, you're free to skip as many intermediate steps as you want, and if it all works perfectly then you'll have saved a little time by skipping ahead... but if it doesn't work, you'll have no idea why, and the first thing we'll suggest is backtracking and doing incremental testing.
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
Well, you hadn't told us that yet, so how were we to know?

Anyway, when testing things, it's generally a good idea to work in small steps and test incrementally. In this particular case, you don't really know how well your Arduino/relay combination is working yet, you don't know if your rechargable battery setup is working yet, and you don't know if your new motor will work well on your rechargable battery.

Instead of mashing a whole bunch of unknown things together at once, why not change just one variable at a time and observe the results? That way, if it works you can proceed to the next step. If it doesn't work, you know the problem is in the one variable you changed. Otherwise, if you change everything at once and it doesn't work, you have no idea which change is the problem.

I think doing a quick test with the 9V battery is smart. That will prove that you have the Arduino relay control working properly, and that you understand which I/O terminals on the relay board you need to connect in order to have the relay successfully control the motor. Once you've established those things, add the new variable of trying to run this whole thing on the rechargeable battery system.

Of course, you're free to skip as many intermediate steps as you want, and if it all works perfectly then you'll have saved a little time by skipping ahead... but if it doesn't work, you'll have no idea why, and the first thing we'll suggest is backtracking and doing incremental testing.
That is true...Ill try it then and my apologies for the miscommunication. I'll try to keep you updated on the progress!
 

djsfantasi

Joined Apr 11, 2010
6,521
The thing is the point of the project is to have the motor run on a recharable battery. Connecting a 9v or an external source similar to it might be counter-intuitive to what I am trying to accomplish you know? I appreciate the idea though thank you!
What part don’t you understand? You’re going to need to supply power externally to the relay contacts, NO MATTER WHAT. So if it’s counterintuitive to what you’re trying to accomplish. It’s also counterintuitive to It ever working.

It may work this way.
  • Connect the Arduino 5V pin yo the relay common contact
  • The relay NO contact goes to one motor lead
  • The other motor lead goes to the Arduino ground
The first connection is your external power to the relay’s contact.

Note that DC motors have a lot of electrical noise. Hooking one up this way can cause glitches, such as the Arduino resetting.
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
What part don’t you understand? You’re going to need to supply power externally to the relay contacts, NO MATTER WHAT. So if it’s counterintuitive to what you’re trying to accomplish. It’s also counterintuitive to It ever working.

It may work this way.
  • Connect the Arduino 5V pin yo the relay common contact
  • The relay NO contact goes to one motor lead
  • The other motor lead goes to the Arduino ground
The first connection is your external power to the relay’s contact.
I'm just gonna try the steps mentioned before, I tend to think too ambitiously and don't think about the small steps. Again thank you for your input and advice.
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
So I can confirm using a 9v works like mentioned above. It ran for a few seconds and then died (pretty sure the battery was already dead). I guess that confirms the hardware and software aspects work, it'll just take a little of finesse :)
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
Now that I know everything works with an external power source how can I make it work without one? If I remember right the point of the external source was to check to see of the hardware or software worked, which it does, so what's the next step? (How can I make it so it works like it does in the video)
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
Now that I know everything works with an external power source how can I make it work without one? If I remember right the point of the external source was to check to see of the hardware or software worked, which it does, so what's the next step? (How can I make it so it works like it does in the video)
Correction: I rewatched the video and DID see he used an external source so props to whoever called that out. But the question still stand, would it be possible to connect a energy shield on top of the relay and use it as an external source of energy?

Like I mentioned before I'm a novice so I don't really understand various concepts yet!
 

djsfantasi

Joined Apr 11, 2010
6,521
Now that I know everything works with an external power source how can I make it work without one? If I remember right the point of the external source was to check to see of the hardware or software worked, which it does, so what's the next step? (How can I make it so it works like it does in the video)
As I said in an early post, you might consider the fact that without an external source, it won’t work... depending on what you think an external source is.

In post #23, I answered your question. You can wire the motor and relay so the Arduino power IS the external source.

Considering the problem in an abstract fashion, the relay contacts are just a switch. Consider it like a simple switch. One side of the motor goes to one side of the power supply. To switch the motor, its other terminal goes to the NO contact of the relay while the Common terminal of the relay goes to the other side of the power supply.

Let me know if you need a schematic. I’m on my cell phone right now.
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
As I said in an early post, you might consider the fact that without an external source, it won’t work... depending on what you think an external source is.

In post #23, I answered your question. You can wire the motor and relay so the Arduino power IS the external source.

Considering the problem in an abstract fashion, the relay contacts are just a switch. Consider it like a simple switch. One side of the motor goes to one side of the power supply. To switch the motor, its other terminal goes to the NO contact of the relay while the Common terminal of the relay goes to the other side of the power supply.

Let me know if you need a schematic. I’m on my cell phone right now.
Yea I'm more of a visual learner. Thank you!

Also I hear you on making the arduino the external sources, I'll try to do some research on that and I'll get back to you.
 

Reloadron

Joined Jan 15, 2015
5,509
This should be your relay shield board. Would that be correct? Just like the one in the video. They call it a "shield" because the board is designed to be placed right on top of the Arduino Uno board. This is a nice feature because it eliminates the need for external wiring. This relay board also has small LEDs to let you visually see which relays are active. The male pins on the bottom of your relay board should mate with the female pins on the Arduino Uno board, they sandwich together. Be careful not to force things and make sure the pins align with their respective sockets. Bent pins can be a problem. So is this exactly what you have and you have them sandwiched?

Should that be the case up till now we can copy and paste the code here and look at it.
[CODE}
/* * This is the Arduino code for 4 Relay Arduino Shield * to control turn ON or OFF 4 AC or DC loads * Watch the video
* * * Written by Ahmad Nejrabi for Robojax Video * Date: Dec 28, 2017, in Ajax, Ontario, Canada * Permission granted to share this code given that this * note is kept with the code. * Disclaimer: this code is "AS IS" and for educational purpose only. * */

// Recorded Dec 27, 2017 by Robojax

#define relay1 7
#define relay2 6
#define relay3 5
#define relay4 4

void setup() {
Serial.begin(9600);
// setup Serial Monitor to display information

pinMode(relay1, OUTPUT);// connected to Relay 1
pinMode(relay2, OUTPUT);// connected to Relay 2
pinMode(relay3, OUTPUT);// connected to Relay 3
pinMode(relay4, OUTPUT);// connected to Relay 4
}

void loop() {
digitalWrite(relay3,HIGH);// turn relay 3 ON
Serial.println(" relay 3 ON");
delay(3000);// keep in relay 3 On for 3 seconds
digitalWrite(relay3, LOW);// turn relay 3 OFF
Serial.println(" relay 3 OFF");
delay(3000);// keep in relay 3 OFF for 3 seconds
}
[?CODE]

All that tells us is that digital pins are defined as outputs using pins 4, 5, 6 and 7. We turn a single relay, relay 3, on for three seconds then off for three seconds in a loop forever. The relay 3 LED should illuminate when relay 3 is on. Does it do that much. No motor and nothing connected to the board. Using the Arduino USB interface does the code load fine? The code is very basic so if this much works we can look at your wiring scheme but it would be nice to know if things work find up to this point.

The code sample included the video so sorry about that. :(

Ron

Ron
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
This should be your relay shield board. Would that be correct? Just like the one in the video. They call it a "shield" because the board is designed to be placed right on top of the Arduino Uno board. This is a nice feature because it eliminates the need for external wiring. This relay board also has small LEDs to let you visually see which relays are active. The male pins on the bottom of your relay board should mate with the female pins on the Arduino Uno board, they sandwich together. Be careful not to force things and make sure the pins align with their respective sockets. Bent pins can be a problem. So is this exactly what you have and you have them sandwiched?

Should that be the case up till now we can copy and paste the code here and look at it.
[CODE}
/* * This is the Arduino code for 4 Relay Arduino Shield * to control turn ON or OFF 4 AC or DC loads * Watch the video
* * * Written by Ahmad Nejrabi for Robojax Video * Date: Dec 28, 2017, in Ajax, Ontario, Canada * Permission granted to share this code given that this * note is kept with the code. * Disclaimer: this code is "AS IS" and for educational purpose only. * */

// Recorded Dec 27, 2017 by Robojax

#define relay1 7
#define relay2 6
#define relay3 5
#define relay4 4

void setup() {
Serial.begin(9600);
// setup Serial Monitor to display information

pinMode(relay1, OUTPUT);// connected to Relay 1
pinMode(relay2, OUTPUT);// connected to Relay 2
pinMode(relay3, OUTPUT);// connected to Relay 3
pinMode(relay4, OUTPUT);// connected to Relay 4
}

void loop() {
digitalWrite(relay3,HIGH);// turn relay 3 ON
Serial.println(" relay 3 ON");
delay(3000);// keep in relay 3 On for 3 seconds
digitalWrite(relay3, LOW);// turn relay 3 OFF
Serial.println(" relay 3 OFF");
delay(3000);// keep in relay 3 OFF for 3 seconds
}
[?CODE]

All that tells us is that digital pins are defined as outputs using pins 4, 5, 6 and 7. We turn a single relay, relay 3, on for three seconds then off for three seconds in a loop forever. The relay 3 LED should illuminate when relay 3 is on. Does it do that much. No motor and nothing connected to the board. Using the Arduino USB interface does the code load fine? The code is very basic so if this much works we can look at your wiring scheme but it would be nice to know if things work find up to this point.

The code sample included the video so sorry about that. :(

Ron

Ron
Thank you for responding, yes I have seen that the code and hardware work. The problem I am running into is that I have a recharable energy shield and I want to be able to use it as an external source to power the relay.
 

ebeowulf17

Joined Aug 12, 2014
3,274
Thank you for responding, yes I have seen that the code and hardware work. The problem I am running into is that I have a recharable energy shield and I want to be able to use it as an external source to power the relay.
The description in post 23 is perfect. If you can wire that up, try it. If you need a visual aid to get started, I'm sure several of us here can make one... although I can't do it until later tonight at the earliest.
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
A visual aid would be very niceQUOTE="ebeowulf17, post: 1488138, member: 245586"]
The description in post 23 is perfect. If you can wire that up, try it. If you need a visual aid to get started, I'm sure several of us here can make one... although I can't do it until later tonight at the earliest.
[/QUOTE]
A visual aid would be very nice and I don't mind the wait. Thank you!
 
I'm going to pretend I just read the first post.

there is motor selection, power source, torqe requirements

Since DC was mentioned, let's say the following:
With a DC motor, torque is proportional to current.
Unloaded voltage is proportional to speed.
You have to actively do speed control.
PWM controls speed at little torque. variation.
DC motors act as generators when unloaded.
DC motors coast when turned off.

There are basically 4 modes
fwd
rev
brake
coast

I'll also mention regenerative braking.

two SPDT relays for each motor with properly rated contacts can do fwd, rev and brake.
PWM and speed feedback can do speed control.

Look up "H-bridge"

I'll also mention limit switches. For 2-relay soluton, the limit switch needs to carry the relay coil current. Contacts, the braking current.
 

Reloadron

Joined Jan 15, 2015
5,509
Thank you for responding, yes I have seen that the code and hardware work. The problem I am running into is that I have a recharable energy shield and I want to be able to use it as an external source to power the relay.
In that case if you have an external energy shield like this one you should be able to stack the relay board above the energy shield. The energy shield will then power the Arduino and the relay card. Have you tried that or am my just missing things here?

Ron
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
A visual aid would be very niceQUOTE="ebeowulf17, post: 1488138, member: 245586"]
The description in post 23 is perfect. If you can wire that up, try it. If you need a visual aid to get started, I'm sure several of us here can make one... although I can't do it until later tonight at the earliest.
A visual aid would be very nice and I don't mind the wait. Thank you!
[/QUOTE]
In that case if you have an external energy shield like this one you should be able to stack the relay board above the energy shield. The energy shield will then power the Arduino and the relay card. Have you tried that or am my just missing things here?

Ron
Yes and that is the exact one I use too, I tried to stack it but I think I have to program the shield itself.
 

djsfantasi

Joined Apr 11, 2010
6,521
In that case if you have an external energy shield like this one you should be able to stack the relay board above the energy shield. The energy shield will then power the Arduino and the relay card. Have you tried that or am my just missing things here?

Ron
Just to make a minor point. The energy shield could provide power to the Arduino and the relay shield, BUT IT WON’T PROVIDE POWER TO THE RELAY CONTACTS AND HENCE THE MOTOR. If the power from the energy shield has enough power for the motors through the relay contacts (and possibly the relay coils), additional wiring is necessary.

This has been implied, but not stated explicitly. There are three requirements for power.
  1. The Arduino and it’s shields
  2. The relay coils. On these relay shields, the Arduino is used to switch a stronger power source required for the relays
  3. The load switched by the relays. A relay shield is often used because the power required by the load greatly exceeds the Arduino and relay coil power. In both voltage and current.
 

Reloadron

Joined Jan 15, 2015
5,509
There should be no programming of the energy shield involved. There is nothing there to program that I can see. It provides power and has the necessary circuitry to charge its power source a LiPo battery using a micro-USB port.

Just to make a minor point. The energy shield could provide power to the Arduino and the relay shield, BUT IT WON’T PROVIDE POWER TO THE RELAY CONTACTS AND HENCE THE MOTOR. If the power from the energy shield has enough power for the motors through the relay contacts (and possibly the relay coils), additional wiring is necessary.

This has been implied, but not stated explicitly. There are three requirements for power.
  1. The Arduino and it’s shields
  2. The relay coils. On these relay shields, the Arduino is used to switch a stronger power source required for the relays
  3. The load switched by the relays. A relay shield is often used because the power required by the load greatly exceeds the Arduino and relay coil power. In both voltage and current.
Oh no and absolutely I agree and should have pointed that out. The relay contacts and their use is a separate entity all on its own.

Ron
 

Thread Starter

Killerbee65

Joined May 15, 2017
222
Just to make a minor point. The energy shield could provide power to the Arduino and the relay shield, BUT IT WON’T PROVIDE POWER TO THE RELAY CONTACTS AND HENCE THE MOTOR. If the power from the energy shield has enough power for the motors through the relay contacts (and possibly the relay coils), additional wiring is necessary.

This has been implied, but not stated explicitly. There are three requirements for power.
  1. The Arduino and it’s shields
  2. The relay coils. On these relay shields, the Arduino is used to switch a stronger power source required for the relays
  3. The load switched by the relays. A relay shield is often used because the power required by the load greatly exceeds the Arduino and relay coil power. In both voltage and current.
So questio
There should be no programming of the energy shield involved. There is nothing there to program that I can see. It provides power and has the necessary circuitry to charge its power source a LiPo battery using a micro-USB port.



Oh no and absolutely I agree and should have pointed that out. The relay contacts and their use is a separate entity all on its own.

Ron
Could I possibly hook up the 5v pin to NO and connect one motor connection to COM and the other to the corresponding points on the board? (7, 6, 4, 5)
 

Reloadron

Joined Jan 15, 2015
5,509
So questio

Could I possibly hook up the 5v pin to NO and connect one motor connection to COM and the other to the corresponding points on the board? (7, 6, 4, 5)
I would not but only because of concerns as to what the motor current draw is and how much current can be drawn on they pin also if this is a small brush type motor the noise it would put in the system. I am not saying it won't work. If this is a 5 volt motor with a low current draw it will likely work. Since I have not read every post and if the motor specs were covered I don't know them, sorry. Anyway will it work? Likely if the motor has the right specs. Will I suggest doing it? No, but only for the reasons stated.

Ron
 
Top