Silícios LabPCBWay
Published © GPL3+

Position Detector Sensor by the Active Time

In this article, you will learn how to trigger a load according to the time the position sensor is actuated.

BeginnerFull instructions provided30 minutes2,493
Position Detector Sensor by the Active Time

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
PIR Sensor Infrared - UTSOURCE
×1
Resistor 10kR - UTSOURCE
×1
LED 5mm - UTSOURCE
×1
Arduino UNO - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Millis function code

C/C++
void setup()
{
  
    pinMode(10, INPUT);  //Pino de conexao do botao
    pinMode(13, OUTPUT); //Pino de conexao do LED da placa do Arduino UNO

}

    unsigned long int tempo_atual = 0; //Variavel utilizada para armazenar o tempo de execucao atual do codigo
    unsigned long ultimo_tempo = 0; //Variavel utilizada para armazenar o ultimo valor armazenado na variavel tempo_atual

void loop()
{
  
    int pino = digitalRead(10); //0
    tempo_atual = millis(); //7000
    
    if(pino == 0)
    {       //7000
      ultimo_tempo = tempo_atual; //7000
      digitalWrite(13, LOW); //LED Desligado
    }
    
    if((pino == 1) && (tempo_atual - ultimo_tempo >= 3000))
    {
      digitalWrite(13, HIGH); //LED Ligado
      ultimo_tempo = tempo_atual;//5000
    }  
    
} 

Credits

Silícios Lab

Silícios Lab

73 projects • 176 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

94 projects • 149 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments