UNO R4 WiFi button press freaks out

Hi!

I picked up Arduino again after some years, now i hooked up a bunch of things as you can see to see if i can use them again?

Now i have a problem, every time i press the button, the green LED and the state of the button starts going crazy. The serial monitor confirms that the button state changes every X interval what i set before. For eg. when i set 100ms interval, the serial monitor be like:

Button was pressed, state is: 0
LED has been changed, state is: 0
Current Millis: 579000

Button was pressed, state is: 1
LED has been changed, state is: 1
Current Millis: 579100

Button was pressed, state is: 0
LED has been changed, state is: 0
Current Millis: 579200

But this continues for like 15-30 seconds even if i completely unplug everything from the UNO in the meantime.
I am using the new UNO R4 WiFi, maybe this is just another bug?

Source code:

#include "Arduino_LED_Matrix.h"
#include "animation.h"

ArduinoLEDMatrix matrix;

const int buttonPin = 7;
const int potmeterPin = A1;
const int lightSensorPin = A0;
const int rgbRPin = 3; //PWM
const int rgbGPin = 5; //PWM
const int rgbBPin = 6; //PWM
const int irSensorPin = 4;
const int greenLedPin = 2;
const int buzzerPin = 8;

const int greenLedInterval = 500;
const int buttonInterval = 100;

unsigned long currentMillis = 0;
unsigned long previousGreenLedMillis = 0;
unsigned long previousButtonMillis = 0;

byte greenLedState = LOW;
byte buttonState = LOW;


