# 8 relay shield Octo Banger (Mike's) not doing what I want (banger.com)



## Bosco P. Soultrane (Sep 11, 2015)

If you want ambient music and a relay sequence that is not triggered, you probably don't need the octobanger except to time out the sequences (easier for a newbie since it has sliders you can move). 

It would be a simple to write a program in a loop with the sequence you desire. The ambient sound could run separately on a mp3 player or cd player in a loop if it doesn't need to be run at a certain time.

I could write a code for you, but I won't be able to until I get back from vacation next week. If you have an idea of what you want to happen, send it to me in pseudo code, ie. 

1) all relays off. 
2) relay 1 on for 10 seconds. 
3) relay 1 off. 
4) relay 2 on for 3 seconds. 
5) relay 2 off. 
6) relay 3&4 on for 12 seconds.
etc....


----------



## fluffy...man (Jul 23, 2017)

Good Morning, Many thanks for your offer and reply, Sorry for the delay in replying, It's 07:00 here in the UK, Just peeled my eyes open, and the first thing I did was to check for any replies, that's how much this unit is doing my head in. Ha Ha.
I have been building Pneumatic Props since last years display, this year it will be in aid of Charity. I will have to check each prop and time them to make sure the relays operate for the correct length of time. (last thing I want is my Coffin to begin opening, and my skeleton to begin rising then just not get to the end of sequence) that's why I went for the Octo banger, the timing was adjustable. Trial and error principle. And if my wife changed her mind (like they do) in which prop would activate and in what order, I just moved the sliders on the programme accordingly. Ho Hum..................
Because the Arduino is using the A2 socket to operate the serial MP3 player (5v and ground) with it's integral SD Card could this be switched on as soon as the board is powered up? Then have the relays operate after a 15second boot time delay for instance? 
So far I have the Arduino wired to the Serial MP3 player with built in SD Card then through a 50w amplifier then to a speaker. 
Cheers Mark.
Cheers.Mark


----------



## J-Man (Feb 1, 2011)

As another option for what you're doing is a simple cycle timer relay for each prop. These would also eliminate running wires to each prop from a single controller. Just play your ambient sound track from any source.
http://m.ebay.com/itm/12V-Timing-De...1888353743?epid=526385567&hash=item569645f1cf


----------



## fluffy...man (Jul 23, 2017)

These style of relays are how I first started, it meant I would need to turn on each prop in a timely manor. Then I found the Octo Banger which offered me everything. just Too much. All I wanted to do was loose they scare and keep everything on a loop. I even contacted some companies for Electronics/Computers here in the UK regarding this. They weren't interested. Just thought I was mad. Are we???????????? Why is Halloween a strange hobby? others celebrate Xmas. Boring.......everyone is doing that.
I got the Jawdunio functioning, from Banger.com, just need to install it into a Skull next.


----------



## Bosco P. Soultrane (Sep 11, 2015)

Once i write the code i can tell you where to change the timing, it's easy. Then you can change and test, change and test until you get it the way you want.
I am not sure about the sound, will have to look into it when i get back home.


----------



## Bosco P. Soultrane (Sep 11, 2015)

if you want to give it a go on your own, here is a place that gives you a background about the relays and some sample code. 
http://arduino-info.wikispaces.com/ArduinoPower#4-8

The code for the 4 relay unit would be good as a starter, load it on your arduino and hook up the relay board. The leds on the relay board should turn on off in the programmed sequence. you will find that all you have to do is add the 4 other relays, then manipulate the delay to what you need.


----------



## fluffy...man (Jul 23, 2017)

Many Thanks for all your help.
Its lovely to have someone taking the time out of there busy life for others.
I will give it a go, just not sure when. I'm pulling 12Hr shifts at work at the moment, It's a long day in a hot commercial workshop. I have ordered the 4 relay shield that fits directly on top of the Uno (well looks like it does on the picture anyway) so hopefully that will save time in construction. Ha Ha, 
I must remember to load the firmware first before assembly, :-[
Watch this space.....................It maybe empty for a long time.........................or Nicki (the wife) will be posting my last will & testament fingers crossed all goes well. Have a lovely Holiday / Vacation.


----------



## fluffy...man (Jul 23, 2017)

Many Thanks for all your help.
Its lovely to have someone taking the time out of there busy life for others.
I will give it a go, just not sure when. I'm pulling 12Hr shifts at work at the moment, It's a long day in a hot commercial workshop. I have ordered the 4 relay shield that fits directly on top of the Uno (well looks like it does on the picture anyway) so hopefully that will save time in construction. Ha Ha, 
I must remember to load the firmware first before assembly, :-[
Watch this space.....................It maybe empty for a long time.........................or Nicki (the wife) will be posting my last will & testament fingers crossed all goes well. Have a lovely Holiday / Vacation.


----------



## fluffy...man (Jul 23, 2017)

Oh dear, you have done it now.......the link you supplied is a good one,
some of the links on the page don't work but I motor reverse relay set up they discus would be good for my riser which has a my take on a linear motor set up. Basically a 1m 10mm threaded bar rotated by a 24v DC Motor. The wife's witch is attached to the threaded bar. The bar turns, the witch goes up or down depending on the rotation. The Arduino would make switching rotation of the DC motor more user friendly especially with a PIR for switching.
The mind boggles....
Now I'm getting ahead of myself, time to draw back and get the basics under control.


----------



## fluffy...man (Jul 23, 2017)

tried some code. FAILED. just keep getting: for example.
exit status 1
'Relay_1' was not declared in this scope
Gonna go and read a French Novel, I may understand it better. Ha Ha.


----------



## lizzyborden (Sep 17, 2009)

I've downloaded the octobanger files but I'm still trying to wrap my head around the fourbanger project. In the fourbanger files there is a file named Sounds and within that file are 3 mp3 files, one which is silence. I don't see that folder in the octobanger files though. You could download the fourbanger files, get the silence mp3 and set it as your scare track. You could keep the ambient file that way. As far as looping it, that's way out of my league. 

Also do you have a link to the 5v 8-relay module you used? I'm thinking of going ahead and getting the parts for an octobanger while I have a little extra cash.


----------



## Bosco P. Soultrane (Sep 11, 2015)

Did you copy/paste it from the website I linked? I just did and it compiled with no errors.
Make sure it was copied correctly. If Relay_1 was not declared, most likely the #define Relay_1 was not copied correctly. Did the '#' symbol copy correctly?
Everything should look like this:

/* YourDuino Example: Relay Control 1.10
Handles "Relay is active-low" to assure
no relay activation from reset until
application is ready.
[email protected] */

/*-----( Import needed libraries )-----*/
/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3
#define Relay_3 4
#define Relay_4 5

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF); 

//---( THEN set pins as outputs )---- 
pinMode(Relay_1, OUTPUT); 
pinMode(Relay_2, OUTPUT); 
pinMode(Relay_3, OUTPUT); 
pinMode(Relay_4, OUTPUT); 
delay(4000); //Check that all relays are inactive at Reset

}//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Turn all 4 relays ON in sequence)---
digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second 
digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
delay(4000); // wait see all relays ON

//---( Turn all 4 relays OFF in sequence)--- 
digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second
digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second 
digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
delay(1000); // wait for a second
digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
delay(4000); // wait see all relays OFF 


}//--(end main loop )---

//*********( THE END )***********


----------



## fluffy...man (Jul 23, 2017)

Here is the link I used for the 8 relay shield. I bought two of them. 1 to break and 1 to use. I did the same with the Arduino Uno boards. Bought more than one at a cheap price. fried one and learn't the hard way. then used the others. I found it cheaper and a learning curve doing it this way, rather than buying an expensive prop controller.

http://www.ebay.co.uk/itm/8-Channel...e=STRK:MEBIDX:IT&_trksid=p2057872.m2749.l2649


----------



## fluffy...man (Jul 23, 2017)

I have even copied you pasted copy, pasted it into the Arduino sketch software/programme clicked on the Verify Button at the top left screen and received this:

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Mark\Documents\Arduino\sketch_jul26a\sketch_jul26a.ino: In function 'void setup()':

sketch_jul26a:60: error: redefinition of 'void setup()'

void setup() {

^

C:\Users\Mark\Documents\Arduino\sketch_jul26a\sketch_jul26a.ino:18:7: note: 'void setup()' previously defined here

void setup()/****** SETUP: RUNS ONCE ******/

^

C:\Users\Mark\Documents\Arduino\sketch_jul26a\sketch_jul26a.ino: In function 'void loop()':

sketch_jul26a:65: error: redefinition of 'void loop()'

void loop() {

^

C:\Users\Mark\Documents\Arduino\sketch_jul26a\sketch_jul26a.ino:36:7: note: 'void loop()' previously defined here

void loop()/****** LOOP: RUNS CONSTANTLY ******/

^

exit status 1
redefinition of 'void setup()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I said reading a French Novel would make more sense. Doh!!!: mad:


----------



## fluffy...man (Jul 23, 2017)

I CAN READ FRENCH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
having persevered..............I copied the code and it was accepted. up loaded it to my board. WORKING!!
Then I copied and pasted each line and changed the relay numbers up all the way to 8
Found the first 4 Relays quicker than the 4-8 relays, then noticed 1-4 were 1000 and 4-8 were 4000, changed all to 1000, now they all work the same.
I'm chuffed about that bit.
must save the file then start playing around. how would I add a command to start up a MP3 card to run continuously?


----------



## lizzyborden (Sep 17, 2009)

fluffy...man said:


> Here is the link I used for the 8 relay shield. I bought two of them. 1 to break and 1 to use. I did the same with the Arduino Uno boards. Bought more than one at a cheap price. fried one and learn't the hard way. then used the others. I found it cheaper and a learning curve doing it this way, rather than buying an expensive prop controller.
> 
> http://www.ebay.co.uk/itm/8-Channel...e=STRK:MEBIDX:IT&_trksid=p2057872.m2749.l2649


Thanks! I bought a few of the unos last year and so far haven't fried one yet. Glad you got your controller working the way you wanted.


----------



## Bosco P. Soultrane (Sep 11, 2015)

fluffy...man said:


> I CAN READ FRENCH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> having persevered..............I copied the code and it was accepted. up loaded it to my board. WORKING!!
> Then I copied and pasted each line and changed the relay numbers up all the way to 8
> Found the first 4 Relays quicker than the 4-8 relays, then noticed 1-4 were 1000 and 4-8 were 4000, changed all to 1000, now they all work the same.


So now you know how to change the timing, it is in milliseconds, meaning 1000ms = 1 second. When you want to change the timing, this is what you would change.

I am sure you can figure out how to turn the relays on and off as needed.

I will work on the mp3 player part. 
There is an example online from github for the YX5300 player, i'll just need to modify the code so it will just play the one song in a loop. The problem is, you can start the mp3 playing, then do all the relay switching, but when the sequence is over, it will start from the beginning, and the mp3 will start from the beginning also. It would be easier if you made the relay sequence the same length as the music you are using.


----------



## Bosco P. Soultrane (Sep 11, 2015)

fluffy...man said:


> Oh dear, you have done it now.......the link you supplied is a good one,
> some of the links on the page don't work but I motor reverse relay set up they discus would be good for my riser which has a my take on a linear motor set up. Basically a 1m 10mm threaded bar rotated by a 24v DC Motor. The wife's witch is attached to the threaded bar. The bar turns, the witch goes up or down depending on the rotation. The Arduino would make switching rotation of the DC motor more user friendly especially with a PIR for switching.


For the clockwise/counterclockwise rotation, you would be using the relays, not the PIR. I thought you said you didn't want the PIR.

If you wire the relay 1 and relay 2 as shown, then it is a matter of turning on relay 1 for CW:

_digitalWrite(Relay_1, RELAY_ON);_

run for a certain amount of time:

_delay(2000);_

then turning it off:

_digitalWrite(Relay_1, RELAY_OFF);_

Then turn on relay 2 for CCW:

_digitalWrite(Relay_2, RELAY_ON);_

run for a certain amount of time:

_delay(4000);_

then turning it off:

_digitalWrite(Relay_2, RELAY_OFF);_


----------



## fluffy...man (Jul 23, 2017)

Ah missing abit here. I have more than one prop build on the go. The reverse polarity is for my riser,The PIR would operate the function of my riser. the 8 Banger is to operate all of the props. Would I be right thinking, 600,000 would be a minute?


----------



## fluffy...man (Jul 23, 2017)

How do I turn 2 relays on at the same time?
would I leave out the 'delay' command and go straight to turn the 2nd relay on?
Something like this:-

digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second 
digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
delay(1000); // wait for a second
digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
delay(1000); // wait see all relays ON

If this correct, does the same apply for switching off 2 relays at the same time?
and how long is a minute?

if the delay time is set for 1 minute, do I change the wording from 'wait for a second' to 'wait for a minute' Or if I want a delay of 1 1/2 minutes, what do I write for that command? 'wait for 1 minute 30 seconds' or 'wait for 90 seconds'

Sorry if it sounds a bit simple to most of you, but I am just a novice. And jumped straight in at the deep end without arm bands. Ha Ha................


----------



## Bosco P. Soultrane (Sep 11, 2015)

yes, leave out the delay command, they will both come on.
just so you know, anything after the "//" are comments, they are not part of the code, and aren't necessary. They are there to help you figure out what is going on. So, "// set the Relay ON" is not code, just comments.
1000 milliseconds equals 1 second. "milli = one thousand, just like the metric system with millimeters. so, there are 60 seconds in one minute, therefore, 60 X 1000, or 60,000. (DO NOT USE THE COMMA IN THE CODE, JUST 60000).
Now here is the kicker, Arduino doesn't really use a clock that good, so it probably won't be a minute, but I am trying to keep it simple for you since you are a novice. It would be better to use what is called "timers" but you are not ready for that.
You have probably figured out by now that the "//wait a second" is NOT code, but a comment, so you could change that to wait a minute if you like, but it doesn't matter, it is just a way to document what is going on with each line of code. Once you learn and build confidence, you won't need it.
The sample of code you wrote is telling the Arduino to:
turn on relay 1, turn on relay 2, wait one second, turn on relay 3, wait a second, turn on relay 4, wait a second. 
Understand?
If you have any trouble, you could always tell me what you want to happen, and i could check your code to make sure it looks good.


----------



## fluffy...man (Jul 23, 2017)

Thanks for helping to clear that up, as a beginner it all sounds double Dutch. I don't need my Props to be timed exact. Just a simple timed sequence would be better than all working at once. I'm still looking for some good music to play in the background of are display, It's so difficult finding something appropriate for young children and teenagers, then the mum's and dads. I think we need something light hearted and up beat, but with a twist of horror, almost cathedral or Gothic chant. 
Got any suggestions?
Oh.........then making and hooking up an MP3 player to the Arduino would be good, keeps it all together and tidy. know what I mean?
Cheers
Mark.


----------



## fluffy...man (Jul 23, 2017)

OK, got the hang of that bit, I have just built a 4 Relay Arduino for my Hidden EYE's that will be in our bush in the front garden. Gonna have 8 pairs of different coloured LED eyes, which are mounted in a cardboard tube (cut out the shape of eyes in the tube) stick foil to the inside of the tube to reflect the light and the LED's are mounted in the ends of the tube. Works wickedly. 

Any how, going back to the Octobanger.
Is there any way of retrieving the code from the Arduino which is installed with the Octobanger code ( 8 Relays, Ambient sound and Scare sound)
then modifiying it to take out the scare command?

Just an idea?
Cheers
Mark


----------



## Bosco P. Soultrane (Sep 11, 2015)

fluffy...man said:


> OK, got the hang of that bit, I have just built a 4 Relay Arduino for my Hidden EYE's that will be in our bush in the front garden. Gonna have 8 pairs of different coloured LED eyes, which are mounted in a cardboard tube (cut out the shape of eyes in the tube) stick foil to the inside of the tube to reflect the light and the LED's are mounted in the ends of the tube. Works wickedly.
> 
> Any how, going back to the Octobanger.
> Is there any way of retrieving the code from the Arduino which is installed with the Octobanger code ( 8 Relays, Ambient sound and Scare sound)
> ...


I can tell you how to make the eyes randomly turn on or off with predetermined limits, say randomly from 1-10 seconds. It would make it look less "programmed."

As for the octobanger, I don't have the code, I didn't write it.
You would have to ask the maker. Maybe he could put in a on/off button that would turn off scare sequence but run the rest of the sequence.


----------



## fluffy...man (Jul 23, 2017)

I sent Mike the builder of the Octobanger an E-Mail some time ago but never got a reply. One thing I did find out mainly by accident, I used the 4 banger code and adjusted it and the variables to accept 8 relays. used the Arduino IDE programme to verify the code that bit was OK, then when I attempted to upload it to my board it failed on more than one attempt. I then used and uploaded the firmware that is included in the Octobanger build instructions, then uploaded the code I played around with and hey presto. it worked. How the firmware made a difference, I haven't got a clue, but who cares.......it worked and that's good enough for me at this stage.
Here is the code I put together for the 4 Banger for my Blinking Eyes, (remember 2 Pairs of eyes for each relay) then I'll scatter 8 pairs of eyes randomly in the Tree.
Your advice would be great.......and if your idea/code would work better than my attempt then I would say......YES please.!!!!!!!!!!!!!!!!!


```
/*Blinking Eyes V2: Relay Control 1.10
    [email protected]*/

/*-----( Import needed libraries )-----*/
/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1  7  // Arduino Digital I/O pin number
#define Relay_2  6
#define Relay_3  5
#define Relay_4  4

void setup()   /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  digitalWrite(Relay_3, RELAY_OFF);
  digitalWrite(Relay_4, RELAY_OFF);  
  
//---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  pinMode(Relay_2, OUTPUT);  
  pinMode(Relay_3, OUTPUT);  
  pinMode(Relay_4, OUTPUT);    
  delay(100); //Check that all relays are inactive at Reset

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{

  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(470);              // wait for a second
  digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
  delay(375);              // wait see all relays ON
  digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait see all relays OFF
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(100);              // wait for a second 
  digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
  delay(400);              // wait for a second
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(650);              // wait for a second
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(100);              // wait for a second 
  digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
  delay(250);              // wait for a second
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(350);              // wait for a second
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(100);              // wait for a second  
  digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
  delay(430); 
  digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
  delay(470);              // wait for a second
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(550);              // wait for a second
  digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
  delay(160);
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait for a second
  digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
  delay(480);
  digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
  delay(100);              // wait for a second
  digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait for a second 
  digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
  delay(600);              // wait see all relays ON
  digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
  delay(300);              // wait for a second
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(400);              // wait for a second
  digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
  delay(350);              // wait for a second
  digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait see all relays OFF 
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(350);              // wait for a second 
  digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
  delay(450);              // wait see all relays ON
  digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait see all relays OFF 
  digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
  delay(500);              // wait for a second
  digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
  delay(800);              // wait for a second
  digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
  delay(700);              // wait see all relays ON
  digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
  delay(200);              // wait see all relays OFF 
  digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
  delay(350);              // wait for a second
  digitalWrite(Relay_3, RELAY_OFF);// set the Relay OFF
  delay(100);              // wait for a second   
  
}//--(end main loop )---

//*********( THE END )***********
```
Booooooo, raining again here in the UK, If I were a Duck....I'd be in heaven, 
Did you have a good Holiday? sorry.....Vacation.....


----------



## Bosco P. Soultrane (Sep 11, 2015)

Yeah, so what you did in your code was kinda make it random by assigning all kinds of different times. Which is cool, and if you like it, then leave it like that.
SO when I made my popcorn popper, I wanted a random delay between "pops" to make it realisitc. To randomize the time, you would simply substitute:

delay(random(250));

instead of the delay(xxx); you have now. what the random does is give a random range of time for the delay. Here, it is random between 1 msec and 250 msec. it could be 34msec, 157 msec, ... etc, etc... in this instance, 250msec is the maximum.
You could also set a range, with a minimum and a maximum. Just use:

delay(random(100,500);

this would give you a random delay between 100-500 msec.

I hope you understand.
If you want to know a little about the arduino code, you could go to the website, https://www.arduino.cc/en/Reference/Random

you can learn about other things you can do with arduino.


----------



## fluffy...man (Jul 23, 2017)

You would make a good teacher, Your explanations are very understandable, and your choice of words are nice and simple for a dumb *** like me. As I have said before, this Arduino stuff is all new to me. I'm a Master Tech for VW Commercial, so the mechanical and Pneumatics are like second nature for me, but electronics are in a different Galaxy......
I'll have ago at your 'Random' suggestion, and run it past the wife for her approval. She did pass comment on my attempt for coding, in as much to say it was very 'computerised' I think she meant...... nice try, but not what I was hoping for, (she was being polite.......I hope !!!! Ha Ha) 
So if I am correct in thinking, I could reduce the code down to listing the basic 4 relay steps of ON/OFF and set the times for both the ON/OFF to 'Random'


----------



## Bosco P. Soultrane (Sep 11, 2015)

fluffy...man said:


> So if I am correct in thinking, I could reduce the code down to listing the basic 4 relay steps of ON/OFF and set the times for both the ON/OFF to 'Random'


Yes. Now you're getting it. This is very rudimentary code, but it does get the job done and you are just starting out.

What I did to learn arduino coding was to set-up an arduino with 8 leds. Then I would write code to get them to do different things. This way you can have a small set up on a desk and write code, upload it, see how it worked, then test it again using different methods. Since you have the 8-relay, it has LEDs that light up and they also click. Hooking up an arduino to them would also help you learn how to control them. 

For instance, when you look at the code you are using, it states:

#define RELAY_ON 0
#define RELAY_OFF 1

You actually do not need this in your code. What it does is it declares RELAY_ON to be 0 and RELAY_OFF to be 1.
You could just replace all "RELAY_ON with a 0 and it would work. You could replace 0 with "LOW" and it would work.
Just the same, you could replace RELAY_OFF with 1 or HIGH.
The reality is if you had an LED, you would want to use '1' or 'HIGH' to turn it on, and '0' or 'LOW' to turn it off.
But this 8-Relay module is set up to be the opposite, which is why low is on and high is off.

Here I took some of your code and rewrote it. I took the RELAY_ON and RELAY_OFF right out of the code.
See how 0 = LOW and 1 = HIGH? They are interchangeable, even within the code. 

/*-----( Declare Variables )-----*/
#define Relay_1 7 // Arduino Digital I/O pin number
#define Relay_2 6
#define Relay_3 5
#define Relay_4 4

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, 1);
digitalWrite(Relay_2, 1);
digitalWrite(Relay_3, 1);
digitalWrite(Relay_4, 1); 

//---( THEN set pins as outputs )---- 
pinMode(Relay_1, OUTPUT); 
pinMode(Relay_2, OUTPUT); 
pinMode(Relay_3, OUTPUT); 
pinMode(Relay_4, OUTPUT); 
delay(100); //Check that all relays are inactive at Reset

}//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/
{

digitalWrite(Relay_1, LOW);// set the Relay ON
delay(470); // wait for a second
digitalWrite(Relay_4, 0);// set the Relay ON
delay(375); // wait see all relays ON
digitalWrite(Relay_4, 1);// set the Relay OFF
delay(200); // wait see all relays OFF
digitalWrite(Relay_1, 1);// set the Relay OFF
delay(100); // wait for a second 
digitalWrite(Relay_3, LOW);// set the Relay ON
delay(400);  // wait for a second
digitalWrite(Relay_1, 0);// set the Relay ON
delay(650); // wait for a second
digitalWrite(Relay_1, HIGH);// set the Relay OFF
delay(100); // wait for a second 
digitalWrite(Relay_3, HIGH);// set the Relay OFF
delay(250); // wait for a second
digitalWrite(Relay_1, 0);// set the Relay ON
}//--(end main loop )---

//*********( THE END )***********


RELAY_ON is just a name. You could just as well call them dog and cat.
you would declare:
#define cat 0
#define dog 1

then you could write code that looked like this:

digitalWrite(Relay_4, cat);
delay(375); 
digitalWrite(Relay_4, dog);
delay(200);


----------



## fluffy...man (Jul 23, 2017)

Thanks for your input ...........Oh great master...........I see you try to confuse me...........some of the code you use the words of LOW and HIGH, then you use the numbers 1 and 0, (Ha.....nice try, they both mean the same) 0 is LOW which is ON, and 1 is HIGH which is OFF. Ta Da, this little Minion is getting the hang of this...I hope.
My confidence may be bigger than my boots, but I'm going to open a the sketch I posted, change the delays to delay(random(100,500);
then resave it under a new title, just in case it doesn't work, I'll have a back up copy of the original.
Q. Can the Arduino take negative input signal which would trigger a response?
Q. Can the Arduino handle 2 programmes?
Let me explain, If we take the sketch I listed above to randomly run the relay's on a constant loop, and if I was to be able to fathom out a simple MP3 YUART device could the Arduino take both sketches at once with a Negative trigger to operate the MP3 for a set time period then reset ready to go again at the next trigger? without disturbing the relay sketch.
If it is possible then the WOW, so many ideas could be put into play, they wouldn't work for me.....but I'd have a go at something
Off to rewrite my sketch now, catch ya later


----------



## Bosco P. Soultrane (Sep 11, 2015)

well, it is only ON and OFF with the relays (this seems to be exclusive with them). 
With LEDs, LOW, 0 is off, and HIGH and 1 is ON.
Q1: I don't understand your question. what is a negative input signal?
Q2: Not really. Not with the simple way we are doing it. It can be done with interrupts, but that would be too much for you at this time. 

What could be done is to turn on a mp3 player, then run the relay sequence. The mp3 would play thru. But I don't understand what you are trying to do.
Can you tell me what you want to happen? What are you running? 
Explain what it is you are thinking of doing.


----------



## fluffy...man (Jul 23, 2017)

A negative input signal: basically a switched earth or ground / negative, In the USA you might have a different terminology. Our cars and vans we use a switched earth signal to operate our engine ECU's. The control modules receive Earth signals from the sensors it's connected to. By using this method compared to live switching (Hot as the USA say) reduces the risk of Arcing (Apparently)
However, on our 12v systems, we switch on consumers using the live (hot) IE Lights, Fans, Motors etc which are all fused.
then control modules using earth/negative inputs from sensors. 
So, I was asking, can the Arduino be controlled by using Negative/Earthed switched inputs from sensors etc. Or does the Arduino require a Live (Hot) signal and at what voltage?
Moving onto your last question:
I have an Arduino with 8 Relays. I wish to run up to 8 props with these relays in a constant loop.
At the same time, have an ambient Mp3 on the same Arduino playing constantly in a loop which will not be affected by the relay programme (code) and visa versa. Mp3 programme (code) to interfere with the relay programme (code)
Or would it be best to run 2 Arduino's, 
1 for the 8 Relays and
1 for the Mp3 ambient sound track?
The main reason for having one Arduino, would be to keep things compact and tidy all in one weatherproof box.
However, I have an Mp3 shield on order to fit directly onto a spare Arduino board, and I also have a spare amp for the speakers, just need to make a code for making an Mp3 player to play sound from an SD Card on a loop.
(one of these)
VS1053B MP3 Music shield board Module with TF card slot For Arduino UNO R3 UK

I hope I haven't ranted on too much,


----------



## Bosco P. Soultrane (Sep 11, 2015)

The sensor for an arduino would typically get a "high" signal of 5 volts, and a low of 0 volts. But there are many sensors out there that can do different things. A photoresistor (or LDR - Light Dependent Resistor) is a sensor that could be used when it is bright, then run a program, or it can do it when dark, then run a program. The arduino would read resitor values from the LDR, and let's say if it is >=500, run program, if <500, shut off. 

What type of sensor are you going to use? The PIR as in the octobanger?

For the other question,
I think that all you have to do is start up the mp3 player, then run your relay code. The problem would be once the relay code is played thru, it will loop back to the beginning and restart the mp3. 

So what you need to do is to tell the mp3 player to start, then for the relay program to run and keep looping until the mp3 player finishes the song. Then the arduino would "hibernate" until it gets a signal from a sensor, and start the sequence all over again.

What if you had two arduinos, but 1 sensor for them both?


----------



## fluffy...man (Jul 23, 2017)

Um, I got a reply from Mike (the dude who designed the OctoBanger) I asked him if he would build me a modified version, Unfortunately he is tooooooo busy, but he did give some advise on a simple mod for what he has constructed (the Octo Banger) It involved changing the PIR sensor range, setting the Audio track to scare only and bridging out 2 pins on the Arduino. It kinda worked. The Mp3 played on a loop, The relays operated for one cycle then stopped, waited for the Mp3 to finish / restart, then they all fired in sequence again, but only once. So if I wanted to use this Mod, I would have to either time the relays to the length of Mp3, or find an Mp3 which would only run as long as my relay sequence.
So, that put pay to that idea....Boooh.
I haven't decided t have my props triggered by any type of switch at this stage, I was just asking, just in case I have an idea in the future.
I'm gonna go for 3 Arduino's.
1 for my Tree eyes, using the code you have supplied and I played around with. I'll run all 8 pairs of Eyes independent of each other by using 1 relay for 2 pairs of eyes, 1 set connected to the NO contact and the other pair to the NC contact of each relay. So between the random code we have put together it should look really cool.
Then:
The 2nd Arduino running the Octo Banger with 8 relays for the props to run on a timed loop only, no triggers (at this stage)
Then the 3rd Arduino to run the Mp3 ambient sound track on a loop.
Problem solved.......and decision made.
Now....where do I find a code for the Mp3 which I can get my head round and understand. Any ideas?


----------



## fluffy...man (Jul 23, 2017)

Question for anyone..............My wife is NOT happy, she wants to know why in the USA Halloween props, animated or not, are so much better than ours in the UK. and she also asks why she can get free shipping from China, but needs to re Mortgage our house for shipping from the USA. ?
I fobbed her off by telling her each country is in a different part of the world, and its cheaper to go round the world in a Clockwise direction, rather than Anti-clockwise because of the jet stream only goes in one direction, and a plane uses more fuel in a headwind. So far she believes my explanation, Bless.........


----------



## J-Man (Feb 1, 2011)

Fluffy...man,
Just read your post about using a negative input signal to the Arduino. Yes it can be done. The input pin needs to be held high with a 10K resistor (pull up). The code has to be written as such that the input pin waits for a low signal instead of high. I don't use Arduinos, I make my own controllers using PIC's and use low inputs quite often.


----------



## lizzyborden (Sep 17, 2009)

Thanks for explanations as well J-Man. I'm currently waiting on a few parts to build my octobanger and new to this too.


----------



## Bosco P. Soultrane (Sep 11, 2015)

fluffy...man said:


> Now....where do I find a code for the Mp3 which I can get my head round and understand. Any ideas?


I have the mp3 player that mike specified in his octobanger build. I could use that for testing and such, just can't be sure that it will work for yours.
I wasn't able to digest it yet, but it seemed that the sample program ran off of serial input from a keyboard, stuff like if you press "p" it would play, ">" would be next song, etc. using a switchcase (basically saying if "p" is pressed, than do a command, etc.

I would have to look it over and modify it to:
Start (play)
when song is finished, stop. Maybe add a delay.
Wait for signal to start again or just loop it to play over and over.

I am pretty sure that I might be able to change the switchcase to the loop and just put in the loop something like sendCommand(CMD_PLAY,0); 
Also, it is a bit complicated because it uses a serial library from arduino, which you would have to install, which isn't necessarily hard, but needs to be done correctly.

I looked up the mp3 shield you ordered. The problem is I don't have the mp3 shield you are using, so testing would prove difficult.

This is the wiki I found for your board: http://www.geeetech.com/wiki/index.php/Arduino_MP3_shield_board_with_TF_card

this looks for keyboard prompts 1-9 and plays that track off the SD card. type "s" and it stops. 
This also includes 4 libraries. You could load this one onto your mp3 shield and then if you can get it working, we could try modifying the code to your liking.
It is a clone of a sparkfun shield and uses the sparkfun shield library. I found some stuff, but once again, won't be sure that it would work with your version of the mp3 player shield or not, but here is the program: https://github.com/sparkfun/MP3_Player_Shield/blob/V_1.5/firmware/MP3_PlayTrack/MP3_PlayTrack.ino

This example seems to start the mp3 player, play the first track, advance to next track, finishes all tracks, then repeats from beginning. This would probably be what you want if it worked with your shield. But it could be difficult to diagnose if it doesn't work.


----------



## J-Man (Feb 1, 2011)

Fluffy...man,
If you just want your ambient sound to continually play in loop, why not just use a cheap mp3 player instead of trying to figure out code for an Arduino?
You can get a cheap repeating mp3 player for under $10.


----------



## fluffy...man (Jul 23, 2017)

Because that would make things too easy.
Bit like the Russian's and the US space agencies. The us spent thousands on developing a pen that will work in space. The Russians took a pencil.
Well this Halloween, I don't want to be a Russian.


----------



## J-Man (Feb 1, 2011)

fluffy...man said:


> Because that would make things too easy.
> Bit like the Russian's and the US space agencies. The us spent thousands on developing a pen that will work in space. The Russians took a pencil.
> Well this Halloween, I don't want to be a Russian.


I would never try to squash anyone's ambition but at the same time, why re-invent the wheel.


----------



## fluffy...man (Jul 23, 2017)

I understand, It's all a learning curve, and I have a thirst for knowledge. If something doesn't work, find out why, and improve the broken component. As a Master Tech for VW, I'm looking for why things fail, and how to improve. Never become complacent, The Japanese didn't with their Motorcycles, now they are world leaders.


----------



## J-Man (Feb 1, 2011)

fluffy...man said:


> I understand, It's all a learning curve, and I have a thirst for knowledge. If something doesn't work, find out why, and improve the broken component. As a Master Tech for VW, I'm looking for why things fail, and how to improve. Never become complacent, The Japanese didn't with their Motorcycles, now they are world leaders.


Knowledge is good, no doubt, but how is this improving? It's just turning something simple into something complicated.


----------



## fluffy...man (Jul 23, 2017)

I have a Question, Can an Arduino with the correct sketch, control 8 Relays for.......lets say 30 Seconds timed operation (ON), But not to have the relays operate in a specific sequence. But for the relays to operate randomly, and maybe more than one at a time with a random off time limited for up to 3 Mins ? , So Basically, have the relays behave like a group of naughty school children in a playground Ha Ha........Until the teacher blows the whistle (3 Mins) then they start misbehaving again in a loop.


----------



## Bosco P. Soultrane (Sep 11, 2015)

you mean for relays to randomly activate and at random duration? Yes.


----------



## fluffy...man (Jul 23, 2017)

Kind of, randomly activate, for a set ON period of 30 Seconds.
I tried building a sketch for a 4 Relay board, See below: Any ideas where I went wrong?

/*-----( Import needed libraries )-----*/
/*-----( Declare Constants )-----*/ 
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1 7 // Arduino Digital I/O pin number
#define Relay_2 6
#define Relay_3 5
#define Relay_4 4

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF); 

//---( THEN set pins as outputs )---- 
pinMode(Relay_1, OUTPUT); 
pinMode(Relay_2, OUTPUT); 
pinMode(Relay_3, OUTPUT); 
pinMode(Relay_4, OUTPUT); 
delay(50); //Check that all relays are inactive at Reset

}//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/
{

digitalWrite(random(Relay_1, 0));// set the Relay ON
delay(100)
digitalWrite(random(Relay_2, 0));// set the Relay ON
delay(100)
digitalWrite(random(Relay_3, 0));// set the Relay ON 
delay(100)
digitalWrite(random(Relay_4, 0));// set the Relay ON
delay(100) 
digitalWrite(random(Relay_1, 1));// set the Relay OFF
delay(random(1000,300000));
digitalWrite(random(Relay_2, 1));// set the Relay OFF
delay(random(1000,300000)); 
digitalWrite(random(Relay_3, 1));// set the Relay OFF
delay(random(1000,300000));
digitalWrite(random(Relay_4, 1));// set the Relay OFF
delay(random(1000,300000)); 

// wait see all relays OFF
}//--(end main loop )---

but when I try to verify it I get this:-
Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Mark\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10803 -build-path C:\Users\Mark\AppData\Local\Temp\arduino_build_327325 -warnings=none -build-cache C:\Users\Mark\AppData\Local\Temp\arduino_cache_485836 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Mark\Documents\Arduino\Random_4_relay_Op\Random_4_relay_Op.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Mark\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10803 -build-path C:\Users\Mark\AppData\Local\Temp\arduino_build_327325 -warnings=none -build-cache C:\Users\Mark\AppData\Local\Temp\arduino_cache_485836 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Mark\Documents\Arduino\Random_4_relay_Op\Random_4_relay_Op.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp" -o "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp" -o "C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp.o"
C:\Users\Mark\Documents\Arduino\Random_4_relay_Op\Random_4_relay_Op.ino: In function 'void loop()':

