problems with 5 volt relay module

Hey folks, I’m new to arduinos and I have some questions that I haven’t been able to find answers for. In the project I’m working on I am using a 5volt relay module to control a 6 volt motor (on its own circuit obviously). The problem I am having is when I hook up the relay, it makes a constant clicking noise. Also what is the jumper for? I’ve been just connecting the gnd to arduino gnd, in1 to one of the digital pins and the vcc to the 5 volt pin.

What Arduino are you using and how is it powered?

The clicking noise means the relay is being switched on and off constantly. Check your code.
And check the relay minimal voltage opetation. For low DC voltage is more common using transistor rather than relay.

Need a link to the relay vendor's website to answer your question.
Also, if you want us to answer questions about the operation of your code you need to post the code.
Without a schematic and your code we can't help you. ( I don't know what "Jd -Vcc" means without looking at the documentation for the relay board). I will tell you this, if you use serial print statements with your relay commands you can find out if your program is telling the relay to turn on and off.

Alright, so the Arduino board I am using is an Uno and it is being powered by usb.
Here is the link to the relay board.

and the code I am using is,

#define relay 2
#define button 7

int val = (2);

void setup(){
  pinMode (relay, OUTPUT);
  pinMode (button, INPUT);
  digitalWrite (relay, HIGH) ;
}
void loop() {
  val = digitalRead (button);
  if (val == HIGH) {
    digitalWrite (relay, LOW);
    }
  else {digitalWrite (relay, HIGH);
    }}

I should have mentioned this in the first post but, I am trying to control the relay with the push of a button connected to a digital pin.

Also, The relay is doing this constant on/off thing even when I have no circuit running through it.

JD-Vcc is the label for the relay coil power. The jumper connects the Vcc to the + terminal of the relay because they are 5V relays.
You need to add those serial print statements I mentioned. What you have told us so far doesn't tell us anything .
If you don't know how to add the serial prints , say so.

The relay is doing this constant on/off thing even when I have no circuit running through it.

If by "circuit running through it" you mean something connected to the contacts, I don't see how that is relavant.

What exactly does "circuit running through it" mean ?
Does it mean power applied (+5V power on) ?
Does it mean something connected to the contacts ?
Does it mean when the code is not running ?

There is a document on the Sainsmart website named "SainSmart UNO Starter Kits Tutorials.pdf". Download this PDF file and do a search for "relay". Here is some of the info:
"Keep the jumper connecting JD-VCC pin to VCC pin on the relay board’s jumper. This allows for the Uno to supply both of the opto-isolator chips and the two relay switches with power, see Figure 19.2 for details. If you are going to connect two or more of these modules to a single Uno, then you would want to remove this jumper and supply the JD-VCC and common ground with a separate +5v power supply."

@ oldvettguy,
Good find.

BTW,
289 or 427 (cu in) ? (what yr ?)

What I mean, is it makes this noise when I have nothing connected to the contacts. And I don't know how to do serialprints.

grumperpuss:
What I mean, is it makes this noise when I have nothing connected to the contacts.

I’m wondering if the current to the relay coil (as distinct from the contacts) is insufficient and it’s basically cutting in and out?

And I don’t know how to do serialprints.

Have a look at this. Sprinkle Serial.print("blah blah"); in appropriate parts of the code and you’ll know where the logic of the program is taking you.

Your relay problem might be related to your input button logic or wiring issues, such as debouncing.

You need to consider these issues separately.

write another sketch with no button in it, just the relay.

Like this.

const int relaypin = 9 ;

bool state=false ;

void setup()
{
pinMode( relaypin, OUTPUT );
}

void loop()
{
    if ( !state )
    {
        state=true ;
        digitalWrite( relaypin, HIGH );
       delay(1000);
   }
   else
    {
      state=false ;
      digitalWrite( relaypin, LOW );
      delay(1000) ;
    }
}

This will try to turn the relay on and off each second.

You can worry about debugging and debouncing your button circuit, separately.

raschemmel:
@ oldvettguy, Good find.
BTW, 289 or 427 (cu in) ? (what yr ?)

1959, 572 cu.in. 59 Frame Conversion
I haven't updated the website lately, so you will not see how I used the Arduino in the car.

@oldvettguy,
AWESOME!

@grumperpuss,
I think if you one of the relay inputs and connect the other input to output D13 and run the IDE Blink example you will find that the clicking you heard before is not there and the relay connected to D13 clicks once every second, which would confirm that the issue is software related rather and not caused by hardware.

Thanks for all the help guys, It turns out my problem was I was missing a resistor for my button.

Now another question I have is, since the circuit i'm using the relay for is only 6 volts, do i need to put a diode on the ground line?
(forgive me if i sound like a fool)

in my research on relays, alot of people are using them for high voltage circuits and they are putting diodes and resistors in the circuit to protect the arduino from getting fried.

Always place a diode across a DC coil if it is powered with unipolar supply.

And with inverted polarity, else you'll have a short.

http://www.davidbridgen.com/coil%20diode.htm

Okay, so I'm still a little fuzzy on where the diode would go in the circuit.
Would it be wired in parallel with the ground?
And what is unipolar?
Sorry if I seem like I know nothing, a lot of this is just very new to me.

Can you read a schematic (the link) .
It shows the cathode (banded end of the diode) goes to the + terminal of the relay coil and the anode goes to the “neg” or minus terminal of the coil. A flyback diiode ALWAYS goes ACROSS the inductive device with the CATHODE at the POSITIVE SIDE . An INDUCTIVE device is a relay coil, a solenoid, motor , etc.
Look at the schematic again.

So even with a relay module, I would need to have a diode in place, if so would it go between the vcc and ground, or would it be between the. Pos and neg of the circuit on controlling?