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:




