In function 'void setup()':

int IN1 = 2;     //IN1 a pin digital 2
int IN2 = 3;     //IN2 a pin digital 3
int ENA = 5;     //ENA a pin digital 5
int IN3 = 7;     //IN3 a pin digital 7
int IN4 = 8;     //IN4 a pin digital 8
int ENE = 9;     //ENE a pin digital 9


int SENSOR= 12;
int Valor= 0;
int ANTERIOR = 1;

void setup() {
  pinMode(IN1, OUTPUT);  //IN1 como salida
  pinMode(IN2, OUTPUT);  //IN2 como salida
  pinMode(ENA, OUTPUT);  //ENA como salida 
  pinMode(IN3, OUTPUT);  //IN3 como salida
  pinMode(IN4, OUTPUT);  //IN4 como salida
  pinMode(ENE, OUTPUT);  //ENE como salida
 

 Serial.begin(9600);
  pinMode(SENSOR, INPUT);
}

void loop() {
  VALOR = digitalRead(SENSOR);
  if (VALOR != ANTERIOR){
    if (VALOR == HIGH)

    digitalWrite(ENA, HIGH); //ENA en alto habilita motor A
    digitalWrite(IN1, LOW); //IN1 en cero logico
    digitalWrite(IN2, HIGH); //IN2 en uno logico

    digitalWrite(ENE, HIGH); //ENA en alto habilita motor A
    digitalWrite(IN3, LOW); //IN3 en cero logico
    digitalWrite(IN4, HIGH); //IN4 en uno logico
    delay(3000);         //demora de 3 seg.

     digitalWrite(ENA, LOW); //ENA en bajo deshabilita motor A
    digitalWrite(ENE, LOW); //ENE en bajo deshabilita motor 
    delay(2000);   //demora de 2 seg.
    }
          }
int Estado =0;

int sensor =2;

int led =3;

int salida =0;

void setup ()

{

pinMode(sensor, INPUT); //entrada de sensor
pinMode (led, OUTPUT); //salida de led
digitalWrite (led, LOW); //apagar el led
}
if loop()

{
 Estado = digitalRead(sensor);
 if (Estado == 1 && salida==0)
{
 digitalWrite (led, HIGH); //se prende el led
 while(Estado ==1) //cambia sensor a 1
 {
 Estado = digitalRead(sensor);
salida = 1;
 }
 }
if (Estado ==1 && salida ==1)
{
digitalWrite(led, LOW);
 while (Estado ==1)
 { 
 Estado =digitalRead(sensor);
 }
 }
}

errores:

In function 'void loop()':
RETO11:27:3: error: 'VALOR' was not declared in this scope
VALOR = digitalRead(SENSOR);
^~~~~
In function 'void setup()':RETO11:53:6: error: redefinition of 'void setup()'
void setup ()
^~~~~
note: 'void setup()' previously defined here
void setup() {
^~~~~
:
RETO11:61:1: error: expected unqualified-id before 'if'
if loop()
^~
exit status 1
'VALOR' was not declared in this scope

VALOR is not the same as Valor.

C++ is case-sensitive.

I don't know what you are trying to do with the "if loop()" thing, but it is plain wrong

@paudari15

Your post was MOVED to it's current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

To be fair, the old forum had a subtitle to the "installation and troubleshooting" section that said something like "For problems with Arduino itself, NOT your project".

The new forum lacks this useful (but largely neglected) subtitle.

3 Likes

why do you have 2 void setup()?

You had two sketches in the same file. After removing the second sketch and fixing "VALOR" to "Valor" it compiles without error.

int IN1 = 2;     //IN1 a pin digital 2
int IN2 = 3;     //IN2 a pin digital 3
int ENA = 5;     //ENA a pin digital 5
int IN3 = 7;     //IN3 a pin digital 7
int IN4 = 8;     //IN4 a pin digital 8
int ENE = 9;     //ENE a pin digital 9

int SENSOR = 12;
int Valor = 0;
int ANTERIOR = 1;

void setup()
{
  pinMode(IN1, OUTPUT);  //IN1 como salida
  pinMode(IN2, OUTPUT);  //IN2 como salida
  pinMode(ENA, OUTPUT);  //ENA como salida
  pinMode(IN3, OUTPUT);  //IN3 como salida
  pinMode(IN4, OUTPUT);  //IN4 como salida
  pinMode(ENE, OUTPUT);  //ENE como salida

  Serial.begin(9600);
  pinMode(SENSOR, INPUT);
}

void loop()
{
  Valor = digitalRead(SENSOR);
  if (Valor != ANTERIOR)
  {
    if (Valor == HIGH)
      digitalWrite(ENA, HIGH); //ENA en alto habilita motor A
      
    digitalWrite(IN1, LOW); //IN1 en cero logico
    digitalWrite(IN2, HIGH); //IN2 en uno logico

    digitalWrite(ENE, HIGH); //ENA en alto habilita motor A
    digitalWrite(IN3, LOW); //IN3 en cero logico
    digitalWrite(IN4, HIGH); //IN4 en uno logico
    delay(3000);         //demora de 3 seg.

    digitalWrite(ENA, LOW); //ENA en bajo deshabilita motor A
    digitalWrite(ENE, LOW); //ENE en bajo deshabilita motor
    delay(2000);   //demora de 2 seg.
  }
}

The second sketch in the file also compiles if you fix "if loop()" to "void loop()":

int Estado = 0;
int sensor = 2;
int led = 3;
int salida = 0;

void setup ()
{
  pinMode(sensor, INPUT); //entrada de sensor
  pinMode (led, OUTPUT); //salida de led
  digitalWrite (led, LOW); //apagar el led
}

void loop()
{
  Estado = digitalRead(sensor);
  if (Estado == 1 && salida == 0)
  {
    digitalWrite (led, HIGH); //se prende el led
    while (Estado == 1) //cambia sensor a 1
    {
      Estado = digitalRead(sensor);
      salida = 1;
    }
  }
  if (Estado == 1 && salida == 1)
  {
    digitalWrite(led, LOW);
    while (Estado == 1)
    {
      Estado = digitalRead(sensor);
    }
  }
}