'아두이노'에 해당되는 글 91건

  1. 2017.05.07 Hardware | Arduino water level sensor
  2. 2017.04.16 Software | CH341SER driver 최신 업데이트 하기
  3. 2017.04.11 Software | Arduino IDE 실행시키기
  4. 2017.03.31 Hardware | Arduino nano 조립기
  5. 2017.03.09 Hardware | BME280 sensor
  6. 2017.03.06 Hardware | Arduino BMP280 고도/온도/기압 센서
  7. 2017.03.06 Software | Arduino IDE 에서 library 추가하기
  8. 2017.03.05 Hardware | Arduino 비접촉 온도센서 GY-906 MLX90614
  9. 2017.03.05 Hardware | Arduino Ambient Light TEMT6000 Sensor
  10. 2017.03.05 Hardware | Arduino 로 buzzer 소리내기

Hardware | Arduino water level sensor

|

1. 시작하기

어항을 시작하면서 물 수위에 대한 자도 조절 기능을 만들고 싶었습니다.

물론 부레가 달린 물탱크를 사용하면 수위가 내려가면 자동으로 물 충전을 시켜주기는 하지만,

뭔가 전자적으로 만들고 싶습니다.



또한, IoT 하면 수위 변동시 alert 등도 스마트폰으로 알람을 띄워 줄 수 있겠죠.


여기선, 우선 단순 구동 확인만 해보겠습니다.



2. 구입하기

AliExpress 에서 "water sensor" 를 검색하면 아래와 같은 센서가 보입니다.

구입합니다.



실제 사진입니다.



뒷면





3. layout

Pin은 다음과 같이 연결합니다.

Water Level Sensor | Arduino Nano
---------------------------------
         S         |     A0
         +         |    3.3V
         -         |     GND
---------------------------------


빵판 layout



실제 연결한 장면입니다.




4. sketch

/*Code for Liquid Level Sensor Circuit Built with an Arduino*/

const int sensorPin= 0; //sensor pin connected to analog pin A0
int liquid_level;

void setup() {
Serial.begin(9600); //sets the baud rate for data transfer in bits/second
pinMode(sensorPin, INPUT); //the liquid level sensor will be an input to the arduino
}

void loop() {
liquid_level= analogRead(sensorPin); //arduino reads the value from the liquid level sensor
Serial.println(liquid_level); //prints out liquid level sensor reading
delay(100); //delays 100ms
}


5. 측정

구동 잘 되고, 물컵 이용하여 측정해 봤습니다.



센서 끝부터 물에 담구면 수치가 변하는 것을 볼 수 있습니다.



센서 끝단은 측정치가 많이 올라가고 (0~200), 그 위에는 (200~400) 천천히 올라갑니다.

일정한 피치로 측정이 될려면 좀더 정확한 sensor 를 구입해야 할 듯 합니다.



한가지 좋은 점은 작은 LED 가 있어서, 구동중이라는 것을 보여주는 것 정도?



FIN

이제 뭘하지?


And

Software | CH341SER driver 최신 업데이트 하기

|

1. 시작하기

Chinese clone 인 arduino nano 를 이용하여 data 를 전송하는 프로그램을 돌려보면, 유난히 buffer 부족에 대한 에러가 많이 나옵니다.


아마 정품과 구성품이 다른 부품이 그 원인인 듯 하고,

또한 이를 제조한 WCH 사의 driver를 통해서만 arduino nano 에 접근이 가능하므로 driver 를 의심해 보기로 합니다.



2. 찾기

외국 친구들이 설명해 놓은 chinese clone driver 는 예전 버전이 많습니다.

WCH 가 만들었으니, "http://www.wch.cn/" 사이트에서 찾아보기로 합니다.


글은 까만색이요 흰색은 종이.... 레벨입니다. (중국어 모름)



다행이 검색란이 있으니, 찾고자 하는 driver 의 정확한 명칭인 "ch340ser" 을 칩니다.



오호이~ 나왔습니다.

여러 OS 별로도 연관 파일에 표시되어 있습니다.




3. Windows용

파일을 받고 실행해 봅니다.


역시 드라이버 버전이 바뀌어 있습니다!




혹시 몰라 장치관리자 > COM6 > 오른쪽 클릭하여 "드라이버 갱신" 에서 인터넷에서 갱신하면, 한번 더 하더군요.






FIN

뭐가 달라졌는지 여러가지로 해봐야겠습니다.

And

Software | Arduino IDE 실행시키기

|

1. 시작하기

