I need quick help with the activation time of a motor

I need a motor to activate for 2 seconds after the variable float is indicated on the A1. I’m working with an arduino uno

the motor must activate after the battery indicates the minimum float

 int ledPin = 4; //Led no pino 4 
int ldrPin = 0; //LDR no pino analígico A0
int ldrValor = 0; //Valor lido do LDR
int ledPint = 7; //Led no pino 7 
int batPin = 1; //bateria no pino analog 1
int batValor =1; //Valor lido da bateria


float voltaje ;
float maximo = 5.0;
float minimo = 0.5;

int servoMotor = 2; //Servomotor no pino 2 
int servoMotor_inver = 12; // Servomotor inversor no pino 12
int ledPin_in = 8; // Led indicador no pino 8 


void setup() {
 pinMode(servoMotor_inver,OUTPUT); // define a porta 12 como saida 
 pinMode(ledPin,OUTPUT); //define a porta 4 como saída
 pinMode(servoMotor,OUTPUT); // define a porta 2 como saida 
 Serial.begin(9600); //Inicia a comunicação serial
}
 
void loop() {
 
 ///ler o valor da bateria 
 batValor = analogRead(batPin); //O volar lido  ser entre 0 e 1023
 voltaje = 0.0048 * batValor;
 Serial.print("Voltaje: ");
 Serial.println(voltaje);

 ///ler o valor da bateria 
 //se a voltagem for minima ativar servomotor e led indicador
 if (voltaje<=minimo) digitalWrite(servoMotor,HIGH); 
 if (voltaje<=minimo) digitalWrite(ledPin_in,HIGH); 
 delay(800);
 if (voltaje=minimo) digitalWrite(ledPin_in,LOW);
 if (voltaje=minimo) digitalWrite(servoMotor,LOW);
 
 //se a voltagem for maxima ativar o servomotor inverso e led indicador 
 if (voltaje>=maximo) digitalWrite(servoMotor_inver,HIGH);
 if (voltaje>=maximo) digitalWrite(ledPin_in,HIGH);
 delay(800);
 if (voltaje=maximo) digitalWrite(ledPin_in,LOW);
 if (voltaje=maximo) digitalWrite(servoMotor_inver,LOW);
 
  
  ///ler o valor do LDR
 ldrValor = analogRead(ldrPin); //O valor lido será entre 0 e 1023
 ///ler o valor do LDR
 //se o valor lido for maior que 700, liga o led
 if (ldrValor>= 900) digitalWrite(ledPin,HIGH);
 // senão, apaga o led
 else digitalWrite(ledPin,LOW);
 
 digitalWrite(ledPint, HIGH);
 delay(350); // esperar por 1000 millisecond(s)
 digitalWrite(ledPint, LOW);
 delay(350); // esperar por 1000 millisecond(s)
  
 //imprime o valor lido do LDR no monitor serial
 Serial.println(ldrValor);
 delay(25);
  }

RafaelOC:
I need a motor to activate for 2 seconds after the variable float is indicated on the A1. I’m working with an arduino uno

the motor must activate after the battery indicates the minimum float

int ledPin = 4; //Led no pino 4 

int ldrPin = 0; //LDR no pino analígico A0
int ldrValor = 0; //Valor lido do LDR
int ledPint = 7; //Led no pino 7
int batPin = 1; //bateria no pino analog 1
int batValor =1; //Valor lido da bateria

float voltaje ;
float maximo = 5.0;
float minimo = 0.5;

int servoMotor = 2; //Servomotor no pino 2
int servoMotor_inver = 12; // Servomotor inversor no pino 12
int ledPin_in = 8; // Led indicador no pino 8
unsigned long duracao;

void setup() {
pinMode(servoMotor_inver,OUTPUT); // define a porta 12 como saida
pinMode(ledPin,OUTPUT); //define a porta 4 como saída
pinMode(servoMotor,OUTPUT); // define a porta 2 como saida
pinMode(servoMotor, INPUT);
Serial.begin(9600); //Inicia a comunicação serial
}

void loop() {

///ler o valor da bateria
batValor = analogRead(batPin); //O volar lido  ser entre 0 e 1023
voltaje = 0.0048 * batValor;
Serial.print("Voltaje: ");
Serial.println(voltaje);

///ler o valor da bateria
//se a voltagem for minima ativar servomotor e led indicador
if (voltaje<=minimo) digitalWrite(servoMotor,HIGH);
if (voltaje<=minimo) digitalWrite(ledPin_in,HIGH);
delay(800);
if (voltaje=minimo) digitalWrite(ledPin_in,LOW);
if (voltaje=minimo) digitalWrite(servoMotor,LOW);

//se a voltagem for maxima ativar o servomotor inverso e led indicador
if (voltaje>=maximo) digitalWrite(servoMotor_inver,HIGH);
if (voltaje>=maximo) digitalWrite(ledPin_in,HIGH);
delay(800);
if (voltaje=maximo) digitalWrite(ledPin_in,LOW);
if (voltaje=maximo) digitalWrite(servoMotor_inver,LOW);

///ler o valor do LDR
ldrValor = analogRead(ldrPin); //O valor lido será entre 0 e 1023
///ler o valor do LDR
//se o valor lido for maior que 700, liga o led
if (ldrValor>= 900) digitalWrite(ledPin,HIGH);
// senão, apaga o led
else digitalWrite(ledPin,LOW);

digitalWrite(ledPint, HIGH);
delay(350); // esperar por 1000 millisecond(s)
digitalWrite(ledPint, LOW);
delay(350); // esperar por 1000 millisecond(s)
 
//imprime o valor lido do LDR no monitor serial
Serial.println(ldrValor);
delay(25);
  }

Congratulations on properly posting your code the first time!!! What is the problem, then? Does your code work? If not, what does it do?

A schematic of how you have the project wired and powered might help answering any question. We can’t see what you have and how you have it all wired up.

Paul

if (voltaje=maximo)
Perhaps you meant:
if (voltaje == maximo)

Paul_KD7HB:
Congratulations on properly posting your code the first time!!!! What is the problem, then? Does your code work? If not, what does it do?

A schematic of how you have the project wired and powered might help answering any question. We can't see what you have and how you have it all wired up.

Paul

the engine turns on as soon as the battery reaches the minimum that is in the code sock the way I did it it turns off soon as it is = minimum or maximum and not that I want it I want it to run for so many seconds until it reaches the position as soon as the arduino receives the information of the minimum and depart from that position when it reaches the maximum

already have circuit diagram to view

larryd:
if (voltaje=maximo)
Perhaps you meant:
if (voltaje == maximo)

I am doing a course where I have to play with the Arduino I am the most advanced of my class in this module. My course and electronic automation and command
I like to program in arduino this and only my first project only I miss these parts the way I did it wrong is not the way intended

A = B takes the value from B and puts it into A.

A == B checks to see if A and B have the same value.

See:
https://www.arduino.cc/reference/en/language/structure/control-structure/if/

It is not a good idea to compare floating point values for equality using == An extremely small variation that would be inconsequential in the real world will cause the test to fail.

Much better to use >= or <=

…R

Robin2:
It is not a good idea to compare floating point values for equality using == An extremely small variation that would be inconsequential in the real world will cause the test to fail.

Much better to use >= or <=

…R

I have already used this in my program so the way it will not reach the position I want will stop when float minimum or maximum is equal to the value of the voltage .

if the voltage is maximum or minimum suddenly the motor can stop in the position that I do not want

Since “voltaje” is a physical value you must have a tolerance, it can’t be a pure number.
I mean, “5V” must be intended as “5V +/-0.1V”, aka [4.9 - 5.1]V.

You should check the value “voltaje” this way:

if ( abs(voltaje - maximo) < tolerance )

“tolerance” can be 0.5V or 0.0001V or whatever, it depends on your project.