Go Down

Topic: relay and switch problem (Read 2701 times) previous topic - next topic

georgfinch

Hi All,

I am making a switch box out of arcade controls that depending on combinations activates a relay.
I have a 8 relay board which I have read up on and am powering separately to the arduino.
 (activates on LOW)
 http://www.ebay.co.uk/itm/252192309090?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

My problem is that it all works fine with up to 4 switches connected and read by the arduino digital inputs (all have 10k pulldown resistors, also tried as pull up). As soon as I add a 5th switch some will activate the relays but not all.

I have simplified my code down to trouble shoot and currently have only one relay connected on digital 2 with if statements in my code to detect button presses.

I don't currently have debounce (still trying to get my head around the concept)

any ideas what I need to do? Eventually I need 10 switches connected, which all works with LEDS to test the code but more than 4 switches and the relays don't activate

cheers

Grumpy_Mike

You need to post the minimum sketch that is failing and post a schematic of how you wired it ALL up.
Please do not post a physical layout diagram but a schematic. Hand drawn is fine

georgfinch

hope this makes sense, (first time using Fritzing)


section on the right is to represent the relay board, (it has two blocks of pins). It has it's own power supply

I have only included one switch setup, this is replicated to pins 8, 9, 10, 11, 12
I get the same results if the resistor is on the ground side (with the code changed to detect HIGH)
The resistors are all 10k (didn't realise I could change that in Fritzing)

Code: [Select]

void setup() {
//output pin to relay
pinMode (2, OUTPUT);
////Input pins from buttons
pinMode (8, INPUT);
pinMode (9, INPUT);
pinMode (10, INPUT);
pinMode (11, INPUT);
pinMode (12, INPUT);
pinMode (13, INPUT);
}

void loop() {
  // check if buttons are pressed
if (digitalRead(8)==LOW)
  { 
    digitalWrite (2,LOW);
  }
if (digitalRead(9)==LOW)
  { 
    digitalWrite (2,LOW);
  }
 if (digitalRead(10)==LOW)
  { 
    digitalWrite (2,LOW);
  }
 if (digitalRead(11)==LOW)
  { 
    digitalWrite (2,LOW);
  }
 if (digitalRead(12)==LOW)
  { 
    digitalWrite (2,LOW);
  }
 if (digitalRead(12)==LOW)
  { 
    digitalWrite (2,LOW);
  }

///set the relay off
 else
  {
  digitalWrite (2, HIGH);
  }

}

georgfinch

Solved it......

So for anyone else..... It was the if statements, by having a pile of these only the first and last if statement sent the right signal. Changing them to if else statements now works

Grumpy_Mike

For future reference:-
Quote
section on the right is to represent the relay board, (it has two blocks of pins). It has it's own power supply
There is no common ground shown. You must have one or else it would not have worked. The image is too small to see and people here don't like using third party web sites that require you to log in. Just attach your image, if you don't know how then please read this:-
How to use this forum

The actual code could have been written in about 9 lines if you learn about arrays.

Paul__B

The image is too small to see and people here don't like using third party web sites that require you to log in. Just attach your image,
Oh for goodness' sake!!

This image is submitted absolutely correctly, it is the correct size, shows perfectly well when you use "view image" and does not requre login.

And the absolutely last thing we want is for people to attach images (or code as ".ino") as the nuisance setup of the forum obfuscates them and prevents correct file association or even viewing in the browser or even downloading for many people.


Grumpy_Mike

Paul, how the hell do you know what size the image is on my device. And the website it was posted on did not allow enlargement.
Coming from the only one on the forum who can't cope with attached images this is a bit ritch.

Paul__B

Paul, how the hell do you know what size the image is on my device. And the website it was posted on did not allow enlargement.
I can't speak for your Apple computer.

All I know is the HTML in which it is written.  Viz:

<img src="http://i246.photobucket.com/albums/gg112/sweety-georg/basic_switch_zpsltfdfzi4.png" alt="" width="500" height="281" class="bbc_img resized">

Now if you understand HTML, you know that this means that the browser loads the whole image, but is instructed to render it as 500 by 281 pixels - in order to fit within the text area.

If however you use the "view image" function of the browser, it will show the exact same file reference in its actual size (though you may need to click on it if it shows a little "plus magnifier" on my browser).  The actual size is 1024 by 576.

I do admit that "photobucket" plays fast and loose, and was doing some strange things as I researched this, and I certainly recommend people do not use it.

Coming from the only one on the forum who can't cope with attached images this is a bit rich.
You may be confusing "only one" with "one who makes a point about it".

Grumpy_Mike

#8
Dec 14, 2015, 10:05 pm Last Edit: Dec 14, 2015, 10:07 pm by Grumpy_Mike
Quote
I can't speak for your Apple computer.
Then shut up about it.

Quote
If however you use the "view image" function of the browser,
There isn't one, it is a mobile device.

Quote
You may be confusing "only one" with "one who makes a point about it".
No, the moderators have no idea what you are talking about, nether do the web developers, and I have not come across a single person who does.

So stop whinging and if you are so clever sort it out, it is your problem.

Paul__B

#9
Dec 15, 2015, 04:20 am Last Edit: Dec 17, 2015, 07:35 am by Paul__B Reason: Missing link
There isn't one, it is a mobile device.
So you are actually complaining about the shortcomings of your mobile device - or your inexperience with using it?  Now that really takes the cake.  If ever there was a case of "Pot calling the kettle black!" :smiley-eek:

No, the moderators have no idea what you are talking about, nether do the web developers, and I have not come across a single person who does.
Then it seems your confabulation has reached yet new heights of absurdity, because the moderators most certainly do know what I am talking about, as do the "web developers" because it was thoroughly discussed last March and set aside as merely yet another amongst the plethora of known bugs in the system.  And again, that you have "not come across a single person" indicates nothing more than your lack of awareness of the wider compass of this forum.

Mind you, I very much doubt you actually discussed this with anyone, or am I not the only one you have flamed in a PM?

So stop whinging and if you are so clever sort it out, it is your problem.
Well, tell that to this guy, and the others on that thread, for a start!

That's actually how the forum is set right now, Paul, and it's not a problem with your system or browser.
Perhaps they know more about HTML than you do (or indeed, I :smiley-roll: ).

Grumpy_Mike

My my, tiny temper.
You are such a well balanced individual. You have a chip on both shoulders.

Paul__B

Ah, I was correct then. :smiley-lol:

Then shut up about it.
Says it all.

pwillard

How has any of this been helpful to the OP?

outsider

Paul forgot to mention he has a 96 inch wraparound monitor.  :smiley-yell: :smiley-yell: :smiley-yell: ROFL.

Grumpy_Mike

How has any of this been helpful to the OP?
Quite simply it hasn't.
I wish he would stop sniping and get down to the proper task of this forum - to help people.

Go Up