Arduino 에 프로그램을 밀어 넣고 실행시키려면, arduino IDE 가 필요합니다.

Arduino IDE 를 실행시키려면, USB로 연결되는 arduino 본체를 인식해야 합니다.


여기에 더하여, 저는 Chinese clone 이므로, 일일히 driver 를 찾아서 설치해 줘야 합니다.


Arduino IDE 를 실행시키면 Happy Coding 의 세계가 열리는 것이죠.


자, 시작해 볼까요?



2. 파일 받기

다운로드 받는 곳은 아래와 같습니다.

http://www.arduined.eu/ch340g-converter-windows-7-driver-download/






3. 드라이버 인스톨

파일을 받고 압축을 풀면 SETUP 실행파일이 있습니다.

저는 Windows 7 64bit 이므로 "DRVSETUP64.exe" 파일을 실행시킵니다.



실행시키면 다음과 같은 화면이 뜹니다.



INSTALL 을 하면 완료 됩니다.



위의 과정을 거치기 전에는 USB를 꼽으면 아래 스샷처럼 인식할 수 없는 기기로 보입니다.



Driver 를 인스톨 하고 USB를 꼽으면 아래 스샷처럼 기기를 정식으로 등록하게 됩니다.



드라이버를 인식했습니닷 !!!

Port 정보를 잘 알아둬야 합니다. 여기서는 COM6 네요.





4. IDE 실행

이제 arduino 기기를 OS에서 인식했으니, 설치한 IDE 를 실행합니다.

IDE 다운로드는 다음 URL 에서 가능합니다.


https://www.arduino.cc/en/main/software


설치 후, 실행시킵니다.


작년 처음 시작할 때는 1.6 이었는데, 지금은 1.8 이네요.




5. 인식 시키기

IDE 를 실행시키면 바로 되는게 아니라, USB로 연결된 arduino nano 를 정식으로 등록해 줘야 합니다.

기기 등록은, Tools > Board, Processor 와 Port 정보 입니다.


Board 는 "Arduino Nano" 를 선택합니다.



Processor 는 "ATmega328" 을 선택합니다.



저의 경우의 Port 는, 아까 확인했던 "COM6" 를 선택합니다.



연결이 완료되면 beacon 신호를 보내는 것처럼 ready 상태를 나타내 줍니다.



이제 준비 완료 입니다!

이젠 Happy Coding 이지요.



FIN

이제 뭘하지?

And

Hardware | Arduino nano 조립기

|

1. 시작하기

Aliexpress 에서 판매되는 Arduino nano 는 2가지 버전이 있습니다.

조립되어 있고 USB cable 이 포함되어 있는 버전과, 케이블이 없고 다리들을 납땜해야 하는 버전.


한 700원 차이나지만, 궂이 cable 도 필요 없고 돈도 아낄 겸, 납땜해야 하는 버전도 하나 구입합니다.



납땜 연습에도 적격입니다.



2. 도착

물건 도착하자 마자 찍어놓은 사진입니다.



뒷모습



앞모습



MEGA328P 프로세서 입니다.



3. 완성

그냥 납땜 합니다.

빵판에 다리를 고정시켜 놓고 납땜하면 편합니다.



위에가 납땜한 버전입니다.

layout 상 다른 부분은 오실레이터가 수평이 아닌, 프로세서랑 나란이 위치하고 있는데 다릅니다.




4. 테스트

전원을 넣으면 빨간불이 켜지면서 ready 한 상태가 됩니다.



BME280 sketch 를 올리고 돌려보면 정상 작동하는 것을 확인하였습니다.

우훗!



성공입니다.



FIN

더 필요하면 납땜 버전을 계속 구입하겠습니다.


이제 뭘하지?

'Hardware' 카테고리의 다른 글

Hardware | BMR-C1 heatsink  (0) 2017.04.26
Hardware | Sharp GP2Y1010AU0F dust sensor  (0) 2017.03.31
Hardware | GeForce GTX 560 Ti 수리 실패기  (0) 2017.03.16
Hardware | BME280 sensor  (0) 2017.03.09
Hardware | DSO150 Oscilloscope  (0) 2017.03.07
And

Hardware | BME280 sensor

|

1. 시작하기

BMP280 을 구동시키면서 googling 해보면, "Humidity = 습도" 값을 표시해주는 글들이 심심치 않게 보였습니다.

그래서 열씸히 Humidity 를 표현하려고 이리저리 시도해 봤습니다.


