Discussion (*ask your questions here!) > Questions

MidiSprout controlling 8channel Switch Relay

(1/2) > >>

Hi Sam,

I'm preparing an art installation with the MidiSprout builded with your tutorials,
My idea is to now change the MIDI output jack of my midi sprout (I do not need midi notes), what I need is something simpler, I want to control in some way an 8-channel relays switch module (the ones that often used with arduino).

at the moment I am controlling the relays with a simple random generator written in an Arduino Uno. the connection and circuit of the relays work very well.

My question is: how could I make the plant define those parameters on and off in the 8 channel relays module? that is: (1) which relay channel it selects and (2) how long that channel remains on, before it is disconnected again.

thanks a lot in advance!

Hello Julio, yes that is a great idea to control a set of relays with the sprout.  How much programming experience do you have, and is this your first electronics project?  Your modifications are very doable, but it will take a bit of solder and code!

1.) what type of relay board are you using?  Many relay boards for arduino have 8 individual digital input pins, some use SPI/I2C, and others can use Serial to trigger the relays.   I think we have 8 digital pins available on the sprout, so even the most basic or diy relay setup should be able to be 'wired' to the sprout.

2.) You can easily modify the code to turn a relay on when a note is triggered and off when an note is updated. 
   a. First you should increase the note polyphony from 5 to 8 (to match your relays). 
   b. Second, In setNote() add  some code to turn on the relay digitalWrite(relayPin[ i ],HIGH);  where relayPin[] is an array containing the pin number for each of the relay inputs and "i" is the currently available 'note' of the 8 available from polyphony
   c. Third, in checkNote() add some code to turn off the relay when the note is expired digitalWrite(relayPin[ i ],LOW);

This method will have the relays mirror the notes and durations as they turn on and off.

Good luck!  please post some more info of your build!


Hi Sam,
sorry for the late reply, I did not get a notification of your response:)
thanks for your reply

well, programming experience very little, but tomorrow I ll have some help from an expert.
I have more experience with soldering DIY oscillators dub sirens, and simple synths, this is my first one involving code.

1. this is my relay board:

(8 Channel 5V Relay Module Modul for Arduino)
Now it is working with a simple code with a random generator / it is working just fine / but I would like to have a real change of this random generator with the input signal of the Midi Sprout.
This is the code I am using:
#define RELAY1  2
#define RELAY2  3
#define RELAY3  4
#define RELAY4  5
#define RELAY5  6
#define RELAY6  7
#define RELAY7  8
#define RELAY8  9
byte relays[8] = { RELAY1, RELAY2, RELAY3, RELAY4, RELAY5, RELAY6, RELAY7, RELAY8};
void setup() {
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(RELAY5, OUTPUT);
  pinMode(RELAY6, OUTPUT);
  pinMode(RELAY7, OUTPUT);
  pinMode(RELAY8, OUTPUT);
void loop() {
  digitalWrite(relays[random(0, 8)], random(0, 4));
  delay(random(500, 5000));

and about my DIY sprout build, here is a picture of it:

(please note I could not find a .0042uF capacitor so instead I use a .0047
also I got so much trouble trying to bootload the ATMEGA328-PU so I use instead the ATMEGA328P-PU from an Arduino UNO, do you think this 2 changes from the original kit would be problematic?, seems to work fine till now)

so, in short, I have this two "devices" working separately.., now I need to somehow make them communicate to each other.. :)

Thanks a lot for the coding suggestions and very creative input!, tomorrow I ll test them with the build, hopefully everything works 0k.


I have the soldering part done (not using Midi Out + leds)
and using 8 digital out from ATMEGA connected to 8channel relay board:

so we tried to work on editing the original code to switch the relays on/off, with still no luck:(

Send me a link to your code and I'd be happy to help.  This should be a fairly easy modification with the right digital pins.


[0] Message Index

[#] Next page

Go to full version