DHT11のその後とDHT22

 

以前作った温湿度計の表示がなんだかスゴイことになってしまった。

2個中一個は常時80%以上、もう一個は常時25%以下。

もともとDHT11の精度はそんなに高くないらしいので参考程度に、とは

思っていたが、ちょっとアテにならなさ加減がハンパなくなってきた。

作った当初はまだマシな値だったのだが、2ヶ月ほど使って来た中で

徐々に酷くなってきた。

f:id:woosan900rr:20161015153317j:plain

DHT11というセンサーはもともとこんな物なのか、あるいはたまたま

手に入れた2個がハズレだったのかは分からないが、一番アテになるのが

100均の湿度計というのもなんなので、センサーを変えてみた。

 

買ったのはこれ、DHT22

 

Amazon CAPTCHA

f:id:woosan900rr:20161015153407j:plain

前回使ったDHT11より一回り大きい。

 

で、交換してスケッチを少し修正。

センサーの種類を指定する部分を変更

#define DHTTYPE DHT11 → #define DHTTYPE DHT22

 

あとはおまじない的にセンサーのセットアップ時に1秒の待ちを入れただけ。

 

void setup(){
    pinMode(10, OUTPUT);
    analogWrite(10, bckl);
   lcd.begin(16, 2);               // start the library
  // lcd.setCursor(0,0);             // set the LCD cursor   position
  // lcd.print("Push the buttons");  // print a simple message on the LCD

//   Serial.begin(9600);
//  Serial.println("DHT11 test!");
  dht.begin();
    // Start up the library
  sensors.begin();

delay(1000);
}

 

で、あっさりと動作。

 

f:id:woosan900rr:20161015154403j:plain

数字もなんとなく合ってるっぽい。

後はしばらく動かしてどうなるか。

 

GY-GPS6MV2をArduinoでテスト

 

GPSセンサーもArduinoで動作テスト。

買ったのはこちら。

 

 HiLetgo GY-NEO6MV2 Flight コントローラー NEO-6M APM 2.5 GPSモジュール For Arduino EEPROM

 https://www.amazon.co.jp/gp/product/B01D1D0F5M/ref=oh_aui_detailpage_o04_s00?ie=UTF8&psc=1

 

参考にしたサイトはここ。

Ublox NEO6MV2 (Neo 6M) GPS Module with Arduino

 

このサイトではVccを5vから取って抵抗を入れているけど、試しに

3.3vから取ったら問題なく動いた。

ま、いいか。

これもあっさり動作した。

数字見てる感じだと、部屋の中でも受信できているっぽい。

アンテナはつけないとダメみたい。

f:id:woosan900rr:20160918140132p:plain

これも細かい話は後程。

 


f:id:woosan900rr:20160918140420j:image

 

 

MPU6050 6軸センサーをArduinoでテスト

注文していた6軸センサーが届いたのでArduinoを使って動作テスト。

他にもGPSセンサーが届いたり、RaspberryPI Zeroとか届いたりと

オモチャが増えてきた。

 

今回購入したセンサーはこれ。

MPU-6050 使用 3軸ジャイロスコープ・3軸加速度センサー モジュール

https://www.amazon.co.jp/gp/product/B008BOPN40/ref=oh_aui_detailpage_o04_s00?ie=UTF8&psc=1

 

動作確認のために参考にしたサイトはこちら。

特に縛りなく: 加速度+ジャイロのGY-521(MPU-6050)を使ってみた -1-

 

コードもこちらのサイトの物をそのまま使ったので、今回は割愛。

とりあえず動いたので写真だけ。

細かいところは後日。
f:id:woosan900rr:20160918134349j:image

2.2インチLCDをArduinoで表示してみる

 

ある企みの為に買ったLCDを表示させてみる。細かい事は後で追記するとして、取り敢えず動いたので画像アップ。


f:id:woosan900rr:20160903190924j:image

 

配線はこんな感じ。

f:id:woosan900rr:20160904131750p:plain

 

ライブラリはGitHubからお借りしました。

https://github.com/gmtii/ili9341-arduino

 

購入したLCDはこれ。

HiLetgo 2.2インチ ILI9341 シリアルSPI TFT液晶モジュール 240*320

Amazon CAPTCHA

 

raspberry piで使うつもりなので、Arduinoで表示する必要はないのだけど

動作検証をサクッとやるためにArduinoで動かそうと思ったら意外とハマる。

Arduinoは5vでraspberry piは3.3v。

信号電圧が違うということを理解していないため、最初は直接結線して

画像が何も表示されないとか、実に初歩的なミス。

こういう時の為にレベルコンバーターを買っておくべきか…。

 

 

Arduinoを使って温湿度計&水温計 改造

 

一つ目の温湿度計はLCDが4列あり、もう一列何か表示したくなって

気圧センサーを購入。

買ったのはこれ。

Amazon CAPTCHA

 


f:id:woosan900rr:20160828134850j:image

