시간과 능력은 부족하지만


오늘은 신나고 재미있는 실습을 많이 함!

첫번째로 온습도 센서를 사용해 보았다.




회로 사진.

회로도는 책에 있으니 생략!

요즘은 간단한 회로를 책 안보고 구성하는 연습을 하고 있는데....


(숙연)



#include <DHT11.h>

int pin=4;

DHT11 dht11(pin); 

void setup()

{

   Serial.begin(9600);

  while (!Serial) {

      ; // wait for serial port to connect. Needed for Leonardo only

    }

}


void loop()

{

  int err;

  float temp, humi;

  if((err=dht11.read(humi, temp))==0)

  {

    // Serial.print("temperature:");

    Serial.println(temp);

    // Serial.print(" humidity:");

    // Serial.print(humi);

    // Serial.println();

  }

  else

  {

    Serial.println();

    Serial.print("Error No :");

    Serial.print(err);

    Serial.println();    

  }

  delay(DHT11_RETRY_DELAY); //delay for reread

}




코드! 각주처리한 부분을 살리면 시리얼모니터에



 

요렇게 뜬다.

그렇지만 우리가 오늘 쓴 것은 시리얼 모니터가 아니라





시리얼 플로터임




시리얼플로터에는 이렇게 온도가 그래프로 표시된다.

각주처리해서 변수를 하나만 살리는 바람에 온도만 표시됐지만,

습도를 살리면 습도가 표시되겠지


시리얼 플로터의 진가(?)는 조금 후에 계속!




오늘의 ★하이라이트★는 capacitive sensing

코코아팹 홈페이지에 나와 있는 아주 간단한 회로를 연결한다.




요렇게


#include <CapacitiveSensor.h>


/*

 * CapitiveSense Library Demo Sketch

 * Paul Badger 2008

 * Uses a high value resistor e.g. 10M between send pin and receive pin

 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.

 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin

 */



CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil


void setup()                    

{

   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example

   Serial.begin(9600);

}


void loop()                    

{

    long start = millis();

    long total1 =  cs_4_2.capacitiveSensor(30);

    long total2 =  cs_4_6.capacitiveSensor(30);

    long total3 =  cs_4_8.capacitiveSensor(30);


    Serial.print(millis() - start);        // check on performance in milliseconds

    Serial.print("\t");                    // tab character for debug windown spacing


    Serial.print(total1);                  // print sensor output 1

    Serial.print("\t");

    Serial.print(total2);                  // print sensor output 2

    Serial.print("\t");

    Serial.println(total3);                // print sensor output 3


    delay(10);                             // arbitrary delay to limit data to serial port 

}


코드에는 핀 2, 6, 8로 3개를 센싱할 수 있게 되어 있지만 우리는 무능하니까(?) 하나만..

코드에 capacitive sensing에 대한 유익한 설명이 써있는데요 각주로.. 우리는 1메가 옴 저항을 사용했다.

중간프로젝트 때 산 부품 중에 47메가 옴 저항 있는데 나중에 그걸로 해봐야지




저는 전도성펜이 다 떨어진고로...(슬픔)

연필로 열심히 피아노를 그려보았습니다. 저의 중간 프로젝트가 피아노니까

근데 중간프로젝트 큰일남




손대면 요렇게 그래프가 쭉!




그래서 2개 해보고 싶어서 은박접시 집어옴




근데 뭔가 센서들 사이에 간섭이 있는지

하나에 손대면 다른 하나도 올라간다. 왜 저런담