Random_4_relay_Op:34: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite(random(Relay_1, 0));// set the Relay ON

^

In file included from C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:134:6: note: declared here

void digitalWrite(uint8_t, uint8_t);

^

Random_4_relay_Op:36: error: expected ';' before 'digitalWrite'

digitalWrite(random(Relay_2, 0));// set the Relay ON

^

Random_4_relay_Op:38: error: expected ';' before 'digitalWrite'

digitalWrite(random(Relay_3, 0));// set the Relay ON 

^

Random_4_relay_Op:40: error: expected ';' before 'digitalWrite'

digitalWrite(random(Relay_4, 0));// set the Relay ON

^

Random_4_relay_Op:42: error: expected ';' before 'digitalWrite'

digitalWrite(random(Relay_1, 1));// set the Relay OFF

^

Random_4_relay_Op:44: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite(random(Relay_2, 1));// set the Relay OFF

^

In file included from C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:134:6: note: declared here

void digitalWrite(uint8_t, uint8_t);

^

Random_4_relay_Op:46: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite(random(Relay_3, 1));// set the Relay OFF

^

In file included from C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:134:6: note: declared here

void digitalWrite(uint8_t, uint8_t);

^

Random_4_relay_Op:48: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite(random(Relay_4, 1));// set the Relay OFF

^

In file included from C:\Users\Mark\AppData\Local\Temp\arduino_build_327325\sketch\Random_4_relay_Op.ino.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:134:6: note: declared here

void digitalWrite(uint8_t, uint8_t);

 ^

exit status 1
too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'


----------



## fluffy...man (Jul 23, 2017)

I have had another attempt and has been verified, but will it turn ON the relays randomly, for a period of 30 Seconds, and run in a constant loop?
Can any one advise please, This is based on a simpler 4 relay set up.

```
/*-----( Import needed libraries )-----*/
/*-----( Declare Constants )-----*/  
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1  7  // Arduino Digital I/O pin number
#define Relay_2  6
#define Relay_3  5
#define Relay_4  4

void setup()  /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_OFF);
  digitalWrite(Relay_2, RELAY_OFF);
  digitalWrite(Relay_3, RELAY_OFF);
  digitalWrite(Relay_4, RELAY_OFF);  
  
//---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  pinMode(Relay_2, OUTPUT);  
  pinMode(Relay_3, OUTPUT);  
  pinMode(Relay_4, OUTPUT);    
  delay(50); //Check that all relays are inactive at Reset
  
}//--(end setup )---


void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
  
  digitalWrite(Relay_1, 0);// set the Relay ON
  delay(random(30000));
  digitalWrite(Relay_2, 0);// set the Relay ON
  delay(random(30000));
  digitalWrite(Relay_3, 0);// set the Relay ON 
  delay(random(30000));
  digitalWrite(Relay_4, 0);// set the Relay ON
  delay(random(30000)); 
  digitalWrite(Relay_1, 1);// set the Relay OFF
  delay(random(1000,300000));
  digitalWrite(Relay_2, 1);// set the Relay OFF
  delay(random(1000,300000));   
  digitalWrite(Relay_3, 1);// set the Relay OFF
  delay(random(1000,300000));
  digitalWrite(Relay_4, 1);// set the Relay OFF
  delay(random(1000,300000));                
 
                 // wait see all relays OFF
}//--(end main loop )---
```


