Help on using FC 51 module

Hi to everyone, I'm new in the Arduino world and I wanted to see if someone can help me with a problem.
I want to make a counter with a FC 51 module, and when I press a 4 pin switch, make the counter zero. I have troubles because the serial monitor shows me every second the words "current counter:" and also the counters resets instantly. Here i attach my code

int counter = 0;
int sensor = 8;
int push = 12;

void setup() {
Serial.begin(9600);
pinMode(sensor, INPUT);
pinMode(push, INPUT);
}

void loop() {
if (digitalRead(sensor) == HIGH){
if (digitalRead(sensor) == LOW){
counter = counter + 1;
Serial.print("Current count:");
Serial.println(counter);
delay(200);
}
if (digitalRead(push) == HIGH){
counter = 0;
Serial.print("Current count:");
Serial.println(counter);
}
}
}

What is a FC51 module? Link to data sheet type information, Please.
How do you have the switch wired?
How do you have the Arduino powered?
I do not see the words "current counter" anywhere in the code you posted. Do yo uhave another version of the code you are not showing?
Paul

Hi, @meca2021
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

What controller are you using?
Can you please post a copy of your circuit diagram?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi Tom,thanks for replying. I attach the diagram now.
And here it is the link with the module information:
https://artofcircuits.com/product/infrared-obstacle-avoidance-proximity-sensors-module-fc-51

Hi Paul, thanks for the reply. The words "Current count" is what I want to print on the serial monitor.
I posted on Tom's commentary the circuit diagram.
I'm powering my Arduino with my laptop and no,I have no more code :smiley:

Hi,
Your button pulls the input to gnd, but when open the input is floating, it has no constant value.
You need to change this statement;

pinMode(push, INPUT);

to this;

pinMode(push, INPUT_PULLUP);

This will add an internal pull up resistor to the input, so it will be HIGH when the button is open and LOW when the button is pressed.

That should fix one of your bugs.

Tom... :smiley: :+1: :coffee: :australia: