Complex circuit with external power controlled with Arduino

Hello, everyone! This forum has been extremely interesting, so much that I finally decided to get my Arduino and start learning. After creating some very basic projects, I now want to tackle a larger one, and I’d like some help understand some concepts and best approaches.

I’m building a model that will have some electronic components. These components can be grouped into 4 “circuits”:

  1. 30 orange LEDs.
  2. 30 blue LEDs.
  3. 4 motors.
  4. 1 servomotor that needs to be able to rotate 90 degrees clockwise or 90 degrees counterclockwise from a starting position.

I’ve hooked each of these components independently and written the code, and everything works as I expect, but now I have no clue on how to consolidate them. My expected behavior for the whole thing is:

  1. When a master, manual switch if off, nothing happens. When it’s manually turned on:

-All orange LEDs turn on for a second, then turn off for a second.
-All blue LEDs do the same, but alternating with the orange ones (they’re on while the orange ones are off)
-The 4 motors run constantly (until the master switch is off)
-The servomotor turns 90 degrees CW, waits 3 seconds, then turns 90 degrees CCW, then repeats.

I can write the code for everything, but have a few questions (apologies if these are quite basic):

  1. I know each color group of LEDs needs to be connected in parallel to avoid requiring an insane amount of Volts, and I know how to calculate the resistor each LED will need. But, how do I control them from a single pin from the arduino (while keeping them powered externally from a supply with sufficient Amps to power them all) without ruining mu arduino?
  2. How do I connect the 4 motors (also in parallel to each other, and in parallel to the LEDs) to the same power supply? These don’t really need to be connected to the arduino as they’ll run constantly as long as the master manual switch is on.
  3. How do I connect the servomotor to the arduino for control while also being powered externally, from the same single power supply as the rest of things?
  4. Finally, is it okay to also power the arduino from the same external power supply?

The ideal end result is a single house plug adapter of some sorts that powers all the circuits and the arduino itself whenever a master switch is manually toggled on, and everything turns off when the switch is off.

Any help would be massively appreciated, and if you consider yourself an expert and are up to teaching me in details, I’d be happy to arrange for an online consultation.

Thanks, all!

1 LED independent or 30 orange independent from 30 blue ?

ok, show all 4 sketches

transistor

direct to PSU

GND and signal to Arduino, GND and VCC to 5-6V supply.

obviously it depend on which particular PSU you mean

Sorry, I meant I know how to hook 1 led to one pin (or multiple leds to multiple pins, with one per pin), but I’d like to know how to connect multiple leds in parallel and control them all at once from a single pin (as my arduino doesn’t have 60 pins).

Im afraid I’m such a beginner that I don’t even know how to create the sketches. But, what I’m looking for is some advice on how to connect them -in any way- that gets the desired result. Any ideas? :slight_smile:

74HC595 and a resistor for each LED.

Thanks a million! This exactly solves my question about the LEDs! As I’ve said, I am a real amateur and didn’t even know such a thing existed. Thanks again!

https://www.google.com/search?q=how+to+connect+multiple+leds+in+parallel+and+control+them+all+at+once+from+a+single+pin

Sounds like a finite state machine to me. There are several good guides in this forum to help you out. The following example drives the state of the machine through a few functions using chars entered in the Serial Monitor. It could be a switch or something else. You can even nest these switch/case/default/break control structures.

/* Typing in the chars to Serial Monitor changes the state (or mode) */

char mode;
const int light = 3;
const int pump = 4;
const int fan = 5;

void setup() {
  Serial.begin(115200);
  pinMode(light, OUTPUT);
  pinMode(pump, OUTPUT);
  pinMode(fan, OUTPUT);
  Serial.println(F("charDrivenThreeDeviceStateMachine"));
  Serial.println();
  Serial.println(F("Type 0-7 to change functions"));
  Serial.println();
  mode = '0'; // start state variable at mode 0
  modeZero(); // let us know and init devices to off
}

void loop() {
  if (Serial.available() > 0) {
    mode = Serial.read(); // could be any switch or sensor driving this
    switch (mode) {
      case '0':
        modeZero();
        break;
      case '1':
        modeOne();
        break;
      case '2':
        modeTwo();
        break;
      case '3':
        modeThree();
        break;
      case '4':
        modeFour();
        break;
      case '5':
        modeFive();
        break;
      case '6':
        modeSix();
        break;
      case '7':
        modeSeven();
        break;
      default: // optional, but leave in even if you don't use, some say
        break;
    }
  }
}

void modeZero() {
  Serial.println(F("mode 0: light off, pump off, fan off"));
  Serial.println("");
  allOff();
}
void modeOne() {
  Serial.println(F("mode 1: light on, pump on, fan on"));
  Serial.println("");
  allOn();
}
void modeTwo() {
  Serial.println(F("mode 2: light on, pump on, fan off"));
  Serial.println("");
  lightAndPump();
}
void modeThree() {
  Serial.println(F("mode 3: light off, pump on, fan on"));
  Serial.println("");
  fanAndPump();
}
void modeFour() {
  Serial.println(F("mode 4: light on, pump off, fan on"));
  Serial.println("");
  lightAndFan();
}
void modeFive() {
  Serial.println(F("mode 5: light on, pump off, fan off"));
  Serial.println("");
  justLight();
}
void modeSix() {
  Serial.println(F("mode 6: light off, pump on, fan off"));
  Serial.println("");
  justPump();
}
void modeSeven() {
  Serial.println(F("mode 7: light off, pump off, fan on"));
  Serial.println("");
  justFan();
}
void allOff() {
  digitalWrite(light, LOW);
  digitalWrite(pump, LOW);
  digitalWrite(fan, LOW);
}
void allOn() {
  digitalWrite(light, HIGH);
  digitalWrite(pump, HIGH);
  digitalWrite(fan, HIGH);
}
void lightAndPump() {
  digitalWrite(light, HIGH);
  digitalWrite(pump, HIGH);
  digitalWrite(fan, LOW);
}
void fanAndPump() {
  digitalWrite(light, LOW);
  digitalWrite(pump, HIGH);
  digitalWrite(fan, HIGH);
}
void lightAndFan() {
  digitalWrite(light, HIGH);
  digitalWrite(pump, LOW);
  digitalWrite(fan, HIGH);
}
void justLight() {
  digitalWrite(light, HIGH);
  digitalWrite(pump, LOW);
  digitalWrite(fan, LOW);
}
void justPump() {
  digitalWrite(light, LOW);
  digitalWrite(pump, HIGH);
  digitalWrite(fan, LOW);
}
void justFan() {
  digitalWrite(light, LOW);
  digitalWrite(pump, LOW);
  digitalWrite(fan, HIGH);
}

OP wants to turn on and off 30 leds simultaneously.
A transistor or a relay could be better solution

ICs are made of _________.

Magic blue smoke compressed to its solid state of matter?

You're not tryin' if your not fryin'.

ICs and microcontroller are made up of transistors. Why don't you suggest op to connect those 30 LED directly to Arduino pin.
He would be very thankful to you :laughing: