Charity project

Only one Arduino being used, the one fixed to the bread board would not load.

I am no electronics expert but I think your bulb circuit is flawed. I would expect the relays to be switching power to the bulbs from another power supply, but I can't see one.

I see on the silkscreen that it is active low, so I will need to change the code accordingly once the bulbs are working.

It may be worth me writing something that turns all the bulbs on and off every few seconds for testing - let me know. Are you using my code as posted above? In particular if you changed any of the pin numbers, please let me know what they are now.

I think perhaps the excitement time can be changed from 5000milliseconds to just 1000, as well as the interval.
Also, is it possible for the highest level to 'pulse' four times instead of a constant sound.

I am using your suggested pin numbers. I was advised that the power for the bulbs can come from the arduino.

Maybe. I rather doubt it though - it can provide very little power. What is the spec on the bulbs? Also, if the Arduino can power the bulbs then there is no need for the relays - I think you may have received some contradictory advice.

They are 4.5v bulbs, and yes I can see your point.

The important question is how much current the bulbs draw. And actually, perhaps the relays would make sense if it's too much current for a digital pin to safely provide. They don't look wired correctly though.

I can see that now. There are three pairs of 4.5v bulbs, then the final set of three, nine bulbs in total.

Could anyone advise how many bulbs an Arduino Uno could cope with directly?, without using a relay, If I change the LED bulbs to 3v at 0.2amps

Zero

The spec for the Uno says that it can manage to provide a maximum of 150 milliAmps.

Since you have the relay board though, all you need is a suitable power supply for the LEDs and the Arduino can use the relays to control them.

thank you

The first one you can change yourself - the intervals near the top of the code are defined there to make it easy for you to fiddle with them. Let me know what you settle on.

The second is done, but still needs testing. I'd rather not introduce extra complexity though until the basic version is working.

thank you, I will give a try.

Here is the latest version. I have tested it with direct connected LEDs so for me, everything's on to start. With the relay board it should be OK.

// Cake Controller V003

// Changes
// Now another level of excitement and a new pattern
// Tones for levels moved to an array
// One Led pin per pattern
// Final tone phases in and out four times
// Flip HIGH/LOW on LEDs to take care of active low relay board

const byte LedPins[]={2,3,4,5};            // Arbitrary Led pins in an array so I can loop through them

const byte NumLeds = sizeof LedPins / sizeof LedPins[0]; 
const byte LedPatterns[5][NumLeds] = { // Patterns for the various led effects, including the special case of all off
                                       {LOW, LOW, LOW, LOW},
                                       {HIGH,LOW, LOW, LOW},
                                       {LOW ,HIGH,LOW ,LOW},
                                       {LOW ,LOW ,HIGH,LOW},
                                       {HIGH,HIGH,HIGH,HIGH}
                                     };

const int Tones[]={0,262,300,392,523};     // Tones for different exitement levels

const byte SoundPin = 10;                  // Used with Tone function to make noise with as yet unknown hardware
const byte CoinDetectPin = 11;             // The coin detector - active LOW
const byte MaxExcitementLevel=4;           

byte ExcitementLevel=0; 

const unsigned long ExitementInterval=6000;      // Milliseconds. How long do users have to add an extra coin
const unsigned long PatternChangeInterval=1000;  // Milliseconds
const unsigned long ToneChangeInterval=250;      // Milliseconds
const byte MaxToneChanges=8;

unsigned long LevelChangeTime;
unsigned long PatternChangeTime;           // When did the pattern last change - used for flashing effect
unsigned long ToneChangeTime;              // When did the tone last change - used for pulsing effect
byte NumToneChanges;
bool PatternOn=false;                      // Flash controller

void setup() 
{
Serial.begin(115200);
Serial.println("Start");
for(byte i=0;i<NumLeds;i++)
  { 
  pinMode(LedPins[i],OUTPUT);
  }
pinMode(SoundPin,OUTPUT);
pinMode(CoinDetectPin,INPUT_PULLUP);
}

void loop() 
{
if(digitalRead(CoinDetectPin)==LOW)
  {
  HandleNewCoin();  
  }
if(millis()-LevelChangeTime > ExitementInterval)
  {
  if(ExcitementLevel>0)  
    {
    ExcitementLevel--;
    LevelChangeTime = millis();    
    }
  }
HandleSounds();
HandleLedPatterns();
}

void   HandleNewCoin()
{
if(millis()-LevelChangeTime < ExitementInterval)
  {
   Serial.println("coin");
   delay(250);                 // Ugly delay to stop cointing coins more than one
  if(ExcitementLevel< MaxExcitementLevel)  
    {
    ExcitementLevel++;
    ToneChangeTime=millis();
    NumToneChanges=MaxToneChanges;
    }  
  }
LevelChangeTime = millis();
}

void HandleSounds()
{
switch(ExcitementLevel)
  {
  case 0:
    noTone(SoundPin);  
    break;
  case MaxExcitementLevel:
    HandleMaxExitementTones();
    break;
  default:  
    tone(SoundPin,Tones[ExcitementLevel]);  
    break;
  }
}

void HandleMaxExitementTones()
{
static bool ToneOn;  

if(NumToneChanges)
  {
  if(millis()-ToneChangeTime > ToneChangeInterval)
    {
    NumToneChanges--;
    ToneOn=!ToneOn;
    Serial.print("ToneOn: ");
    Serial.println(ToneOn);
    if(ToneOn)
      tone(SoundPin,Tones[ExcitementLevel]);  
    else    
      noTone(SoundPin);  
    ToneChangeTime=millis();  
    }
  }  
}

void HandleLedPatterns()
{
if(millis()-PatternChangeTime > PatternChangeInterval)
  {
  Serial.print("Excite: ");
  Serial.println(ExcitementLevel);
  PatternOn = !PatternOn;
  if(PatternOn)
    {
    for(byte i=0;i<NumLeds;i++)
       digitalWrite(LedPins[i],LedPatterns[ExcitementLevel][i]==HIGH ? LOW : HIGH);
    }
  else
    {
    for(byte i=0;i<NumLeds;i++)
       digitalWrite(LedPins[i],HIGH);
    }
  PatternChangeTime=millis();  
  }
}

Fabulous, thank you.

Thank you, but I am having trouble with it. The sound increases, and the lights come on in series, but the final ones don't flash, then the sound goes back down the scale instead of being silent, and the lights stay on!

Ok, I'll take a look at it tomorrow. The way I have it now, the excitement level builds as coins are detected and falls off by stages when they're not. It sounds like you're planning that it resets to nothing after the final level.

Could you clarify what it should do?

When does it go on display?

Yes please, a straight cut off when it has reached it's peak. I am puzzled why the lights stay on though, I am sure the wiring is correct now.
I am in a panic as it is on display next Tuesday, however I am meant to have it PAT tested on Friday at the Hospice. If it is easier, could we just have the coin detector setting all the lights at once, with one sound 523hz, for 2000 milleseconds, and re-setting after that. This would be more than adequate for the job. I really appreciate your help. We spent too long building the frame, and realising too late that we needed a relay. Thank you in advance.

Well, if you have time, we can iterate significantly faster. It may be useful to talk on the phone, but first I'll take a look at the code.