When I plug my light strip into power it makes arduino go crazy.

I made a simple circuit which uses DPDT momentary switch to the colours and the brightness of these colours on the light strip. Everything works fine, the code, the circuit. When I plug the light strip into power it starts sending on/off singals to the arduino as if I was moving the switch to the sides sending the signals to the input pins (I have two input pins, one for each side of the button) at the same time. It is even bypassing the code somehow which by the way does not let the values change when the other side of the switch is HIGH.

Any ideas as to why it does that would be appreciated.

thanks.

When I plug the light strip into power it starts sending on/off singals to the arduino as if I was moving the switch to the sides sending the signals to the input pins (I have two input pins, one for each side of the button) at the same time. It is even bypassing the code somehow which by the way does not let the values change when the other side of the switch is HIGH.

I can't visualize your schematic... Can you post a schematic? Is there any connection between the light strip and the Ardino? Are they sharing a power supply?

If your inputs are high-impedance, or if you forgot to include a pull-up (or pull-down) resistors, your inputs can pick-up noise when the switch is off. You can write a little test program to see if is signal is picking-up noise and creating a false-input. For example, write a little program that turns-on the pin-13 LED for one second whenever the button is pushed. If it triggers "falsely" you might have noise pickup.

It is even bypassing the code somehow which by the way does not let the values change when the other side of the switch is HIGH.

I'm not sure what that means either... Maybe you think your code is being bypassed, or maybe a glitch is resetting/rebooting your Arduino.

DVDdoug:
I can't visualize your schematic... Can you post a schematic? Is there any connection between the light strip and the Ardino? Are they sharing a power supply?

If your inputs are high-impedance, or if you forgot to include a pull-up (or pull-down) resistors, your inputs can pick-up noise when the switch is off. You can write a little test program to see if is signal is picking-up noise and creating a false-input. For example, write a little program that turns-on the pin-13 LED for one second whenever the button is pushed. If it triggers "falsely" you might have noise pickup.
I'm not sure what that means either... Maybe you think your code is being bypassed, or maybe a glitch is resetting/rebooting your Arduino.

What I mean by my code getting bypassed is that my code basically says (In human language) "If one side of the button is on, the other side cannot change value even if the switch is bouncing" because it happens especially with my momentary DPDT button. The problem in this is that both of the inputs fluctuate between HIGH and LOW simultaneously xD even though the code should not let it. I had the states of the button printed to the serial monitor. The code and the arduino works fine until I plug in the light strip which needs 2A and I power it from the mains.

They are not sharing a power supply. My arduino is powered by the computer and the strip like I said above, form the mains. I use 2 ground pins, one for the switch and one for the strip. I will get a schematic so you can see and the code but have to add comments first.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a picture of your project?

WHY???
You have the project infront of you, we don't.
You know how it is wired, we don't.

Thanks....Tom.... :slight_smile:

Here is the circuit. I don't know if it makes any sense though so sorry if it doesn't. I don't really know how to draw circuits xD. I'll post the code after I annotate it. Maybe you will be able to see what is wrong from the circuit.

I forgot the connect the the last transistor's collector to mains on the circuit btw. Sorry about that.

Hi,
Yes, your circuit is very confusing, can you post some pictures of your project, showing your wiring.
What voltage is your light strip and what is supplying that voltage.
What is supplying your arduino?
Please some pictures...

Tom.... :slight_smile:

Im going to post another picture when it lets me.

Second photo is here.

Hi,

What voltage is your light strip and what is supplying that voltage.
What is supplying your arduino?

The way you have your LEDs and TIP31 connected is wrong.
Please answer the two questions above.

I have no idea what your switches are doing.
Can you draw (pen and paper) a diagram, use a box as your arduino with the used pin numbers around it.
Particularly how you have wired your switch.

Thanks.....Tom.... :slight_smile:

When I plug the light strip into power it starts sending on/off singals to the arduino as if I was moving the switch to the sides sending the signals to the input pins (I have two input pins, one for each side of the button) at the same time.

Sounds like you have a power setup that is causing the arduino to crash and reset. You probably need to put an arduino reset flag in the code you did not post.

Tip31 and 1k base resistors = maximum 30cm of LED strip?

