Static charge makes my sketch trigger.

Hi All,

My project is being triggered by static electricity.
While the UNO R3 board is energized running my sketch it will be triggered if I go near it, especially if I remove my jacket with fleece lining near it, 1’ to 2’ away. No kidding!
I provided a pic of setup and the sketch.

1)I tried coupling cap/resister connecting reset pin to ground on UNO.
2) Tried cap/resistor on buttonpin to ground on ONO.

Any thoughts?

// KOBE control Rev4
// This will sequence the ouputs after button press 1 and and a shutdown sequence on press 2:
const int buttonPin = 2;             //assigns digital input 2 the name buttonPin
const int fan = 12;                  //assigns digital output 12 the name fan
const int pump = 11;                 //assigns digital output 11 the name pump
const int igniter = 10;              //assigns digital output 10 the name igniter
const int cooldownled = 9;           //assigns digital output 9 the name  cooldownled
int x = 0;                           //sets x variable to 0 at start.


int buttonState = 0;                 // variables will change:
int oldButtonState = LOW;

void setup()
{
  Serial.begin(9600);                      // start serial com at 9600 baud
  while (! Serial);                        // Wait until Serial is ready
  Serial.println("KOBE program started");  // print KOBE program started
  oldButtonState = digitalRead(buttonPin);

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(fan, INPUT_PULLUP);          //initalize as an input first so during power up it is not energized
  pinMode(igniter, INPUT_PULLUP);
  pinMode(pump, INPUT_PULLUP);
  pinMode(cooldownled, INPUT_PULLUP);
  // initialize the load pins as outputs
  pinMode(fan, OUTPUT);                     // pin 12 // initialize the load pins as an output
  pinMode(pump, OUTPUT);                    // pin 11
  pinMode(igniter, OUTPUT);                 // pin 10
  pinMode(cooldownled, OUTPUT);             // pin 9

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

}

void loop()
{
  // Get the current state of the button
  int newButtonState = digitalRead(buttonPin);


  // Has the button gone high since we last read it?
  if (newButtonState == HIGH && oldButtonState == LOW) {

    if (x == 0) {
      Serial.println("button pressed"); // print button pressed

      // Toggle on fan
      Serial.println("fan on");
      digitalWrite(fan, LOW);           // turn on fan
      delay(5000);                      // delay xxxx sec

      // Toggle on pump
      Serial.println("pump on");
      digitalWrite(pump, LOW);         // turn on pump
      delay(0);                        // delay xxxx sec

      // Toggle on igniter
      Serial.println("igniter on");
      digitalWrite(igniter, LOW);       // turn on ignition relay active low
      delay(5000);                      // ignition on time xxxx sec

      digitalWrite(igniter, HIGH);      // turn off ignition
      Serial.println("igniter off");
      Serial.println("Run mode entered");
      x = 1;                            // toggle PButton state indicator to 1


    } else {                            // if pump is on turn off and enter cool down mode

      // shut down sequence
      digitalWrite(pump, HIGH);         // turn off pump
      Serial.println("pump off");
      digitalWrite(cooldownled, LOW);   // turn on cool down led
      Serial.println("cool down led on");
      delay(5000);


      digitalWrite(fan, HIGH);           // turn off fan
      digitalWrite(cooldownled, HIGH);        // turn off cool down led
      Serial.println("Heater off");

      x = 0;                             // toggle PButton state indicator to 0
    }
  }

  // Store the button's state so we can tell if it's changed next time around
  oldButtonState = newButtonState;
}

Increase the relative humidity of the room. A well grounded Faraday Cage.

You have an external pullup resistor here :

pinMode(buttonPin, INPUT);

?

The internal pull up resistors are high value and cause grief - use anexternal 10k resistor instead as a pull up .
If input leads are long look at using optio isolators in your inputs ( and outputs ) .
Put the Arduino in a metal box too - or mount it on stand off on a metal plate connected to 0v.
It’s worth googling “ industrino” to see circuit ideas for ruggedised I/O

Internal pull ups cause grieve? No no no :smiley: Not unless you connect 1m+ of cable and/or place it next to heavy motors or relays. The +-30k of the internal pull up is just fine in 95% of the cases. But floating inputs ARE causing grieve :smiley:

Hi all
Thanks for all your replys!
I am not following most of your though. Please be specific i am new and know very little.
So how can i fix this?

If the triggering is coming from an input, try a N.C. switch connected to GND, look for a HIGH on push.

In you code you have:

void setup()
{
  //...

  pinMode(buttonPin, INPUT_PULLUP);

  //...

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

}

The last pin mode you set to buttonPin is INPUT, not INPUT_PULLUP which means that input is floating :slight_smile:

:slight_smile: Septillion,

You ar da man...I think this worked, and I see why now. If i set it as just INPUT it is floating between a low and high state, and when I get near it with a static field it can change the voltage on the input pin causing it to trigger.

Big thanks to all you guys!!!

Mully911:
:slight_smile: Septillion,

You ar da man...I think this worked, and I see why now. If i set it as just INPUT it is floating between a low and high state, and when I get near it with a static field it can change the voltage on the input pin causing it to trigger.

Big thanks to all you guys!!!

Static electricity is an interesting phenomenon. IT works both ways. If your Arduino project is not connected to some large metallic device or to a real ground connection, it could be the one with the charge and you are neutralizing it. Same results!

Paul

Also looks like you have a resistor in series with the ground pin of the switch. If this was an attempt at an external pulldown, it's on the wrong side of the switch. It should have been placed on the pin side, and not in series, but parallel.