void setup() {
  Serial.begin(9600);

  pinMode(buttonPin, INPUT);
  pinMode(potmeterPin, INPUT);
  pinMode(lightSensorPin, INPUT);
  pinMode(rgbRPin, OUTPUT);
  pinMode(rgbGPin, OUTPUT);
  pinMode(rgbBPin, OUTPUT);
  pinMode(irSensorPin, INPUT);
  pinMode(greenLedPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  matrix.loadSequence(dinosaur);
  matrix.begin();
  matrix.play(true);
}

void loop() {
  currentMillis = millis();

  //greenLedBlinking();
  buttonRead();

  switchLED();

}

void greenLedBlinking() {
  if (greenLedState == LOW) {
    if(currentMillis - previousGreenLedMillis >= greenLedInterval) {
      greenLedState = HIGH;
      previousGreenLedMillis += greenLedInterval;
    } 
  } else {
    if(currentMillis - previousGreenLedMillis >= greenLedInterval) {
      greenLedState = LOW;
      previousGreenLedMillis += greenLedInterval;
    }
  }
}

void switchLED() {
  digitalWrite(greenLedPin, greenLedState);
}

void buttonRead() {
  if (currentMillis - previousButtonMillis >= buttonInterval) {
    if(digitalRead(buttonPin) == HIGH) {

      buttonState = !buttonState;
      Serial.print("Button was pressed, state is: ");
      Serial.println(buttonState);

      greenLedState = !greenLedState;
      Serial.print("LED has been changed, state is: ");
      Serial.println(greenLedState);

      Serial.print("Current Millis: ");
      Serial.println(currentMillis);

      Serial.println();
      
    }
    previousButtonMillis += buttonInterval;
  }
}

Also i tried using hardvare debounce with 10k resistor and a 0.1uF capacitor, no luck. I tried only touching the 5V rail with the wire for the corresponding pin, no luck. I tried switching out the button but this is irrelevant because it still freaks out even when i only touch it to the 5V rail manually.
I also have no electric shorts.


Where?

I also have no shorts.

Not a great idea when you are playing with electronics.

Please read the forum guidelines about how to post a question. You didn't provide the kinds of information that are actually needed in order to help you.

In the source code, the definition of the inputs and outputs with corresponding names.

What should i provide, can you help? I provided the source code, the error that i have and the steps that i already tried to eliminate the factors like bad switch or electric shorts.

I also added an overall picture and a schematic for the questionable switch and LED.
I repeat that the elimination of the hardware debounce or the switch doesn't solve the problem, also the LED works fine.

That's not the way to connect and use switches/buttons. Use INPUT_PULLUP and connect the butten between pin 7 and GND. Drop the cap.

Please post it here.

In the source code, the definition of the inputs and outputs with corresponding names.

So, a kind of time wasting puzzle for me to solve. No thanks.

It was a p(w)astebin link, not an inline post with code tags as explained in the guidelines. The reasons why that is unacceptable, are outlined there.

I said twice previously that if i disconnect the switch or remove the debounce circuit the problem still persist. Also i found the circuit in another post, Debouncing capacitor where everyone said that this is fine.

Looks like OP is attempting to do a manual debounce but.....needs to look how to do it the correct way.
Op, there is plenty of detail out there.

Sorry (also i don't think that reading this is more time consuming that reading the entire post and then commenting twice about something entirely irrelevant, i uploaded a picture too :slight_smile: )

const int buttonPin = 7;
const int potmeterPin = A1;
const int lightSensorPin = A0;
const int rgbRPin = 3; //PWM
const int rgbGPin = 5; //PWM
const int rgbBPin = 6; //PWM
const int irSensorPin = 4;
const int greenLedPin = 2;
const int buzzerPin = 8;

Thanks, i included the source code.

Thanks, but did you checked the link? I found the circuit there what worked for everyone else, and also if i remove it the problem still persist.

Also i tried using hardvare debounce with 10k resistor and a 0.1uF capacitor, no luck. I tried only touching the 5V rail with the wire for the corresponding pin, no luck. I tried switching out the button but this is irrelevant because it still freaks out even when i only touch it to the 5V rail manually.

i have and the steps that i already tried to eliminate the factors like bad switch or electric shorts

I repeat that the elimination of the hardware debounce or the switch doesn't solve the problem, also the LED works fine

if i disconnect the switch or remove the debounce circuit the problem still persist Also i found the circuit in another post, Debouncing capacitor where everyone said that this is fine

I found the circuit there what worked for everyone else, and also if i remove it the problem still persist .

This is the 5. time that i want to clarify that the problem is not with the debouncing capacitor.

  1. I followed the linked post
  2. I removed it once
  3. I switched the button for a brand new
  4. I tried only touching the corresponding pin to 5V but the 15-30 sec looping problem still persist

Sadly, it is simply wrong...so do yourself a favour, and look up how to do it with hardware properly.
Either that or simply do the debounce in software.
Plenty of detail on that as well.

It doesn't help how many times You tell something that's wrong or useless. Connect according to reply #4 to get somewhere nearby. Add the cap if You feel like. Debouncing is preferable done in the code.

Have you looked at the example sketches and tutorials on this site? Switch interfacing is pretty well covered there...

The pull up resistor is connected to the wrong side of the switch.
In post#4 it was explained how to use the switch without a resistor or cap.
pinMode(buttonPin, INPUT); // button between pin and ground, no resistor
Did you already change that?

An Uno R4 is a racehorse, not a workhorse like the Uno R3. Be careful with your LED current limiting resistor choice. The R4 pins only have 1/5th of the drive capacity of the R3. A 330 ohm resistor with a red LED could draw (5 - 1.8) / 330 = 9.7mA, which is more than the 8mA absolute max of the R4.
Leo..

1 Like

@bluejets, @Railroader and @anon57585045 can we move on with my circuit? I removed it and hooked up just like #4 said and the problem is still there. :frowning:

Also i tried to say five times that i already done that with no luck.

Try moving on with the solutions you've been handed. They are textbook advice.

Moving on with mistakes, is well, a mistake...

I already did and the problem still there as i said in #15.

If you made circuit changes or code updates, post them. Otherwise, we're guessing what you did.

I forgot the current limits, thanks, i'll add a slightly bigger one to avoid burning the chip.

Yes, i changed it, but still no luck.

Do you understand that we can't see over your shoulder, can't see what you did? We need complete, accurate, up to date information. Diagrams, code, all of it. In it's most current state.

I don't feel that it is an unreasonable request...

Please do not forget to also include a clear, complete and accurate description of the problem behaviour.