ちっちゃ。

 

それとむき出しではイマイチなのでケースを製作する。

塗装前なのでカッコ悪い。


f:id:woosan900rr:20160828134935j:image

ケースに入れてエージングしてみると、LCDの熱の影響なのか温度が

高くなっている。

とりあえずスケッチで差分を補正するのと、湿度の数字が低く表示されるのも

係数かけて修正。

スケッチは以下の状態。

 

*******************************

#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

#define DHTPIN 3
#define DHTTYPE DHT11
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

int cnt=0;

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

LiquidCrystal_I2C lcd(0x3F,16,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


DHT dht(DHTPIN, DHTTYPE);

 

 

void setup() {
  //Serial.begin(9600);
  //Serial.println("DHT11 test!");
  dht.begin();
    // Start up the library
  sensors.begin();

    if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
 
  lcd.init();                      // initialize the lcd
   // Print a message to the LCD.
  lcd.backlight();
  lcd.print("SYSTEM START"); 
    delay(3000);
}

void loop() {


  int h = dht.readHumidity();
  int t = dht.readTemperature();
  float wt = sensors.getTempCByIndex(0);

  h=h*1.6; //湿度の補正 1.6倍
  t=t-2; //温度の補正 ケース内のLCDの影響で2度ほど高くなっている
 
    // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  //Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.println("DONE");

 // Serial.print("Temperature for the device 1 (index 0) is: ");
  //Serial.println(sensors.getTempCByIndex(0));

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("ROOM TEMP: ");
  lcd.print(t);
  lcd.print(" *C ");
  //print water temp

  if(wt<25){
    if(cnt==0){
    lcd.setCursor(0,2);
    lcd.print("WATER TEMP:");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print("*C ");
    lcd.setCursor(0,3);
    lcd.print("WARNIG!");
    cnt=1;
    }else{
       cnt=0;
             }
  }else{
      lcd.setCursor(0,2);
      lcd.print("WATER TEMP:");
      lcd.print(sensors.getTempCByIndex(0));
      lcd.print("*C");

      // float atpress;
  sensors_event_t event;
  bmp.getEvent(&event);
 // atpress = bmp.getEvent(&event);

    if (event.pressure){
    /* Display atmospheric pressue in hPa */
   // Serial.print("Pressure:    ");
   // Serial.print(event.pressure);
   // Serial.println(" hPa"); 
      lcd.setCursor(0,3);
      lcd.print("AT PRESS:");
      //lcd.print(atpress);
      lcd.print(event.pressure);
      lcd.print("hPa");
  }else{
      lcd.setCursor(0,3);
      lcd.print("AH Sensor error");
  }
  }


  delay(1000);

 
}

*******************************

で、こんな感じになった。

f:id:woosan900rr:20160828134952j:image

 

それと忘れないうちに配線図をアップしておく。

 f:id:woosan900rr:20160903204817p:plain

Arduinoを使って温湿度計&水温計 二個目

 

もう一つの水槽用に二個目の温湿度計+水温計を作る。

構成は一個目とほぼ同じだが、LCDが違うのでスケッチも若干違っている。

 

買ったのは

SODIAL(R)キーパッド シールド ボード ブルー バックライト Arduinoロボット LCD 1602 1280 2560 UNO US用品

Amazon CAPTCHA

LCDにボタンが6個ついたもの。Arduino Unoにそのまま取り付けられる

シールドと呼ばれる形式。

前回のI2C変換を使って配線を減らしたかったけど、ピンアサインが

良くワカランのでそのまま使うことにした。

 

で、せっかくなのでボタン使って何かしようかと思ったけど、パッと

思いつかないので後回し。

スケッチもキーの読み取りとかいろいろコメントアウト

 


#include <LiquidCrystal.h>
#include <LCDKeypad.h>
#include "DHT.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define DHTPIN 3
#define DHTTYPE DHT11
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);           // select the pins used on the LCD panel

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


DHT dht(DHTPIN, DHTTYPE);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
 
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

#define DELTA 10

int cnt=0;

 
int read_LCD_buttons(){               // read the buttons
    adc_key_in = analogRead(0);       // read the value from the sensor
 
    // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
    // we add approx 50 to those values and check to see if we are close
    // We make this the 1st option for speed reasons since it will be the most likely result
 
    if (adc_key_in > 1000) return btnNONE;
 
    // For V1.1 us this threshold
    if (adc_key_in < 50)   return btnRIGHT; 
    if (adc_key_in < 250)  return btnUP;
    if (adc_key_in < 450)  return btnDOWN;
    if (adc_key_in < 650)  return btnLEFT;
    if (adc_key_in < 850)  return btnSELECT; 
 
   // For V1.0 comment the other threshold and use the one below:
   /*
     if (adc_key_in < 50)   return btnRIGHT; 
     if (adc_key_in < 195)  return btnUP;
     if (adc_key_in < 380)  return btnDOWN;
     if (adc_key_in < 555)  return btnLEFT;
     if (adc_key_in < 790)  return btnSELECT;  
   */
 
    return btnNONE;                // when all others fail, return this.
}
 unsigned char bckl=150;
 