----------



## Bosco P. Soultrane (Sep 11, 2015)

That is way wrong. You don't need to post the error code, just tell me it didn't work.

*digitalWrite(random(Relay_1, 0));*

Random picks a number randomly within a range, from x to y, where x is the lowest and y the highest of the range. "Relay_1" is not a number, so it will not recognize it. You are saying here "generate a random number between Relay_1 and 0" That is like me asking you, try to guess a number between blue and zero. Can you do that? Well, neither can Arduino.

*delay(random(1000,300000));*

here you are saying "generate a random number between 1000 and 300000." Remember, this is in milliseconds. so you are saying a delay between 1 second and 300 seconds, or 5 minutes. I think you wanted 30 seconds.

I threw this together, it's a little different to what you are used to, but gotta go. See if this works and let me know what it does. Will get back to you tomorrow.

void setup() 
{
pinMode(7, OUTPUT); //relay 1
pinMode(6, OUTPUT); //relay 2
pinMode(5, OUTPUT); //relay 3
pinMode(4, OUTPUT); //realy 4
delay(50); //Check that all relays are inactive at Reset

}//--(end setup )---

void loop() {
digitalWrite(random(4,7), LOW); // sets a random relay on
delay(random(1000,30000)); // wait for some time (between 1 and 30 seconds)
digitalWrite(random(4,7), HIGH); // sets a random relay off
delay(random(1000,30000)); // wait for some time (between 1 and 30 seconds)
}


----------



## fluffy...man (Jul 23, 2017)

I get what your saying:
'That is like me asking you, try to guess a number between blue and zero'
I expect there is a formula for that question with an answer of PINK to the power of -1 Tee Hee.......
Thanks for your tutoring, it certainly helps.
I'll try your sketch out, 
then I might modify it for this :
relay on, to
delay (30000); if i'm correct this will turn the relay on for a fixed 30 seconds
then change the relay off to:
delay(random(30000,60000));
I believe you are steering me in the right direction and without knowing it, making me find my own answers: Good coaching....A+A+A+


----------



## Bosco P. Soultrane (Sep 11, 2015)

try this, the other one won't work. Here I shortened the random time to a range from 100 msec to 3 sec. If you look at the declarations, i made two new variables, time1 and time2, this way you won't have to remember a second or 30 seconds, here I defined them with only 100 msec and 3 seconds so you can test them quickly. then when you are sure this is good, add one zero to each in the declaration, and you will have a range of 1 sec to 30 seconds.

I have been running this for a while, it randomly turns them on and off, sometimes 1 on, 2 on, or all 4... etc.. 



> #define time1 100
> #define time2 3000
> 
> void setup()
> ...


----------



## fluffy...man (Jul 23, 2017)

Thank you, I'll give it a try. As long as I can get the relays to operate at a constant 30Seconds before turning Off. and for them to operate randomly it will make my display more of a surprise (not knowing which animation will operate next) If it all works well. I s'pose I would then add the additional 4 relays to the Pinmode sketch and then adjust the digitalWrite accordingly remembering to enter 1 digit above the final pinMode.

We have the biggest front garden in our street, and we intend on keeping the Onlookers out on the street pavement, looking over our boundary fence to view our display. This is the reason for not using a PIR to activate the props.

Approximately, How many different commands/sketch's can someone write code for a relay? You have now shown me 3 different ways so far......


----------



## fluffy...man (Jul 23, 2017)

I have plumbed my 8 relay board to the Arduino. Connected the pins as listed below, left off the ground wire between both units, connected the 5v supply from the 5v Arduino supply to the VCC of the relay board at the end of the relay pins. Removed the jumper, Just need to connect an external 5V and earth to the Gnd and the Jd-Vcc to power up the relays (as per wiring listed here http://forum.arduino.cc/index.php?topic=374728.msg2585056#msg2585056)
Your sketch moded below seems to work the LEDS at the relay, (relay's aren't firing as no external power is connected.....Yet)
I have modified your code for my 8 relay board to this:

#define time1 100
#define time2 3000

void setup() 
{
pinMode(2, OUTPUT); //relay 1
pinMode(3, OUTPUT); //relay 2
pinMode(4, OUTPUT); //relay 3
pinMode(5, OUTPUT); //relay 4
pinMode(6, OUTPUT); //relay 5
pinMode(7, OUTPUT); //relay 6
pinMode(8, OUTPUT); //relay 7
pinMode(9, OUTPUT); //relay 8
delay(50); //Check that all relays are inactive at Reset
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
//--(end setup )---

void loop() 
{

digitalWrite(random(2,10), LOW); // sets a random relay on
delay(random(time1,time2)); // wait for some time (between 1 and 30 seconds)
digitalWrite(random(2,10), HIGH); // sets a random relay off
delay(random(time1,time2)); // wait for some time (between 1 and 30 seconds)
}


----------



## Bosco P. Soultrane (Sep 11, 2015)

there are many ways to write code, i have purposely kept it simple because you are starting. We could do arrays, we could get rid of delay all together because it is limiting. It's better to use timers for actions than delay. But you have to learn new things slowly. It is good you are doing your own research, the arduino forum could prove helpful.


----------



## fluffy...man (Jul 23, 2017)

If i continue to use this random code, which appears to average 5 relays at on at any given time for a reasonable amount of time, Is there a limit instruction / digitalWrite that could limit the maximum amount of relays to operate at any given time?
IE Random relay operation, Maximum of 30 seconds operation with the maximum of 3 relays activated at any given time.?
I have looked and i'm unable to find any thing, perhaps I'm searching in the wrong area.


----------



## fluffy...man (Jul 23, 2017)

Q. 
When the Delay is written for a command, does the 'Delay' operate between each separate instruction?

And what command structure would work to limit a random code without stopping it's entire randomness? 
I 've tried < and > the word 'Limit', although it passed verification, the program refused to run.


----------



## Bosco P. Soultrane (Sep 11, 2015)

Yes, which is why delay isn't so good. 

I do not know what you are trying to do.
You can't just try using words like limit and expect them to work.
Arduino is a C based language, you have to remain in it.
random is already limited between two numbers, a min and a max range.

What is it that you want to do exactly? Are we still talking about the eyes lighting up? Or the props?
Random might not be what you really want to do and there might be an easier solution.


----------



## Bosco P. Soultrane (Sep 11, 2015)

"While it is easy to create a blinking LED with the delay() function, and many sketches use short delays for such tasks as switch debouncing, the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the millis() function and the sketch sited below. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10's of milliseconds unless the Arduino sketch is very simple."

Look at this:
https://learn.adafruit.com/multi-tasking-the-arduino-part-1/ditch-the-delay


----------



## fluffy...man (Jul 23, 2017)

Good evening,,,,,,,,,,,,,,, well it's like this, the blinking eyes works fantastically 
That one is now finalised and put to bed, as one would say.
My next challenge is to have an 8 Relay module connected to my props in the front garden.
have the 8 animated props function for 30 Seconds, but in no particular order, and no more than 3 of them activated at any given time. 
That's why I thought I could use the code for my flashing eyes and limit the relays in the random selection. I tried the symbol for less than 3, and also greater than 3. IE: >3 and <3 both were accepted in verification, but froze the program. Booh!
What about if I try a shuffle type programme, Ive seen code written for card shuffling, maybe I could modify one of them and limit the relays to a percentage rather than a number?
What do you think?


----------



## Bosco P. Soultrane (Sep 11, 2015)

ok, i came up with something that works for you.
This will pick three numbers randomly, then turn them on for 30 seconds, shut them off and then run again after one second.
Once again, for testing, I have changed time1 and time2 to 100ms and 3 seconds, respectively, add a zero to each for 1 sec and 30 sec.
I have added a serial read and print function, after loading the program onto the arduino, you can hit the serial monitor button in the upper right of the arduino compiler (it looks like a magnifying glass). this will open the serial monitor screen and print the random numbers 3 at a time. It will give you an idea of which numbers it is selecting.
If a number repeats, like it picks a 2,4,2, then it will only run 2 and 4. If it picks a 333, then it will only run 3, if it picks 9,3,7, it will plays all three.
Each one will play for 30 seconds, then it will loop , picking three more random numbers.

Have fun!


```
#define time1 100 // change this to 1000 for one second
#define time2 3000 // change this to 30000 for 30 seconds
int rand1 = 0; //random number 1
int rand2 = 0; //random number 2
int rand3 = 0; //random number 3

void setup() {
Serial.begin(9600); //opens serialport, sets data rate to 9600
  
pinMode(10, OUTPUT);//relay 1
pinMode(9, OUTPUT); //relay 2
pinMode(8, OUTPUT); //relay 3
pinMode(7, OUTPUT); //relay 4
pinMode(6, OUTPUT); //relay 5
pinMode(5, OUTPUT); //relay 6
pinMode(4, OUTPUT); //relay 7
pinMode(3, OUTPUT); //relay 8
delay(50); //Check that all relays are inactive at Reset
digitalWrite(10,HIGH);
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);

}//--(end setup )---

void loop() {
  rand1 = random(3,11); //picks random relay 1
  rand2 = random(3,11); //picks random relay 2
  rand3 = random(3,11); //picks random relay 3
  Serial.println(rand1);//prints numbers
  Serial.println(rand2);
  Serial.println(rand3);
  Serial.println(   );   
       
  digitalWrite(rand1, LOW); //turns on relays
  digitalWrite(rand2, LOW);
  digitalWrite(rand3, LOW);       
  delay(time2);  //time delay for relay to be on
  
  digitalWrite(rand1, HIGH); //turns off relays
  digitalWrite(rand2, HIGH); 
  digitalWrite(rand3, HIGH);    
  delay(time1);  //time dealy before running again     

}
```


----------



## Bosco P. Soultrane (Sep 11, 2015)

you get to try it out?


----------



## fluffy...man (Jul 23, 2017)

Sorry for the delay,
My PC died and I had to wait for payday to buy a new one. Then get all my data transferred from my old PC to my new one. Any way, on to more important matters:

Your code works a treat, Thank you. you have saved the day.
I have also put together an Arduino uno, with a 4 relay shield stacked on top, written a code that works, for my flying witch. she rises up and to the left all on Pneumatics, then squirts water from her mouth (using car windscreen washer jets and pump) and the movement triggers her boring pre recorded voice "I'm the bat keeper" I'll change her voice when I get better at coding using an Mp3 breakout board (thingy)
At present I'm looking into stacking an Mp3 Shield on top of this configuration I mentioned earlier so that when the Arduino is switched on it will play 1 track that will last for a couple of hours then start over until the power is switched off. without compromising my code for the witch, just haven't figured out how to do it yet.
Any ideas?
Here is my 4 Relay code:

void setup() {
// initialize the digital pins as an output.

pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop() {
digitalWrite(4, HIGH); // Turns ON Relay4 ON digital pin 4
delay(20000); // Witch rises
digitalWrite(5, HIGH); // Turns ON Relay3 ON digital pin 5
delay(3000); // Voice Mp3
digitalWrite(5, LOW); // Turns OFF Relay3 OFF digital pin 5
delay(1000); //
digitalWrite(6, HIGH); // Turns ON Relay2 ON digital pin 6
delay(100); // Squirt Water
digitalWrite(6, LOW); // Turns OFF Relay2 OFF digital pin 6
delay(1000);  // 
digitalWrite(7, HIGH); // Turns ON Relay1 ON digital pin 7
delay(1000); //
digitalWrite(7, LOW); // Turns OFF Relay1 OFF digital pin7
delay(10000); //
digitalWrite(4, LOW); // Turns OFF Relay4 OFF digital pin 4
delay(30000); // Time before loop begins
}

[/code]


----------



## Bosco P. Soultrane (Sep 11, 2015)

I have this code to play a file on an SD card in a loop. not sure yet how to integrate it into the relay parts.
Try this out and see how it goes. Just open an SD card, make a folder called 01 then put a song in the folder.
This code should play anything in the folder in a loop.
This is for the octobanger mp3 player, the Catalex board with the YX5300 chip.
Connect the mp3 player with:
RX to arduino pin 6
TX to arduino pin 5
VCC to the 5V arduino pin 
GND to the Arduino GND pin


----------



## Bosco P. Soultrane (Sep 11, 2015)

It won't let me add the code here, just write me a private message and I can send the code to you via email.


----------



## Bosco P. Soultrane (Sep 11, 2015)

*Code for mp3 player*

Code attachment


----------



## fluffy...man (Jul 23, 2017)

hi ya.
I wrote a reply, but it didn't send so I try again.
thank you for the code.
Arduino didn't like it on verification MP3 code only was tested separately.
All was going well then I got an instruction error that threw me.
it went like this:
'code' was not declared in this scope
I haven't played with code and this error is highlighted at the line
{ return "???: " + mp3answer;
} (code)

I did add a missing { at the beginning of the line as the closing " } " was before the word " } (code) "
which is just after. to remove the error message: 
expected unqualified-id before ' { ' token

Doesn't make sense to me. But do you understand my explanation ?


----------



## Bosco P. Soultrane (Sep 11, 2015)

Remove '(code)' from the program. That is from when i was trying to imbed the code in my post that didn't work, it is not part of the code.


----------



## Bosco P. Soultrane (Sep 11, 2015)

SO, i looked it over, the attachment i accidentally put the code in twice. so where it says :

}(code)

// Demo for the Serial MP3 Player Catalex (YX5300 chip)
// Hardware: Serial MP3 Player *1


You want to delete everything after the '}'
around line 98 so erase:

(code)..... all the way to the end.


----------



## Bosco P. Soultrane (Sep 11, 2015)

*Corrected Code*

Here it is corrected


----------



## fluffy...man (Jul 23, 2017)

Cheers chap,
I thought I was going mad.
everything my novice of a brain tried failed.
I'll have a go at wiring it up at the weekend. And all being well we will be good to go (Happy Days !!!!!!!!!!)


----------



## fluffy...man (Jul 23, 2017)

Hi Ya 
I've mixed up the Random 8 Relay code and the MP3 Code, and combined the 2 together, Arduino IDE programme has passed the verification. I have changed the Pin numbers for the relays and the TX / RX pins.
In your opinion, do you thing it will work?
I don't fancy cooking another Arduino so close to Halloween,
Awaiting with anticipation on your opinion


----------



## Bosco P. Soultrane (Sep 11, 2015)

It won't blow it up, but it won't do what you want it to do.
I wanted you to test the mp3 player first, not jump ahead and try to integrate it.
I haven't tried integration, not even sure how to make that happen yet.
If I can't get to it, you might have to run the mp3 player continuous separate from the props.

I am not sure what you are trying to do. The way it is written, it will pick a random relay, play it for 30-60 seconds, then shut off, wait 30-60 seconds, then play the mp3 player, then wait 1 second, start loop again.

Do you have 8 props you are trying to trigger? you are better of not making it random because you'll find some that play all the time while others never happen.


----------



## fluffy...man (Jul 23, 2017)

Ive done it now...........
We have 8 Animated props....air cylinder operated and wiper motor controlled, these will run on the original 8 Random relay code that you helped me with.
We also have numerous static props which have voices and light up eyes etc.
They all have TRY ME buttons. I intend to remove the buttons for the relay NO position, with the MP3 player producing sound in the back ground for our 'Yard' display.
I have tinkered around with another code which I will attach to this post.
I have tested it with relay the code and Mp3 code integrated. The Mp3 plays, the relays fire up at random, only glitch is now and again the Mp3 stops for a second or two, then continues.
Software or Hardware??????


----------



## Bosco P. Soultrane (Sep 11, 2015)

Yeah, i had the same problem with the glitch, it might be something I took out of the original code to trim it down a little. There is a 1000 msec delay after the initialization of the mp3, you might want to remove it or change the time, see what happens.


----------



## fluffy...man (Jul 23, 2017)

Well, that's that. Halloween over now. I played around with the code and gave up. I dragged out my stereo instead and played 4 Hrs of Mp3 on a USB stick. We did a three day event and raised just under £1200 for 2 of our local Charities. Google for Haunt's Corner, hopefully something will come up it does in the UK.
Many thanks for all your help. We have already have a few ideas for next years project. Jawduino will be on the cards for certain. (Skeletons with moving Jaws and speech) 
I did a simple code to operate our smoke machine. Only a simple 1 relay activation, On for a few seconds, then Off for around 20-30 seconds, it worked, then pumped constantly, so I unplugged it, and went without the smoke in our Cauldron Creeper.
Something else to look into the reliability..........a stuck relay or a glitch in coding...Ho Hum?
Anyway............I think we will have a few days rest then play around later, with more comprehensive testing.


----------



## fluffy...man (Jul 23, 2017)

Oh dear, it's not even Christmas and I'm thinking of next years display, got a few ideas, getting skulls with moving talking jaws with moving fingers. 
What have you been doing?
Got any new ideas for the next Halloween.?
I want to find a way round our UK rules so I can get USA props they are way better than ours, do you know a way?


----------



## Bosco P. Soultrane (Sep 11, 2015)

If you know how to solder, you could try these at haunt hackers: http://www.haunthackers.com/

The wee little talker will move a skull mouth in sync to a mp3 file.
The banshee does a little more, mouth, and 3 axis head movement


----------



## javahaunt (Sep 4, 2017)

Hi first attempt as well.. bought the parts but when tryig to unzip and run program to initiate UNO i get dll errors.. Has anyone successfuly built one and got things to work in win 10?
Thanks


----------



## Bosco P. Soultrane (Sep 11, 2015)

javahaunt said:


> Hi first attempt as well.. bought the parts but when tryig to unzip and run program to initiate UNO i get dll errors.. Has anyone successfuly built one and got things to work in win 10?
> Thanks


Yes, it will work in Windows 10. It's a nice program once you get it to work since you can put together 8 different relays but there is a bit of a learning curve to get it working. I don't recall what errors I had, but it wasn't a seamless install and activation.


----------



## javahaunt (Sep 4, 2017)

Bosco P. Soultrane said:


> Yes, it will work in Windows 10. It's a nice program once you get it to work since you can put together 8 different relays but there is a bit of a learning curve to get it working. I don't recall what errors I had, but it wasn't a seamless install and activation.


Thanks for the response. do you know of any resources to look at , i am new to rduino and was hoping this would be a little simpler but dont mind learning a new skill along the way.
Thanks


----------

