Jun 1, 2020

[Arduino code] Motor/Servo RPM measurement using photodiode (아두이노에서 포토다이오드를 이용한 모터/서보모터 RPM 측정)

- RPM measurement of motor/servo motor using photo diode.
- 포토 다이오드를 활용한 모터/서보모터의 RPM 측정.
- Sensor: SZH-EKAD-109
https://www.devicemart.co.kr/goods/view?no=1329652

- 원리
포토 다이오드: 빛에너지 -> 전기에너지
발광 다이오드: 전기에너지 -> 빛에너지
https://youtu.be/SFc673lEyQA

- 코드
const byte interruptPin = 2;
volatile int pre_count, count;
unsigned long skip_milli_time = 100; 
unsigned long cur_time = 0;
unsigned long pre_time = 0;

void setup() {
  // put your setup code here, to run once:
  count = 0;
  pre_count = 0;
  attachInterrupt(digitalPinToInterrupt(interruptPin), CountServoRotation, FALLING);
  Serial.begin(9600);
  Serial.println("start");
}

void loop() {
  // put your main code here, to run repeatedly:
}

void CountServoRotation() {
  cur_time = millis();
  if ( (cur_time - pre_time) > skip_milli_time ) {
    count++;
  }
  pre_time = millis();
  if (pre_count != count) {
      Serial.print("Rotation #:\t");
      Serial.println(count);
      pre_count = count;
  }
}
- 연결 모습
 Sensor Arduino
 VCC 3.3 V
 GND GND
 OUT Pin 2

        









- 동영상
At low-speed rotation 

At high-speed rotation 

No comments:

Post a Comment