Transistors aren't being biased, code compiles fine, hardware issue?

Hello, I am trying to toggle transistors for a cosplay project, and am not sure if I'm having code or circuit issues.
I've got 3 switches and a button, allowing a high signal from one arduino to a low pin to act as a sort of monitor for when a switch is toggled and the current is flowing through it. I take this and define loops and ifs based on whether or not that low pin is recieving a high signal. When a certain pin receives a high signal, the arduino is to write a high signal that will go to the base of the transistor and bias it, turning a light on.

The code compiles fine, but the circuit isn't completely functional, the lights do not turn on. I'm not sure where to go from here.
Here's my code:


 /*This code is a work on progress and is
 designed to provide lights and sounds for
 a custom-modified Spirit Halloween Ghostbusters
 Proton Pack and other Arduino Based packs*/

 int modeSwitch = digitalRead(A1); //identifier for pack mode
 int packStart = digitalRead(12); //Identifier for pack startup
 int packOff = digitalRead(0); //Identifier for pack startup
 int protonFire = digitalRead(8); //Identifier for proton fire

void setup() {
 // put your setup code here, to run once:

 //Neutrona Wand Switches

 pinMode(0, INPUT); //Pack Shut Down Input Pin
 pinMode(1, OUTPUT); //Pack Shut Down Output Pin
 pinMode(2, OUTPUT); //Start Up Output Pin
 pinMode(12, INPUT); //Start Up Input Pin
 pinMode(3, OUTPUT); //Firing Output Pin
 pinMode(8, INPUT); //Firing Input Pin
 pinMode(A0, OUTPUT); //Mode Switch Output Pin
 pinMode(A1, INPUT); //Mode Switch Input Pin

 //Cyclotron LED leads connect here

 pinMode(4, OUTPUT); //Port 1 for the Cyclotron Lights
 pinMode(5, OUTPUT); //Port 2 for the Cyclotron Lights
 pinMode(6, OUTPUT); //Port 3 for the Cyclotron Lights
 pinMode(7, OUTPUT); //Port 4 for the Cyclotron Lights
 
 //Enables Pins that toggle transistors for sound effect board

 pinMode(9, OUTPUT); //Sound Effect 1 Base Toggle
 pinMode(10, OUTPUT); //Sound Effect 2 Base Toggle
 pinMode(11, OUTPUT); //Sound Effect 3 Base Toggle
 pinMode(A3, OUTPUT); //Sound Effect 4 Base Toggle

 
 //Power Meter Activation

 pinMode(13, INPUT); //DOES NOTHING RIGHT NOW
 pinMode(A2, OUTPUT); //Power Meter Activation, listed as pin 7 in pseudo, which isn't correct anymore but we'll roll with it
 
 

 Serial.begin(9600);     // start serial interface

}

void loop() {
 // put your main code here, to run repeatedly:
 /* Here, in this part of the loop (for now)
  *  the code will cycle between ports 7, 6, 5,
  *  and 4, lighting up the Cyclotron lights for
  *  brief periods.
  */


 digitalWrite(2, HIGH); //Feeds Power to top right Thrower Switch for start up
 digitalWrite(A0, HIGH); //Feeds Power to bottom right Thrower Switch for mode switch
 digitalWrite(1, HIGH); //Feeds Power to bottom left Thrower Switch for shut down
 digitalWrite(3, HIGH); //Feeds Power to top left Thrower Switch for firing
 int blueMeter = A0; // Blue Meter LEDs 1-4 will go here.
 int lighting = 0; // Sets brightness of LEDs
 int fadeQuantity = 5; //amount to fade LEDs
 int packPower;
 int loopStarter;
 loopStarter = 1;
 int i;
 loopStarter = i;
 packPower = digitalRead(12); //identifier for if statement

 

do {
 Serial.println("Cyclotron Online");
 digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(4, LOW);
  delay(500);
  digitalWrite(5, HIGH);
  delay(500);
  digitalWrite(5, LOW);
  delay(500);
  digitalWrite(6, HIGH);
  delay(500);
  digitalWrite(6, LOW);
  delay(500);
  digitalWrite(7, HIGH);
  delay(500);
  digitalWrite(7, LOW);
  delay(500);
} while (packPower == HIGH || LOW);
 

 if (packPower == HIGH || LOW){
 //if switch command == 1, then the switch has been flicked and the cyclotron lights should be working
 Serial.println("Power Meter Online");

  for (int i = 1; i <= 4; i++) {

 //set lighting of blueMeter
analogWrite(blueMeter, lighting);

//changing lighting
lighting = lighting + fadeQuantity;

// reverse the direction of the fading at the ends of the fade:
 if (lighting <= 0 || lighting >= 255) {
   fadeQuantity = -fadeQuantity;
 }
 // wait for 300 milliseconds to see the dimming effect
 delay(300);
 
  
 }
 }

 //if statements for toggling transistors

 if (packStart == HIGH){
 digitalWrite(9, HIGH);
 delay(500);
 digitalWrite(99, LOW);
 //pack start up toggle
 Serial.println("start up toggled");
 }

 if (packOff == HIGH){
digitalWrite(11, HIGH);
  delay(500);
  digitalWrite(11, LOW);
  //shug down toggle
  Serial.println("shut down toggled");
 }


  
 if (protonFire && !modeSwitch == HIGH){
   digitalWrite(10, HIGH);
   //fires neutron stream but not slime
   Serial.println("firing toggled");
 }
 
 if (protonFire && modeSwitch == HIGH){
   
   digitalWrite(A3, HIGH);
   //fires slime but not neutron stream
   Serial.println("slime blo");
   }

}


And here's a picture of the circuit:

It's an electricity 101 failure. Literally first day stuff.

Without a connection between the negative side of the batteries and the Arduino, you don't have a circuit.

Circuit: an unbroken path that returns to its starting point.

Try and trace where electron flow through your base of your transistors has a circuit back to the Arduino. You can't. There isn't one. Connect all your emitters together and make a connection to the Arduino's ground. Voila: circuit.

3 Likes


My bad, I wasn't paying to that bit, but it's still not working.

Wire colours notwithstanding, now it looks like you have the positive side of the batteries hooked up to the Arduino's ground. Because the negative side had better being going to those transistor emitters.

1 Like

The positive side of the battery is connected to the collector, the emitter goes to the led, then the resistor, then ground.

An emitter follower? Really? You might want to rethink that.

And label your transistor types, would you? CBE is not a universal configuration everywhere in the world.

2 Likes

Also Serial.print will not work if a switch is connected to Pin 0.

Does the corresponding OUTPUT Pin change state?
I dont see any pull down resistors to keep the Input at a known state.

The better way of reading switches is to use Internal pullups and the switch connect between Input Pin and ground (Batt negative).

1 Like

Those fritzing pics are less than useless.
Draw a decent circuit diagram and mark all connections including whatever it is you are using for a power supply.
Mark all terminal numbers and resistor values.

1 Like

Assuming those are NPN transistors, is the red wire connected to the emitter or collector?

How would we know that, there are no terminal labels? Same thing with LEDs, is the green wire connected to anode or cathode?

The blue leds need a resistor.
And will not do anything with 3 in series.
Why do your switches use 2 input/output pins?
It is far easier to wire them from input to gnd...
What colors are those resistors: gray black brown gold?

The fritz diagram is fine but may be wrong.
What is the part number of the transistors?

Also there are quite a few errors in your code.

Don't use pins 0 and 1.

This code should be inside loop not at the top

 int modeSwitch = digitalRead(A1); //identifier for pack mode
 int packStart = digitalRead(12); //Identifier for pack startup
 int packOff = digitalRead(0); //Identifier for pack startup
 int protonFire = digitalRead(8); //Identifier for proton fire

So the LED and resistor should come before the collector?

They are NPN, they're d331 transistors. I didn't include them because I got it in my head that it wasn't important because I did look up some circuit examples, my bad.

They work in the real life equivalent, but I can add a resistor if it's best.
How would I detect a change if all my switches are wired to ground?

They are NPN, they're d331 transistors, I will amend the code and circuit to not use 0 and 1, thank you.

D331?

Or D331, or better known as an S8050?

How are we to know, since you didn't include a datasheet link?

Interestingly, in neither case are the pins arranged in a CBE configuration. So your transistors are still wired wrong if your amended Fritzing accurately reflects your actual wiring.

Anyway, I've reached my limit with the lack of rigour and care being displayed here. Good luck, and good-bye.

I do thank you for the help thus far, even if you have been rather arrogant towards the end.

They need to be connected like this

Usually we start all arrogant and lighten up as we get the information and questions answered. Maybe you were early.

Can you explain the slide switches and pushbutton, all four of which are an input connected to an output. This is unusual. Say why it is necessary here.

Also, whats with three diodes in serial hanging off A0?

a7