relay and switch problem

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)

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

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

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)

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);
  }

}

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

For future reference:-

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.

Grumpy_Mike:
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.

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.

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.

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.

Grumpy_Mike:
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”.

I can't speak for your Apple computer.

Then shut up about it.

If however you use the "view image" function of the browser,

There isn't one, it is a mobile device.

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.

Grumpy_Mike:
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!" :astonished:

Grumpy_Mike:
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?

Grumpy_Mike:
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!

Chagrin:
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 :roll_eyes: ).

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

Ah, I was correct then. :grinning:

Grumpy_Mike:
Then shut up about it.

Says it all.

How has any of this been helpful to the OP?

Paul forgot to mention he has a 96 inch wraparound monitor. :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes: ROFL.

pwillard:
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.

pwillard:
How has any of this been helpful to the OP?

The problem here; the common problem, is getting those who come here for help to post sufficient information - and that in a meaningful form - for those of us who are evaluating their situation to form an adequate picture to actually provide that help.

Now this is not helped by the obtuse behaviour of the forum. We are told (as I cited in the other thread) that this is supposedly to inhibit spam, or to cope with the attachment of over-size images, or some such. In any case, the consequence of this deliberate mis-configuration (and it is deliberate) is that attachments are completely useless to many people and yes, I am one such where I am using a system other than Windoze. On some systems attachments (only from this forum) will neither load nor download.

So am I advised not to help people who supply information in attachments? Well, notwithstanding Mike's insistence that I am always talking through my hat, I do believe I have things to contribute.

But it goes beyond that.

It really is much easier to evaluate problems if we have the illustrations inline, and the code inline. I know I am not the only one who is reluctant to take a ".ino" file in an attachment, download it and bring up the IDE just to inspect it - though it is the case that if the forum was correctly configured, this would probably happen automatically. (Mind you, the later versions of the IDE also insist on saving the code somewhere locally even just to test-compile it.)

And that is the basis of my complaint - in reply #5. Having the image inline is exactly where it needs to be and there was in this case, no lack of resolution; it is just that the forum - not unreasonably - initially shows it with reduced magnification in order to meld it in with the text.

But the full image is already there - you can either use "view image" to inspect it in full detail, or if on a mobile/ tablet device you use the "pinch/ expand" two-finger gesture - the subject of some serious patent-trolling as I understand - to enlarge that complete image to the available pixel resolution of the particular device, spilling beyond the display frame as necessary. Really, that is surely simple enough, just part of using your browser.

So all I am seeking is to encourage posters to provide that necessary information in the most usable form - and indeed for all viewers.

Well, I guess we can't help that this has now become a how-to thread about attachments.

Regarding:

It really is much easier to evaluate problems if we have the illustrations inline, and the code inline.

I can't stress enough how much I agree with this comment and how I find the current options (changes) infuriating. So I guess I am a supporter of your opinion.

I would guess you have loading problems. For 4 relays activated, the 4 opto leds would draw about 80mA and your relay status sensing would draw about 90mA, so that makes 170mA total. I doubt you'll get that from your arduino if it is powered by 12V. Try replacing the 220 ohm resistors with something around 1K to 10K, or power the arduino with around 7.5VDC to 9VDC, or do both.

Is your relay board adequately powered? You'll need more than 500mA for this board. Go with 1A or greater @5VDC.