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() {
pinMode(sensor, INPUT);
pinMode(push, INPUT);

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

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?

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:![Circuit|690x414](upload://ehd6wuTKkgawvlI2sJOhN6UYE20.jpeg)

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:

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:

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