Using Pull-Up Resistor to get rid of False positive in millistimer

Im building my first project because i needed a timer to press a button in once every 7 days.
The issue i run in to is that I get a false trigger when starting up. (specificly when i switch the PINMODE from Pin D7 to OUTPUT)
As i understand this is often the case with a Arduino Every in start up having to do with floating voltages and can be solved either by soldering in an resistance between the Output pin "D7"and the GND, or by using an internal resistance by programming.
Ive spend time searching for the right lines of codes but so far are not able to get it to work.
Due to my lack of experiance i might be doing something completly wrong, but i hope someone can at least point me in the right direction

const int devicePin = 7;
// Weekly interval in milliseconds: 1000ms * 60s * 60m * 24h * 7d
unsigned long previousMillis = 0;
unsigned long interval = 604800000UL;

void setup() {
  digitalWrite(devicePin, LOW); 
  pinMode(devicePin, INPUT_PULLUP); 
  pinMode(devicePin, OUTPUT);
  digitalWrite(devicePin, LOW);   
  previousMillis = millis();
  delay(3000);

}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
if (currentMillis -  previousMillis >=  interval) {

    digitalWrite(devicePin, HIGH);
    previousMillis = currentMillis;
  }
  else
  {
      digitalWrite(devicePin, LOW);
}
}

Welcome to the forum

  pinMode(devicePin, INPUT_PULLUP); 
  pinMode(devicePin, OUTPUT);

Why are you setting the pin to INPUT_PULLUP then immediately setting it to OUTPUT ?

Hi @hvacdesignpim ,

Welcome to the forum..

Sounds like you need a pull down resistor like 10k between device pin and ground..

might want to add a small delay after setting device pin high or it won’t be high for long and may not be detected as a push..

good luck.. ~q

I presume you are driving either a relay or mosfet to 'actuate the button'. Please show us your output circuit. A photo of a pencil sketch will do.

Your loop() code will result in a VERY short pulse each time the time criteria are met; As @qubits-us says, you should extend that, as it may not result in a pulse long enough for the system you are trying to trigger.

Because you coded it like that.

When the Every starts up, your pin will be an INPUT and be floating.

When your code writes a LOW to it... I don't think anything will happen. Your pin will likely still be floating. You could write a test sketch and check it with a meter.

When your code configures the pin as INPUT_PULLUP, it will be weakly pulled to 5V.

When your code configures the pin as OUTPUT, it will be set LOW (unlike in the 328P, where setting to pin to INPUT_PULLUP prior to setting it to OUTPUT would result in a HIGH).


Whether or not that's what you want to happen is something only you know. But that's what your code is telling the processor to do.

If your undescribed button is triggering on the weak pullup or a floating input, I have to wonder what it's hooked up to.

Im trying to connect this device

Trying to make the manual override to trigger every 7 days

I think part of the problem is that I had it connected to the 5V pin to power the arduino but read its often the cause because it doesnt get regulated

The problem isnt i cant trigger the system i get that working no problem but it Triggers on start up which im trying to prevent

I am still interested in hearing your answer to this question

Was trying to do this

  1. from the tech doc, it's evident your external button is connected to pins labeled 0V and IN, and a spst button is used to short the two. So, you're looking to provide a short pulse to 0V.

  2. your code is structured to achieve the opposite - a short high pulse at the end of the time period, then low.

This is the equivalent of holding the button all the time, releasing and pressing again to get the unit to operate.

At least, that's all I can determine from what you've provided. If I'm correct, then your code should establish a high at startup, keeping the pin high all the time until you provide a short low pulse.
Good luck!

Apparently you need to start with pin D7 (PA1) high, and after interval pulse it low. Unfortunately, Arduino header files for Nano Every contain a flaw, making this impossible using Arduino Language. Direct register access can be used to work around.

In setup():

VPORTA.OUT |= 0b00000010; // to set PA1 high
VPORTA.DIR |= 0b00000010; // to make PA1`output

In loop() after if-statement:

VPORTA.OUT &= ~0b00000010; // to set PA1 low
delayMicroseconds(5);      // to add a delay equivalent to digitalWrite
VPORTA.OUT |= 0b00000010;  // to set PA1 high

To understand the meaning of VPORT you might read the datasheet.

By the way, you need to advance previousMillis.

Is this documented somewhere?

It's been discussed in this forum many times before.
You might also read:
C:\Users\USER\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\cores\arduino\wiring_digital.c

To be clear I want to do the following

Nothing for 7 days
Activate button
Repeat

The reason for my high low and input stuff was all to get the bug out the program that it activates the button on boot

Did you read my last post to you? (not the useless divergence with @stitech). You must determine whether the system triggers on a high-low, or a low-high. By definition, even if you manage to keep the input high from power on forwards, if low-high triggers the system, so will power-off to power-on.

You might be better off using a relay to drive the button input, as at least then, you might be able to prevent the relay from clicking at power-on, and only happen on timeout.

Ah ok so I've been assuming putting it in high is activation but it's the other way arround?
I will try it tomorow

Question:
Why don't you use the built-in function in Control Spui itself?


Looks like it offers what you want.

No for two reasons either you have to do it only on time and not flush on temperature, or it loses its interval time after one interval

Their has been extensive contact with the manufacturer to get this done before asking me to do this.