void setup(){
    pinMode(10, OUTPUT);
    analogWrite(10, bckl);
   lcd.begin(16, 2);               // start the library
  // lcd.setCursor(0,0);             // set the LCD cursor   position
  // lcd.print("Push the buttons");  // print a simple message on the LCD

//   Serial.begin(9600);
//  Serial.println("DHT11 test!");
  dht.begin();
    // Start up the library
  sensors.begin();
}

 

void loop(){
    //adjust the backlight


 // delay(3000);

  int h = dht.readHumidity();
  int t = dht.readTemperature();
  float wt = sensors.getTempCByIndex(0);

  /*
    // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for the device 1 (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0));

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  */
 
/*
if(wt<30){
  lcd.blink();
  }else{
    lcd.noBlink();
  }
*/
 sensors.requestTemperatures(); // Send the command to get temperatures
 
  //lcd.print("ROOM TEMP:");
  lcd.clear();
  lcd.print("Hu:");
  lcd.print(h);
  lcd.print("%");
  lcd.setCursor(8,0);
  lcd.print("T:");
  lcd.print(t);
  lcd.print("*C ");
 
  //print water temp
  lcd.setCursor(0,1);
  if(wt<25){
    if(cnt==0){
    lcd.print("WARNIG!");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print(" *C ");
    cnt=1;
    }else{
       cnt=0;
             }
  }else{
      lcd.print("WATER: ");
      lcd.print(sensors.getTempCByIndex(0));
      lcd.print("*C ");
  }
  delay(500);
       
}

 

とりあえず動いた。

f:id:woosan900rr:20160820235054j:plain

 

こちらも忘れないうちに配線図を追加。

f:id:woosan900rr:20160904003927p:plain

 

 

Arduinoを使って温湿度計&水温計

電子工作の備忘録として。

 材料が揃ったので温湿度計+水温計を作る。

 買ったのは

 

EasyWordMall DHT11温湿度センサーモジュール

https://www.amazon.co.jp/gp/product/B010PZZPLS/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1

 

NUOLUX DS18B20 防水温度センサー 温度センサプローブ

https://www.amazon.co.jp/gp/product/B01C3YGZOA/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1

 

EasyWordMall 1602 LCD ブラック IIC/I2C/TWI/SPI シリアル インタフェース ボード モジュール

https://www.amazon.co.jp/gp/product/B010Q000V2/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

 

SODIAL(R)2004 20x4文字のLCDディスプレイモジュールブルーブラックライト

https://www.amazon.co.jp/gp/product/B00KBPQ8NW/ref=oh_aui_detailpage_o07_s00?ie=UTF8&psc=1

 

HiLetgo Mini USB Nano V3.0 ATmega328P CH340G 5V 16M マイクロコントローラーボード

https://www.amazon.co.jp/gp/product/B01CZQANN0/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

 

目的は家の90cm水槽に使っている水温計が壊れて久しいので

Arduinoの勉強兼ねて製作。

 

スケッチのメモは以下。

いろんなところから借りてきたものなので、細かいところは不明。

 

*******************************************************************************************

#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define DHTPIN 3
#define DHTTYPE DHT11
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

int cnt=0;

LiquidCrystal_I2C lcd(0x3F,16,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


DHT dht(DHTPIN, DHTTYPE);

void setup() {
  //Serial.begin(9600);
  //Serial.println("DHT11 test!");
  dht.begin();
    // Start up the library
  sensors.begin();
 
  lcd.init();                      // initialize the lcd
   // Print a message to the LCD.
  lcd.backlight();
  lcd.print("SYSTEM START"); 
}

void loop() {
  //delay(3000);

  int h = dht.readHumidity();
  int t = dht.readTemperature();
  float wt = sensors.getTempCByIndex(0);

    // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  //Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.println("DONE");

 // Serial.print("Temperature for the device 1 (index 0) is: ");
  //Serial.println(sensors.getTempCByIndex(0));
/*
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
*/
/*
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
*/
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("ROOM TEMP: ");
  lcd.print(t);
  lcd.print(" *C ");
  //print water temp

  if(wt<25){
    if(cnt==0){
    lcd.setCursor(0,2);
    lcd.print("WATER TEMP:");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print("*C ");
    lcd.setCursor(0,3);
    lcd.print("WARNIG!");
    cnt=1;
    }else{
       cnt=0;
             }
  }else{
      lcd.setCursor(0,2);
      lcd.print("WATER TEMP:");
      lcd.print(sensors.getTempCByIndex(0));
      lcd.print("*C");
  }
  delay(500);

 
}

*******************************************************************************************

 

出来上がりはこんな感じ。

f:id:woosan900rr:20160817154429j:plain