'Sensor'에 해당되는 글 16건

  1. 2017.03.31 Hardware | Sharp GP2Y1010AU0F dust sensor
  2. 2017.03.06 Hardware | Arduino BMP280 고도/온도/기압 센서
  3. 2017.03.05 Hardware | Arduino 비접촉 온도센서 GY-906 MLX90614
  4. 2017.03.05 Hardware | Arduino Ambient Light TEMT6000 Sensor
  5. 2017.03.05 Hardware | Arduino 로 buzzer 소리내기
  6. 2017.02.27 Hardware | Arduino 구입기

Hardware | Sharp GP2Y1010AU0F dust sensor

|

1. 시작하기

원래 Arduino 를 시작하게 된 동기는, 깨끗한 공기속에서 생활하고 싶었습니다.


그렇기 위해서는 병원 침상 위에 설치되어 있는 O2 발생기 같은 것도 필요하겠지만,

일단 상태를 아는 것이 우선입니다.


그래서 sensor 류를 알아보기 시작한거죠.


이번에는 Sharp Optical Dust Sensor 인 GP2Y1010AU0F 에 대해서 알아보겠습니다.


이번에도 AliExpress 에서 도움을 주셨습니다.

Sharp 사의 부품인데, 알리에서 활발히 판매되고 있습니다.






2. specification

PDF 파일입니다.


gp2y1010au_e.pdf


우선 두번째 그림을 참조하여 리드의 번호를 확인합니다.



실제 회로 구성시 필요한 capacitor 와 resister 정보 및 연결도 입니다.





3. Arduino 와 연결


Sharp / Arduino

- 1 (V-LED) / 3.3V (150 Ohm in between)

- 2 (LED-GND) / GND

- 3 (LED) / D12

- 4 (S-GND) / GND

- 5 (Vo) / A6

- 6 (Vcc) / 3.3V (Direct)







4. Sketch

참고 사이트 : http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/

/*
 Standalone Sketch to use with a Arduino Fio and a
 Sharp Optical Dust Sensor GP2Y1010AU0F
 
 Blog: http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
 Code: https://github.com/Trefex/arduino-airquality/
 
 For Pin connections, please check the Blog or the github project page
 Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
 Changelog:
   2012-Dec-01:  Cleaned up code
 
 This work is licensed under the
 Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
 or send a letter to Creative Commons, 444 Castro Street, Suite 900,
 Mountain View, California, 94041, USA.
*/
 
int measurePin = 6;
int ledPower = 12;
 
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
 
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
 
void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}
 
void loop(){
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  voMeasured = analogRead(measurePin); // read the dust value
 
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
 
  // 0 - 3.3V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (3.3 / 1024);
 
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
  dustDensity = 0.17 * calcVoltage - 0.1;
 
  Serial.print("Raw Signal Value (0-1023): ");
  Serial.print(voMeasured);
 
  Serial.print(" - Voltage: ");
  Serial.print(calcVoltage);
 
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity);
 
  delay(1000);
}

그래프로 그려보면, Signal Value 가 너무 높아서 Dust Density 가 잘 보이지 않습니다.


그래서 다른 값들은 comment out 하고, "dustDensity = 0.17 * calcVoltage - 0.1" 부분을,

1000배인 "dustDensity = (0.17 * calcVoltage - 0.1) * 1000" 로 바꾸면 볼만 해 집니다.



5. 결과

중간에 그래프가 높이 올라간 것은 먼지털이게를 옆에서 털있기 때문이예요.




FIN

이제 뭘하지?

'Hardware' 카테고리의 다른 글

Hardware | Transistor Tester  (0) 2017.05.01
Hardware | BMR-C1 heatsink  (0) 2017.04.26
Hardware | Arduino nano 조립기  (0) 2017.03.31
Hardware | GeForce GTX 560 Ti 수리 실패기  (0) 2017.03.16
Hardware | BME280 sensor  (0) 2017.03.09
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

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

Hardware | Arduino 구입기

|

1. 시작하기


집에 해수 어항이 있는지라, 물이 증발하면 물을 채워줘야 하고, 니모 밥도 정기적으로 줘야 하고,

이끼가 끼면 유리벽도 청소해야 하고, 박테리아 창궐하면 약도 넣어 줘야 하고...

이런것들을 자동화 할 수 없을까?


내 몸은 소중하니까, 집의 산소 농도를 측정하고,

전기분해를 통하여 자동으로 산소를 공급하는 것을 자동화 할 수는 없을까?


지구는 소중하니까, 태양광이나 소형 풀역 발전소를 만들고 싶은데,

효율 좋게 sun tracking system도 만들고 싶고, 원격 제어도 하고싶은데 어떻게 해야 할까?


그렇습니다, 개나소나 이야기 하는 IoT 에 동참하고 싶었습니다.



Raspberry Pi 는 model 1 B 부터 model 3 B+ 까지 모두 써 봤지만, 이런 자잘한 자동화에 쓰기엔 조금 아까웠습니다.


그럼 뭘로? Arduino 가 적절해 보입니다.


2. 구입

Arduino 정품은 허걱! 25 USD 정도 합니다.


요즘 Aliexpress 에 맛들인 지라, 검색해 봅니다.

올레~ 호환 제품이 약 3 USD !!! 유레카 입니다. (거기에다 케이블 포함 !)



케이블 있는것과 없는것을 하나씩 삽니다.

나는 마구마구 만들꺼고 많이 활용할 꺼니까요. 미니멈 2개로 시작입니다. (3 + 2.30 USD)



테스트를 하려면 우선 빵판이 있어야겠네요.

Arduino nano 호환기를 사용할 것이기 때문에 작고 슬림한 걸로 구입합니다. (1.94 USD)

대학 이후로 처음이야... (감격)




전원모듈이 딸린 팡판도 구입합니다. (슬림 빵판 하나가지고는 프로젝트 진행 못한다는 합리화 스킬 발동) (3.95 USD)



빵판에는 점퍼가 필수! 구입합니다. (2.80 USD)



뭔가 보조줜원 모양이, 우주인들이 우주유영시 등짝에 매고 사용하는 로켓 붙사기처럼 멋져 보입니다. 구입합니다. (1.27 USD)



어항 관리를 위해 프로브 온도계 구입합니다. (1.26 USD)


수위 인식 모듈이 필요해 보입니다. 구입합니다. (0.41 USD)


온도계, 습도계 일체형이 있네요. 최신이네요. 구입합니다. (3.08 USD)


왠지 광원 센서도 있으면 좋을것 같습니다. 구입합니다. (1.50 USD)


상태 확인용 미니 디스플레이를 빠트릴 수 없습니다. 구입합니다. (3.22 USD)


음? 비접촉식 온도센서? 구입합니다. (4.35 USD)


부저도 필요해 보입니다. 싸니까 구입합니다. (0.38 USD)


기압/고도 센서... 나중에 필요할 듯 하여 구입합니다. (1.3 USD)


고도센서가 있으니 GPS도 필요해 보입니다. 구입합니다. (8 USD)


UV 검출센서... 영화에서 본것 같습니다. 구입합니다. (6.21 USD)



3. 도착

이렇게 벌려 놓으니 배부릅니다.


구입/ 도착까지 조사도 많이 하고, Aliexpress 도 샅샅이 뒤지고, 시간도 많이 흘러버려 의지 다운.

막상 받고 보니 만족감에 더이상 진도를 못 뺍니다.


이번에는 여기까지. 도착품들은 일단 장롱행...

아.. 언제 하지?


FIN




And
prev | 1 | 2 | next