또, Aliexpress 에서 구입한 BMP280 제품을 보면 GY-BME/P280 이라고 표시되어 있습니다.

할거 다 해봤습니다.


아니 그런뒈.... 그런뒈! (컬투 버전) 



2. 알아버렸다

그렇습니다. Humidity 를 하려면, 정확하게 BME280 이 있어야 합니다. BMP280 로는 안되는 것이였습니다.

아놔.




나를 깨우쳐준 글.



정말 되냐 안되냐를 확인할 수 있는 글.



3. 넌 누구냐

직접 확인해 봅니다.

SparkFun 이 제공하는 'I2C_ReadAllData.ino' sketch 를 통해서 0x58 이냐, 0x60 이냐를 확인해 봅니다.


SparkFun Library 를 아래 링크를 통해 다운받고 설치합니다.


 - https://github.com/sparkfun/SparkFun_BME280_Arduino_Library


마지막으로 I2C address 를 0x77 > 0x76 으로 바꾸고 실행해 봅니다.



아놔... 넌 BMP280 이구나...



4. BME280 구입

정말 정말 Humidity 수치를 알고 싶습니다.


한꺼번에 구입하지 못 한것을 탓하면서, 다시 주문을 넣습니다.

3주만에 오네요.



2개를 주문해서 앞뒤로 한 샷에 넣어 봅니다.



위의 부분이 센서군요. 보통 Bosch 에서 만든다고 하는데, Bosch 각인은 아닌것 같습니다.




이놈이 진짜 BME280 인지, 바로! 확인해 봅니닷!



오옷! 맞네요.
(정보를 알려준 외국인 친구 감사~!)



5. 구동해 보기

Library 를 다운받아 설치합니다.


 - https://github.com/adafruit/Adafruit_BME280_Library


I2C address 를 0x77 > 0x76 으로 꼭 변경해야 합니다.



이거 수정하지 않고 한참 해멨습니다.



이제 example sketch 를 로딩합니다.



소스는 다음과 같습니다.


/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include 
#include 
#include 
#include 

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    Serial.println(F("BME280 test"));

    bool status;
    
    // default settings
    status = bme.begin();
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}

layout 은 다음과 같고, pin 구성은 BMP280 과 같이 I2C 연결과 같습니다.


- VIN : 3.3V

- GND : GND

- SCL : A5

- SDA : A4



빵판에 연결합니다.




6. 결과

얏호~!!!

이제 Humidity 를 볼 수 있어요.



더 사용폭이 많은 BME280 만 만들지, 왜 BMP280 을 만드냐고 살짝 울분을 토해봅니다..



FIN

이제 뭘하지?

And

Hardware | Arduino BMP280 고도/온도/기압 센서

|

1. 시작하기

온도, 기압, 고도센서가 하나의 기판에 달려있는, 참 고마원 BMP280 을 가지고 놀아봅니다.

원래는 Adafruit 에서 나온 정식 발매품이 있는 듯 하나, Aliexpress 를 사랑하는 저로서는 clone 품을 가지고 놀아봅니다.





2. Library

2가지 library 를 설치해야 합니다.

- Adafruit Sensor

- Adafruit BMP280


먼저, Adafruit Sensor library 를 설치합니다.

- https://github.com/adafruit/Adafruit_Sensor




그리고, BMP280 용 library 를 다운로드 받아 설치합니다.

     - https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout/wiring-and-test




맨 마지막으로, clone 부품을 구동시키기 위해,

"Adafruit_BMP280.h" 파일을, 아래처럼 I2C 어드레스에 대해 0x77 > 0x76 으로 수정해 줘야 합니다.





3. 소스코드

위의 library 를 추가하였으면, "File > Examples > Adafruit BMP280 Library > bmp280test" 를 선택할 수 있습니다.




/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout 
  ----> http://www.adafruit.com/products/2651

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required 
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include 
#include 
#include 
#include 

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
}

void loop() {
    Serial.print(F("Temperature = "));
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print(F("Pressure = "));
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}



4. Layout

PIN 배열은 다음과 같습니다.

- VCC : 3.3v

- GND : GND

- SCL : A5

- SDA : A4







5. 결과

잘 나오네요.

실재로 사용시에는 기준값을 조금 수정해야 할 것 같습니다만, 일단 성공입니다.




6. 확장

아래 링크에서는 OLED 를 사용한 방법을 소개하고 있습니다.


- http://www.instructables.com/id/Standalone-Arduino-Altimeter/


바로 따라해 봅니다.

