Program is activating on its own

Hello all. I have a program that activates 2 solenoids. When the button is pushed, it should turn the first one on for 2.75 seconds and then turn off. Wait 1 second. Turn on the second one for 2 seconds and then turn off. The program works as desired except for it randomly activating without the button being pushed. Any thoughts on how to correct this? Much appreciated in advance. The program is below:

const int buttonPin = A3;  //Pin for the button
const int solo1 = 7;       //Pin for the larger solonoid that activates first
const int solo2 = 6;       //Pin for the smaller solonoid that activates second


int buttonState = 0;  //Variable for reading the pushbutton status


void setup() {

  Serial.begin(9600);  //start serial communication
  Serial.print("Serial communication initialized");

  // Initialize the solonoid pins as outputs
  pinMode(solo1, OUTPUT);
  pinMode(solo2, OUTPUT);

  // Initialize the button as an input
  pinMode(buttonPin, INPUT_PULLUP);
}



void loop() {

  // Read the state of the button value:

  buttonState = digitalRead(buttonPin);


  if (buttonState == LOW) {

    //Turn solo1 on:

    digitalWrite(solo1, HIGH);

    Serial.println("solo1 high");

    delay(2750);

    digitalWrite(solo1, LOW);

    Serial.println("solo1 low");

    delay(1000);

    //Turn solo2 on:

    digitalWrite(solo2, HIGH);

    Serial.println("solo2 high");

    delay(2000);

    digitalWrite(solo2, LOW);

    Serial.println("solo2 low");

    delay(1000);
  }
}

Sounds like power supply, electrical noise or solenoid driver problems.

Please post a hand drawn wiring diagram and links to the components, including the power supply.

How do you power the solenoids? I hope not directly from the output pins of your Arduino. Solenoids are electromagnetic devices, that may create voltage spikes when switched off. These spikes can create problems for the microcontroller.

For the wiring, I have the button wired to the Keyestudio relay shield, one to ground and one to A3. The solenoids are powered from the arduino to an adjustable voltage step up set to about 8V.

Voltage step up: https://www.amazon.com/Adjustable-Converter-Step-Down-Regulator-Stabilizer/dp/B081N6WWJS/ref=sr_1_6?crid=1SH5L61ZW8H0G&keywords=arduino+5v+to+12v&qid=1652722380&sprefix=arduino+5v+to+12v%2Caps%2C122&sr=8-6

Relay shield: (Amazon.com)

Wiring diagram and links to the rest of the components.

Solenoid: https://www.emerson.com/no-no/catalog/aventics-sku-r422103561-en-gb

I only included one solenoid in the wiring diagram but the other is wired the same.

There's your problem (probably).

The Arduino's 5V regulator can only supply a "little extra" current beyond powering the Arduino itself. It's complicated but the more voltage you "drop" across a linear regulator, the hotter it gets and the less current it can supply (reliably).

You are already "pushing it" if you are powering the Arduino from 24V.

And a voltage step-up means a step-down in current... Or looking at it the other way you have to supply more current into the DC-DC converter than the solenoids are pulling out.

So generally, it would be better to step-down the 24V to drive the solenoids.

Wow. Been a long day and I can barely think. I was incorrect before. I have 24V coming in to the solenoids and using a voltage step down from the 24V to 8V to power the arduino only.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.