Storage of a variable in a line counter

Hello, I recently started in the world of Arduino. Currently I work in a line meter with an FC-51 sensor for Arduino, I am using the Arduino UNO and so far I have created a counter that digitally reads the black line, I will use it for counting stations in an electronic cart, but I do not know how the data could be stored in the counter until it finds a new black line and does not count it several times. Below I share what I have scheduled;

int sensorPin = 2;
int contador = 0;
int ledPin = 13;
int sensorValue = 0;
int desenclave = 1;
int maquina = 5;
int motor1;
int motor2;

void setup () {
pinMode (ledPin, OUTPUT);
Serial.begin (9600);
}

void loop ()
{
sensorValue = digitalRead (sensorPin);
digitalWrite (ledPin, HIGH);
if(maquina = contador){
digitalWrite (motor1,LOW);
digitalWrite (motor2, LOW);
}
else(maquina > contador);
{
if(sensorValue <= 0)
{
contador = contador;
digitalWrite (ledPin, LOW);
Serial.println (contador);
}
if(sensorValue >= desenclave)
{
contador = contador+1;
digitalWrite (ledPin, HIGH);
Serial.println (contador);
}
}
}

Tanks :slight_smile:

I don't understand what you are trying to do but this

else(maquina > contador);

is meaningless and this

  contador = contador;is a waste of time.

Can you please explain what problem you are experiencing

Hello, the goal of my code is to count the lines, each line is a station, but the lines should not be counted more than once because the sensor is subject to a moving cart, if it is on a line that does not count more than once

if it is on a line that does not count more than once

Count a line when it [u]becomes[/u] detected rather than when it [u]is[/u] detected. Look at the StateChangeDetection example in the IDE to see how to do it