우선 아래 용도로 사용될 BMP280 library 를 다운로드 받고, libraries 폴더에 위치시킵니다.


BMP280.zip





[BMP280]

----------------------

- VCC : +3.3V

- GND : GND

- SCL : A5

- SDA : A4

- CSB : +3.3V

- SDO : GND


[0.96" I2C IIC Series 128X64 OLED]

----------------------

- SCL : A5

- SDA : A4

- VCC : +3.3V

- GND : GND


#include "U8glib.h"
#include "BMP280.h"
#include "Wire.h"
#define P0 1021.97  //1013.25 
BMP280 bmp;

// OLED Type
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);

char sT[20];
char sP[9];
char sA[9];
char sA_MIN[9];
char sA_MAX[9];
double A_MIN = 0;
double A_MAX = 0;

void draw(double T, double P, double A) {
  u8g.setFont(u8g_font_unifont);

  dtostrf(T, 4, 2, sT);
  dtostrf(P, 4, 2, sP);
  dtostrf(A, 4, 2, sA);

  u8g.drawStr( 5, 10, "Temp: ");
  u8g.drawStr( 5, 30, "Bar : ");
  u8g.drawStr( 5, 50, "Alt : ");
  u8g.drawStr( 50, 10, sT);
  u8g.drawStr( 50, 30, sP);
  u8g.drawStr( 50, 50, sA);
}

void draw2(double A_MIN, double A_MAX) {
  u8g.setFont(u8g_font_unifont);

  dtostrf(A_MIN, 4, 2, sA_MIN);
  dtostrf(A_MAX, 4, 2, sA_MAX);
  u8g.drawStr( 5, 20, "A Min: ");
  u8g.drawStr( 60, 20, sA_MIN);
  u8g.drawStr( 5, 45, "A Max: ");
  u8g.drawStr( 60, 45, sA_MAX);
}

void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println("BMP init failed!");
    while (1);
  }
  else Serial.println("BMP init success!");

  bmp.setOversampling(4);

  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_unifont);
}

void loop(void) {
  double T, P;
  char result = bmp.startMeasurment();

  if (result != 0) {
    delay(result);
    result = bmp.getTemperatureAndPressure(T, P);

    if (result != 0) {
      double A = bmp.altitude(P, P0);

      if ( A > A_MAX) {
        A_MAX = A;
      }

      if ( A < A_MIN || A_MIN == 0) {
        A_MIN = A;
      }

      //      Serial.print("T = \t"); Serial.print(T, 2); Serial.print(" degC\t");
      //      Serial.print("P = \t"); Serial.print(P, 2); Serial.print(" mBar\t");
      //      Serial.print("A = \t"); Serial.print(A, 2); Serial.println(" m");

      u8g.firstPage();
      do {
        draw(T, P, A);
      } while ( u8g.nextPage() );
      u8g.firstPage();
      delay(1000);

      do {
        draw2(A_MIN, A_MAX);
      } while ( u8g.nextPage() );
      u8g.firstPage();
      delay(1000);
      
    }
    else {
      Serial.println("Error.");
    }
  }
  else {
    Serial.println("Error.");
  }

  delay(100);

}





값이 잘 바뀌고 있습니다.




FIN

이제 뭘하지?

And

Software | Arduino IDE 에서 library 추가하기

|

1. 시작하기

새로운 sensor 나 module 을 구매하여 구동시키려면,

제조 vendor 에서 제공한 library 가 필요합니다. (밑도 끝도 없이 혼자 파볼 수는 없는 일!)


- https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use/installing-a-library


그래서, module 이 구해지면 자동으로 library 추가가 필요합니다.



2. ZIP 으로 추가하기

메뉴에서 Sketch > Include Library > Add .ZIP Library...

이렇게 하면 편하게 library 를 추가할 수 있습니다.



위에서처럼 추가하면, 아래처럼 추가한 library 가 보입니다.




다만, 정식 제품이 아닌,

clone 제품 등을 사용하거나, 비슷한 제품을 사용하게 되면, 이 library 소스를 조금 수정해야 하는 일이 발생합니다.

(완전히 같을 수는 없겠죵)



3. 직접 추가하기

메뉴로 추가하면 편하지만, 한가지 단점이 있습니다.

바로 위에서 이야기한, clone 제품일 경우 library 수정이 필요한 경우가 있습니다.


이럴때는 다음과 같은 순서로 작업을 합니다.


A) Library ZIP 파일을 다운로드

B) 개인이 관리하는 장소 (예: Windows OS 의 "내문서" 하위에 "Arduino" 폴더) 를 작성

C) 다운로드 받은 파일을, 새로 만든 폴더에 압축을 품

D) 압축 풀때 사용하는 folder 명을 수정

예) Adafruit_BMP280_Library_master --> Adafruit_BMP280


E) 수정한 파일 열어서 수정 후, 저장


위의 방식으로 하면, "File > Examples" 에서 등록된 것을 찾을 수 있습니다.





FIN

모두 Arduino 가지고 enjoy your life 하세요~!



And

Hardware | Arduino 비접촉 온도센서 GY-906 MLX90614

|

1. 시작하기

오늘은 비접촉 온도센서인 MLX90614 를 가지고 놀아봅니다.


미키마우스같이 생겼네요.


뒷부분에 여러 보조 부품이 같이 실장되어 있어, Arduino 연결 시, 따로 콤포넌트를 추가하지 않아도 됩니다.





2. Library 추가하기

구동하기 위해서는 관련 library 를 추가해야 합니다.


- https://learn.adafruit.com/using-melexis-mlx90614-non-contact-sensors/wiring-and-test




3. 레이아웃

핀 연결은 다음과 같습니다.


- VIN : +3.3V

- GND : GND

- SCL : A5

- SDA : A4






4. 소스

Library 를 설치했으면, File > Example > Adafruit MXL90614 Library > mlxtest 를 가지고 이용할 수 있습니다.



/*************************************************** 
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1748
  ----> https://www.adafruit.com/products/1749

  These sensors use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include 
#include 

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}


5. 결과

성공입니다.



다만, 다른 component 와 비교하여 단순히 온도만 내 주는건 좀 아쉽습니다.

특히 BMP280은 온도 외에, 기압, 고도도 나타내 주거든요.



6. 확장

아래 사이트를 보니, OLED 를 이용해서 표시해주는 코드를 발견했습니다.

이제 좀 있어 보이네요.


- http://www.arduinoprojects.net/lcd-projects/mlx90614-and-oled-display-example.php#codesyntax_1


바로 따라해 봅니다.



#include 
#include 
#include 
#include 
#include 
#include 
 
#define OLED_RESET 4
 
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
//if (SSD1306_LCDHEIGHT != 32)
//error("Height incorrect, please fix Adafruit_SSD1306.h!");
//endif
 
void setup()   
{                
  Serial.begin(57600);
  Serial.println("Adafruit MLX90614 test");  
  mlx.begin();  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
}
 
 
void loop() 
{
    // Clear the buffer.
  display.clearDisplay();
 
  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Ambient: ");
  display.print(mlx.readAmbientTempC()); 
  display.print(" c");
  display.setCursor(0,10);
  display.print("Object: ");
  display.print(mlx.readObjectTempC()); 
  display.print(" c");
  display.display();
  delay(2000);
  
}

잘 나오네요.

부품 2개를 연결하여 작동시킨 처음 케이스 입니다.



온도 센서 근처에 손가락을 가져가면 온도변화를 화면에 표시해 줍니다.




FIN

이제 뭘하지?

And

Hardware | Arduino Ambient Light TEMT6000 Sensor

|

1. 시작하기

저번에 ambient light sensor 인 TEMT6000 센서가 잘 동작하는지, 어떻게 구동시키는지 확인해 보고 싶었습니다.




2. 소스

소스는 아래 사이트를 참고하였습니다.


http://cactus.io/hookups/sensors/light/temt6000/hookup-arduino-to-freetronics-temt6000-light-sensor-module


그냥 따라해 봤습니다.

int sensorValue;

void setup()
{
  Serial.begin(9600);  // sets the serial port to 9600
}

void loop()
{
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println(sensorValue, DEC);  // prints the value read
  delay(100);                        // wait 100ms for next reading
}



3. 연결하기

fritzing 을 이용하여 레이아웃도 만들어 봤습니다.


- Signal : A0

- GND : GND

- VCC : 5V


실제 연결 사진입니다.




4. 결과

소스를 arduino 에 업로드 하고 확인해 봅니다.

특별히 결과치를 보여주는 창이나 output 소자가 없으므로, Arduino Sketch 툴에서 확인합니다.


- Tools > Plotter

  -- 메뉴


  -- 결과



- Tools > Serial Monitor

  -- 메뉴


  -- 결과




FIN

잘 동작하네요.

이제 뭘 하지..?


And

Hardware | Arduino 로 buzzer 소리내기

|

1. 시작하기

Aliexpress에서 buzzer 를 구입했는데, 스피커 뚜껑이 깨지고 내용이 분해된 채로 배달이 됩니다. (아놔...)


잔해들은 본체, 금속 판, 짧은 철사 하나...

이걸 어떻게 조립해야 할까요?



2. 고치기

싸게 샀지만, 또 주문하고 기다리기 싫어서 어떻게든 고쳐서 써 보려고 합니다.

다만, 금속판을 위치시킬 때, 위아래의 정보와 철사의 사용처를 알아야 제대로 고칠 것 같습니다.


일단 갈라진 뚜껑을 순간접착제로 붙입니다.


Google 에서 image 검색을 해 보지만, 모두 겉모습만 나오고,

스피커 뚜껑의 작은 구멍으로 보이는 금속판의 위아래를 가늠할 수 없었습니다.


그러다, "buzzer structure" 키워드로 검색한 결과, 겨우 하나의 그림을 찾아냅니다.


금속판에 덧댄 부분은 위쪽이었습니다!!!


자, 그러면 저 철사는 무얼까요?

일단 구조적으로 부착될 부분이 없어서, 제조과정에서 잘못 들어간 것이라고 유추하고 제외토록 합니다.


스피커는 자석으로 되어 있으니, 금속판을 올려놓고 테스트 해보면 알 것 같습니다.



3. 테스트

Signal, GND, +V 로 구성되어 있으니, 연결을 잘 하고

그에 맞는 코드를 찾아봅니다.


연주를 시킬 것이면 이왕이면 재미있는 것이 좋겠죠?


슈퍼마리오를 연주해주는 코드가 있네요!

http://www.princetronics.com/supermariothemesong/


소스는 +/- 만 Piezo Buzzer 를 기준으로 작성되어 있지만,

이번에 고친 Passive Buzzer는 Signal 을 통해서 컨트롤 되므로, 아래와 같이 변경합니다.

- +V : +5V

- -V : GND

- Signal : D3

아래는 소스 입니다.

/*
  Arduino Mario Bros Tunes
  With Piezo Buzzer and PWM

  Connect the positive side of the Buzzer to pin 3,
  then the negative side to a 1k ohm resistor. Connect
  the other side of the 1 k ohm resistor to
  ground(GND) pin on the Arduino.

  by: Dipto Pratyaksa
  last updated: 31/3/13
*/

/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

#define melodyPin 3
//Mario main theme melody
int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7,
  0, NOTE_C7, NOTE_E7, 0,
  NOTE_G7, 0, 0,  0,
  NOTE_G6, 0, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0,

  NOTE_C7, 0, 0, NOTE_G6,
  0, 0, NOTE_E6, 0,
  0, NOTE_A6, 0, NOTE_B6,
  0, NOTE_AS6, NOTE_A6, 0,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0, NOTE_DS4, NOTE_CS4, NOTE_D4,
  NOTE_CS4, NOTE_DS4,
  NOTE_DS4, NOTE_GS3,
  NOTE_G3, NOTE_CS4,
  NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
  NOTE_GS4, NOTE_DS4, NOTE_B3,
  NOTE_AS3, NOTE_A3, NOTE_GS3,
  0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  6, 18, 18, 18,
  6, 6,
  6, 6,
  6, 6,
  18, 18, 18, 18, 18, 18,
  10, 10, 10,
  10, 10, 10,
  3, 3, 3
};

void setup(void)
{
  pinMode(3, OUTPUT);//buzzer
  pinMode(13, OUTPUT);//led indicator when singing a note

}
void loop()
{
  //sing the tunes
  sing(1);
  sing(1);
  sing(2);
}
int song = 0;

void sing(int s) {
  // iterate over the notes of the melody:
  song = s;
  if (song == 2) {
    Serial.println(" 'Underworld Theme'");
    int size = sizeof(underworld_melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / underworld_tempo[thisNote];

      buzz(melodyPin, underworld_melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }

  } else {

    Serial.println(" 'Mario Theme'");
    int size = sizeof(melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / tempo[thisNote];

      buzz(melodyPin, melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }
  }
}

void buzz(int targetPin, long frequency, long length) {
  digitalWrite(13, HIGH);
  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
  }
  digitalWrite(13, LOW);

}



4. 결과

성공입니다!

뚜껑도 순간접착제로 붙이고 최종 테스트까지 마쳤습니다.


소스에서 음악에 따라 LED도 점등해 주네요.


FIN

And
prev | 1 | ··· | 6 | 7 | 8 | 9 | 10 | next