0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduino通過カウンタ

Posted at

Arduino通過カウンタ

  • Arduinoマイコン + レーザ発信機 + 光度センサ + サーボモータ + 計算機
  • 通過カウンタを作って欲しいと依頼を受けて作ったもの。
  • incする手法は計算機のボタンをサーボで押すという簡単(手抜き)仕様。
  • bool t=false はセンサ前で立ち止まっていると連続incされるのでその防止用。
  • 隔たりなく通過すると複数でも一つ(一人)としてカウントされる。
  • 適当なポートにブザーもしくはFET経由で付けて非受光部のelse文を直せば侵入警報器になる。アクション映画等で見かけるアレです。
  • (https://qiita.com/inf102/items/9eec6471b1c587995a7b)

1.試作動画

2.Arduino R3マイコン ATmega328チップ

P1580846.JPG

  • 7PIN サーボデータ線
  • 5PIN 光度センサデータ線

3.システム全景

P1580841.JPG

4.c++ Sourcecode

////////////////////
// Arduino Counter.
// inf102 S.H 2025.
////////////////////

#include <Servo.h>

Servo myservo;
const int SV_PIN = 7;
const int PIN_ANALOG_INPUT = 5;
static bool t=false;

void setup() {
    myservo.attach(SV_PIN, 500, 2400);
    Serial.begin( 9600 );
}

void loop() {
    int i = analogRead( PIN_ANALOG_INPUT );
    
    float f = i * 5.0 / 1024.0;
    Serial.print (f); 
    
    if ( f>=4.0) {
        Serial.print ("レーザ受光中\r\n"); 
        t=false;
    }
    else{
        Serial.print ("レーザ非受光\r\n"); 
        if (t==false){
            myservo.attach(SV_PIN, 500, 2400);
            myservo.write(33);
            delay(300);
            myservo.write(0);
            delay(300);
            myservo.detach();
            t=true;
        }
    }
    delay (50);
}
  • 参考 LR44等ボタン電池は意外と早くなくなるので不要な単三電池に無理やり換装
    数年使ってます。
    P1440752.JPG
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?