Ce site contient essentiellement des notes de travail. Le contenu est en constante évolution, et loin d'être achevé. (+ d'infos)
La plupart des documentations informatiques sont orientées Debian / Ubuntu.

Electronique/Hardware/Sensors/TCRT5000

De Ordinoscope.net
Sauter à la navigation Sauter à la recherche

Introduction

TCRT5000

Le TCRT5000 est un émetteur / récepteur en infrarouge. Il convient particulièrement bien comme compte tours ou switch optique.

Caractéristiques

Package type leaded
Detector type phototransistor
Dimensions (L x W x H in mm) 10.2 x 5.8 x 7
Peak operating distance 2.5 mm
Operating range within > 20 % relative collector current: 0.2 mm to 15 mm
Typical output current under test IC = 1 mA
Daylight blocking filter
Emitter wavelength 950 nm
Lead (Pb)-free soldering released
Compliant to RoHS directive 2002/95/EC and in accordance to WEEE 2002/96/EC

Câblage

TCRT5000 pinout.jpg

Exemples

Compte tour (sériel)

#define RPM_PIN 2

unsigned long sum = 0;
unsigned long count = 0;

void setup() {
  pinMode (RPM_PIN, INPUT);

  Serial.begin (115200);
  Serial.println ("ready");

  attachInterrupt (0, rpmISR, RISING);
}

void loop() {
  delay (500);
  detachInterrupt (0);

  freq = (sum) ? ((float) count * 1000000.0 / (float) sum) : 0.0;
  rpm = freq * 60;

  Serial.print (freq);
  Serial.print ("Hz - ");
  Serial.print (rpm);
  Serial.println ("rpm");

  sum   = 0;
  count = 0;

  attachInterrupt (0, rpmISR, RISING);
}

void rpmISR () {
  static unsigned long last_micros = 0;

  if (last_micros) {
    sum += micros () - last_micros;
    count++;
  }

  last_micros = micros ();
}

Compte tour (TM1637)

#define RPM_PIN 2

#include "TM1637.h"
 
#define CLK 4    
#define DIO 5
TM1637 tm1637 (CLK,DIO);

unsigned long sum = 0;
unsigned long count = 0;

void setup() {
  pinMode (RPM_PIN, INPUT);
  tm1637.init();
  tm1637.set (BRIGHT_TYPICAL);  //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  tm1637.display (0, 0);
  tm1637.display (1, 0);
  tm1637.display (2, 0);
  tm1637.display (3, 0);
  attachInterrupt (0, rpmISR, RISING);
}

void loop() {
  float freq;
  int rpm;
  
  delay (1000);
  detachInterrupt (0);
  
  freq = (sum) ? ((float) count * 1000000.0 / (float) sum) : 0.0;
  rpm = freq * 60;
  
  tm1637.display (0, rpm/1000);
  rpm = rpm % 1000;
  tm1637.display (1, rpm/100);
  rpm = rpm % 100;
  tm1637.display (2, rpm/10);
  rpm = rpm % 10;
  tm1637.display (3, rpm);
  
  sum = 0;
  count = 0;
  
  attachInterrupt (0, rpmISR, RISING);
}

void rpmISR () {
  static unsigned long last_micros = 0;

  if (last_micros) {
    sum += micros () - last_micros;
    count++;
  }

  last_micros = micros ();
}

Références