ESTOU REALIZANDO UM PROJETO E ESTOU COM UM PEQUENO PROBLEMA NO CÓDIGO ARDUÍNO
MEU PROBLEMA E QUE MEU PROJETO POSSUI DOIS SENSORES INFRAVERMELHOS UM NO INICIO E OUTRO 30CM A FRENTE, FIZ ESSE CÓDIGO E FUNCIONA SO QUE PRECISA DE UM REPARO.
O SENSOR 1 DETECTA PRESENÇA LIGA O MOTOR, EM SEGUIDA PASSA PELO SENSOR 2 E MANTEM O MOTOR LIGADO SÓ QUE POR CAUSA DO DELAY NO FINAL DO CODIGO, SE O SENSOR 1 TORNAR A DETECTAR PRESENÇA A FUNÇÃO DE CONTINUAR COM MOTOR LIGADO NÃO ESTA FUNCIONANDO.
PRECISO FAZER UMA ALTERAÇÃO NO CÓDIGO PARA QUE QUANDO O DELAY ESTIVER CONTANDO O TEMPO, SE ALGUM SENSOR DETECTAR PRESENÇA CANCELAR O DELAY E EXECUTAR A FUNÇÃO QUE ESTA DETERMINADA NO CODIGO.
CODIGO DO MEU PROJETO
int motor = 3;
int sensor = 4;
int sensor1 = 5;

int estado_sensor = 0;
int estado_sensor1 = 0;

void setup()
{
Serial.begin(9600);
// Define o pino do sensor como entrada
pinMode(sensor, INPUT);
pinMode(sensor1, INPUT);
// Define o pino do MOTOR como saida
pinMode(motor, OUTPUT);
Serial.println("Teste sensor infravermelho Arduino");
}

void loop()
{
estado_sensor = digitalRead(sensor);
if (estado_sensor == 0)
{
// liga o motor
digitalWrite(motor, HIGH);
// Envia mensagem para o Serial Monitor
Serial.println("Movimento detectado!");
}
estado_sensor1 = digitalRead(sensor1);
if (estado_sensor1 == 0)
{
// liga o motor
digitalWrite(motor, HIGH);
// Envia mensagem para o Serial Monitor
Serial.println("Movimento detectado!");
estado_sensor1 = digitalRead(sensor1);
if (estado_sensor1 == 1)
{
delay(2600); (APOS O DELAY DESLIGAR O MOTOR)
digitalWrite(motor,LOW );
}
}

}

Exibições: 188

Responder esta

Respostas a este tópico

Boa tarde JN.

Só ajudo amigos que não colam sketch na área de texto do tópico.
Sou velho e  ranzinza.
Se remover o code, e anexar como arquivo, posso reconsiderar minha decisão de não ajudá-lo.

Leia: http://labdegaragem.com/forum/topics/sugest-o-de-como-postar

Rui

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço