레이블이 아두이노인 게시물을 표시합니다. 모든 게시물 표시
레이블이 아두이노인 게시물을 표시합니다. 모든 게시물 표시

2017년 8월 8일 화요일

유량센서 사용하기 - 인터럽트 이용

유량센서 작동방식이 홀센서가 내부에 있어서 1회전에 할때마다 트리거가 발생하는 원리이므로

트리거 신호를 인터럽트에 연결시켜서 회전수를 카운트 해서 유량을 계산하는 코드입니다.

신호선에는 10K 저항을 연결해서 풀업저항으로 만들어 줍니다. 

1회전시 유량은 유량센서 용량에 따라 다르므로 스펙에 맞게 공식을 수정해야 할 것 같습니다.

제가 구한 유량센서는 The frequency calculation = constant flow rate (L/min) 7.5 * unit time (in seconds)

분당 7.5 리터니깐 초당 계산하니깐 60을 더 곱해줍니다.

인터럽트를 사용하니 SoftSerial은 사용할 수 없을것 같네요. 같이 인터럽트를 사용하니 WiFi을 연결하려면

하드웨어 시리얼을  이용해야 할 듯 합니다.

flow meter arduino

아래 사이트를 코드를 참고하였습니다.


// Reading liquid flow rate using an Arduino 
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn@thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com 

volatile int NbTopsFan;            //measuring the rising edges of the signal
int Calc; 
int hallsensor = 2;                //The pin location of the sensor

void rpm ()                        //This is the function that the interupt calls
{
  NbTopsFan++;                     //This function measures the rising and falling edge of signal
}                                  //The setup() method runs once, when the sketch starts

void setup() 

{
 pinMode(hallsensor, INPUT);       //initializes digital pin 2 as an input
 Serial.begin(9600);               //This is the setup function where the serial port is initialised
 attachInterrupt(0, rpm, RISING);  //and the interrupt is attached
}
                                   // the loop() method runs over and over again
                                   // as long as the Arduino has power
void loop () 
{
 NbTopsFan = 0;                    //Set NbTops to 0 ready for calculations
 sei();                            //Enables interrupts
 delay (1000);                     //Wait 1 second
 cli();                            //Disable interrupts
 Calc = (NbTopsFan * 60 / 7.5);    //(Pulse frequency x 60) / 7.5Q = flow rate in L/hour
 Serial.print (Calc, DEC);         //Prints the number calculated above
 Serial.print (" L/hour\r\n");     //Prints "L/hour" and returns a new line
}

온도 습도 측정하기 - SHT71 센서이용

아두이노를 이용하여 SHT71 센서를 이용하여 온도, 습도를 측정하는 방법입니다.

측정값을 시리얼 모니터로 확인가능합니다.

/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHTxx-series (SHT10,
 * SHT11, SHT15, SHT71) sensor.
 *
 * Copyright 2012 JAS
 */</code>
#include "SHTxx.h"
// Specify data and clock connections and instantiate SHTxx object
 // Sensor SHT71 power with vccPin & gndPin
 #define clockPin 8
 #define vccPin 9
 #define gndPin 10
 #define dataPin 11
SHTxx sht71(dataPin, clockPin);
void setup()
 {
 Serial.begin(9600); // Open serial connection to report values to host
 Serial.println("Starting up");
 // Power sensor
 pinMode(gndPin, OUTPUT);
 pinMode(vccPin, OUTPUT);
 digitalWrite(vccPin, HIGH);
 digitalWrite(gndPin, LOW);
 }
void loop()
 {
 float temp_c;
 float temp_f;
 float humidity;
// Read values from the sensor
 temp_c = sht71.readTemperatureC(); //섭씨
 temp_f = sht71.readTemperatureF(); //화씨
 humidity = sht71.readHumidity(); //습도
// Print the values to the serial port
 Serial.print("Temperature: ");
 Serial.print(temp_c, DEC);
 Serial.print("C / ");
 Serial.print(temp_f, DEC);
 Serial.print("F. Humidity: ");
 Serial.print(humidity);
 Serial.println("%");
delay(2000);
 }

첨부한 SHTxx.rar 파일을 받아 압축을 풀어 아두이노 라이브러리에 폴더를 추가하면 됩니다.

라이브러리 추가하는 방법은 http://cafe.naver.com/diymaker/6 글을 참고하세요.

참 쉽죠잉~ ^^

SHT71 센서는 정확도는 높지만 비싸서 취미로 사용하기는 부담스럽죠. 

다음에는 좀더 저렴한 DHT11보다 성능이 향상된 DHT22 온습도 센서 사용방법을 알아 보겠습니다.

#참고사이트