Connected as emitter follower? (post#4)

Can't you switch in software.
Leo..

TomGeorge:
Hi,

What voltage is your light strip and what is supplying that voltage.
What is supplying your arduino?

The way you have your LEDs and TIP31 connected is wrong.
Please answer the two questions above.

I have no idea what your switches are doing.
Can you draw (pen and paper) a diagram, use a box as your arduino with the used pin numbers around it.
Particularly how you have wired your switch.

Thanks.....Tom.... :slight_smile:

the strip is 12V, supplied by the mains at 2 amps since the strip requires 24W.
my laptop is supplying power to the arduino.

Intelligent Power and Sensing Technologies | onsemi - TIP31C datasheet. I dont think I have connected them in the wrong way as the light strip lights up but it just makes the arduino go crazy so I cant controll the strip or the arduino. When I unplug the power to the strip everything works fine.

I will post the picture of the pins used soon.

int ButtonCounter = 0; // records how many times the switch has been pulled HIGH (resets to 1 beyond 3) 
                       // 1, 2, 3 corresponds to the selected colour e.g. 1 = red selected
                       
int PWMbuttonStorage = 0; // checks if the other side of the switch has been pulled to HIGH which
                          // changes the PWM value sent to the currently selected colour pin
int reading = 0; // used for debouncing


// PWM values for the 3 colours are stored here
int BlueBrightness = 0;  
int GreenBrightness = 0 ;
int RedBrightness = 0;

//fade values
int FadeRed = 1;
int FadeGreen = 1;
int FadeBlue = 1;


const int PWMchangeButton = 4; // the pin used to activate PWM alternation 

// PWM outputs for the 3 colours of the strip.
const int RedLed = 9;
const int GreenLed = 10;
const int BlueLed = 11;


const int ButtonPin = 2; // button pin used the select the colour who's PWM value is to be changed

const int LedPin = 13; // too see if the button bounced or not

// Initialisations
int LedState = HIGH;
int ButtonState;
int lastButtonState = LOW;


long LastDebounceTime = 0;

long DebounceDelay = 100;


void setup() {
  // put your setup code here, to run once:
pinMode(ButtonPin, INPUT);
pinMode(LedPin, OUTPUT);
pinMode(PWMchangeButton, INPUT);

pinMode(RedLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(BlueLed, OUTPUT);
Serial.begin(9600);


}

void loop() {
  // put your main code here, to run repeatedly:
  
  
   reading = digitalRead(ButtonPin);
  delay(50);
  
  PWMbuttonStorage = digitalRead(PWMchangeButton);
  
  
 if (PWMbuttonStorage != HIGH) {     // if the PWM values are changing any signals sent to the
                                     // other side of the DPDT due to bouncing will be ignored
                                     
  if (reading != lastButtonState) { // state change check
    
    LastDebounceTime = millis();
  }
  
  if ((millis() - LastDebounceTime) > DebounceDelay) {  // if the button has not been activated for longer than the
                                                        // Debounce delay then proceed.
    
    if (reading != ButtonState) {  // if the state has changed the proceed
      ButtonState = reading;
      ButtonCounter = ButtonCounter + 1; // selects the colour of the strip whos PWM value is to be altered.
      
      if (ButtonCounter > 6) {    // Since it is a momentary switch th reading will go up by 2 every time.
                                  // so actually it will reset to 1 beyond 6.
        ButtonCounter = 1;
      }
      
      if (ButtonState == HIGH) {
        LedState = !LedState;
      }
    }
  }
  digitalWrite(LedPin, LedState); // write the current state of the LED to the arduino.
  
  lastButtonState = reading;
 }
 
 
 if (reading != HIGH) {    // prevents the PWM values from changing when the colour is getting selected
 
 //between 1 & 2 red is selected and if the button to alter the PWM value is high then the pwm value will change for red.
 // this code is repeated for the other 2 colours too.
  if (ButtonCounter == 1 || ButtonCounter == 2) {
    if (PWMbuttonStorage == HIGH) {
      analogWrite(RedLed, RedBrightness);
      
      delay(30);
      RedBrightness = RedBrightness + FadeRed;
      
      
      if (RedBrightness == 0 || RedBrightness == 255) {
        delay(50);
        FadeRed = -FadeRed;
      }
      delay(50);
    }
  }
 if (ButtonCounter == 3 || ButtonCounter == 4) {
    if (PWMbuttonStorage == HIGH) {
      analogWrite(GreenLed, GreenBrightness);
      delay(30);
      GreenBrightness = GreenBrightness + FadeGreen;
      
      if (GreenBrightness == 0 || GreenBrightness == 255) {
        delay(50);
        FadeGreen = -FadeGreen;
      }
      delay(30);

    }
 }
 if (ButtonCounter == 5 || ButtonCounter == 6) {
    if (PWMbuttonStorage == HIGH) {
      analogWrite(BlueLed, BlueBrightness);
      delay(50);
      BlueBrightness = BlueBrightness + FadeBlue;
      
      if (BlueBrightness == 0 || BlueBrightness == 255) {
        delay(30);
        FadeBlue = -FadeBlue;
      }
      delay(30);
    }
 }
}
}

This is my code for the project

Wawa:
Tip31 and 1k base resistors = maximum 30cm of LED strip?

Connected as emitter follower? (post#4)

Can't you switch in software.
Leo..

what do you mean?

Hi,

Can you draw on this basic schematic how you have your project connected please.

Tom.... :slight_smile:

Hopefully you'll make something of this.

In your diagram you have SHORTED the Arduino outputs to ground through the base-emitter diodes of the transistors. Bad for the Arduino.
Luckily you have used base resistors in our setup.

You diagram shows the transistors being used to SHORT the 12volt power supply to ground.
I'm sure you don't mean doing that.

The transistors you have used have low gain and high saturation, and you drive them with ~4mA base current (1k resistor).
They can't drive a LED strip to full brightness.
You NEED mosfets for a LED strip.

I have seen several articles on the web use these transistors with a 1k base resistor.
Tells me they don't know what they're doing.

The switch should be wired differently.
This way you will need pull-down resistors.
You can avoid that if you wire the common contact (green wire) of the switch to GROUND.
And use INPUT_PULLUP in pinMode.
Leo..

Wawa:
In your diagram you have SHORTED the Arduino outputs to ground through the base-emitter diodes of the transistors. Bad for the Arduino.
Luckily you have used base resistors in our setup.

You diagram shows the transistors being used to SHORT the 12volt power supply to ground.
I'm sure you don't mean doing that.

The transistors you have used have low gain and high saturation, and you drive them with ~4mA base current (1k resistor).
They can't drive a LED strip to full brightness.
You NEED mosfets for a LED strip.

I have seen several articles on the web use these transistors with a 1k base resistor.
Tells me they don't know what they're doing.

The switch should be wired differently.
This way you will need pull-down resistors.
You can avoid that if you wire the common contact (green wire) of the switch to GROUND.
And use INPUT_PULLUP in pinMode.
Leo..

I bought some MOSFETS. Could you draw me a simple diagram of how I should wire everything together? I would be very grateful!

Did you buy LOGIC mosfets?
Leo..

Yes