Detection de presence avec Arduino

Principe

Une variable est incrémenté a chaque boucle et affichée. Un passage devant le détecteur fait passer l’input a l’état haut et remet a 0 le compteur.

Materiel

Cablage

Code source

#include <Wire.h>
#include <LCDI2C.h>

const int PIN_BOUTON_RESET = 6;
int currentValue = 0;

//I2C display adress (found by I2C scanner
#define LCDI2C_ADDRESS 0x3B

//I2C display setup : Number of lines, char and i2c address of the display
LCDI2C lcd = LCDI2C(2,16,LCDI2C_ADDRESS);             

void setup()
{
  //defined input button
  pinMode(PIN_BOUTON_RESET,INPUT);

  //Active resistor as pull up
  //digitalWrite(PIN_BOUTON_RESET,HIGH);

  //Start I2C bus
  Wire.begin();

  //Init the display, clears the display
  lcd.init();
  lcd.printstr("Starting...");
}

void updateDisplayedValue()
{
  lcd.clear();
  lcd.printstr("Value");
  lcd.setCursor(1,0);
  String atexte=String(currentValue);
  char charBuf[50];
  atexte.toCharArray(charBuf, 50);
  lcd.printstr(charBuf);
}

void loop()
{
  //Read button status
  int aInputDigitalValue = digitalRead(PIN_BOUTON_RESET);
  //Reset the counter if button is press
  if (aInputDigitalValue == HIGH)
  {
    currentValue=0;
  }
  else
  {
    currentValue=currentValue+1;
  }
  //update the display with new value
  updateDisplayedValue();
  //wait a little
  delay(150);
}

librairies

  • LCDI2C : http://www.arduino.cc/playground/Code/LCDi2c
  • Wire : http://www.arduino.cc/en/Reference/Wire
  • Arduino beta 23

1 thought on “Detection de presence avec Arduino

  1. Pingback: Lumiere automatique Arduino | Djynet

Comments are closed.