2015/03/15

Weekend Project – Arduino Temperature Meter

Found an interesting temperature probe on the auction site and I decided to acquire two pieces to test them out. With the LCD module, it seems making a temperature meter is not that hard at all.

In this tutorial, I will show you how to make a temperature meter that allows you to measure temperature with a probe and display current, highest, and lowest temperatures on LCD module.

After I made this, I left it on the desk almost a week and it’s still working! 
I guess it’s time to share how I did this.
See photo below:



Material Needed: 
  • Arudino Mini Pro * 1
  • LCD Module 4 x 20 (J204A) * 1
  • Temperature Probe (DS18B20) * 1 
  • Protoboard * 1 
  • 22k resistor * 1
  • Few jumper wires
Wiring:
  1. Arduino-GND to GND 
  2. Arduino-VCC to VCC 
  3. Temperature probe-GND to GND 
  4. Temperature probe-VCC to VCC 
  5. Temperature probe-Data to 2.2K resistor to VCC 
  6. LCD-GND to GND 
  7. LCD-VCC to VCC 
  8. LCD-SDA to Arduino A4/SDA 
  9. LCD-SLC to Arduino A5/SLC 
  10. Protoboard VCC/GND to 5V DC power source 
  11. Slide switch to VCC/GND (For LCD on/Off, but not shown below)
Connection:

LCD Module:

//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//Used for DS18S20 Temperature sensor
#include <OneWire.h>
#include <DallasTemperature.h>

/*Define for DS18S20 data pins
*  This data pins needs to connect 220 Om resister and to 5V to work
*/
#define ONE_WIRE_BUS 4 

//Define for LCD display pins, SLC 3, SDA 2
#define SCL_CLOCK_PIN 3
#define SDA_DATA_PIN 2

//Initialize OneWire library for temperature sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27,20,4);  

float HighestTemp = 0.0;
float CurrentTemp = 0.0;
float LowestTemp = 0.0;

void setup()
{
  // start temperature sensor
  sensors.begin();
  sensors.requestTemperatures(); //get temperature
  // initialize the LCD
  //You may setup your own clock pin(SCL), data pin(SDA) 2013-12-14
  //Wire.beginOnPins(SCL_CLOCK_PIN, SDA_DATA_PIN);
  lcd.init();
  
  lcd.backlight();
  
  //Set lowest, highest temperatues 
  CurrentTemp  = sensors.getTempCByIndex(0);
  HighestTemp = CurrentTemp;
  LowestTemp = CurrentTemp;
  
  lcd.setCursor(0,0);  
  lcd.print(F("=Temperature Meter="));

  lcd.setCursor(0,1);
  lcd.print(F("Highest: "));
  LCDshowNum(8,1,HighestTemp);    
     
  lcd.setCursor(0,2);
  lcd.print(F("Current: "));
  LCDshowNum(8,2,CurrentTemp);  
    
  lcd.setCursor(0,3);
  lcd.print(F("Lowest: "));
  LCDshowNum(8,3,LowestTemp);     
}


void loop()
{ 
  sensors.requestTemperatures(); //get temperature

  //Get Current
  CurrentTemp = sensors.getTempCByIndex(0);
  LCDshowNum(8,2,CurrentTemp);   
  
  //Check if Hightest
  if(CurrentTemp > HighestTemp){
     HighestTemp = CurrentTemp;
     LCDshowNum(8,1,HighestTemp);     
  }

  //Chekc if Lowest
  if(CurrentTemp < LowestTemp){
    LowestTemp = CurrentTemp;
    LCDshowNum(8,3,LowestTemp);
  }

  delay(1);
}

/*
* LCDshowNum
* LCD display location: x, y
* Float n: temperature to display
*/
void LCDshowNum(int x, int y, float n){
  lcd.setCursor(x,y);
  lcd.print(n);
}
In the video, I had three bottles filled with hot water from drinking fountain, room temperature tap water, and ice cube water. I told my son to place the probe into each bottle and we observed the changing in temperatures.   It was a lot of fun to see the temperature goes high and low!



My son asked me “Is there a way to see temperature drop to 0 or minus”? We quickly found the answer from Internet. The answer is so simple, just put salt on top of ice cubes without water. With in a minute, the temperature dropped to -11 Celsius degrees (12 degrees in Fahrenheit). Actually, the lowest temperature we got was Celsius -14.31 (6.242 degrees in Fahrenheit), but not recorded in the video. See video below.



I hope you enjoy this tutorial and have fun with your kids!

Stonez

自製 Arduino 溫度測量機

在這個教學中,我會教你們怎麼做一個可以讓你在LCD模型上測量出目前的溫度,最高的溫度和最低的溫度的「溫度測量機」。在我完成它之後,我把它放在桌子上大約一個星期後,它還在運作呢!☺ 我覺得是時候該跟大家分享我是怎麼製作它了。

 看看我的溫度測量機:



需要材料: 

  • Arudino Mini Pro * 1 
  • LCD 模組 4 x 20 (J204A) * 1 
  • 溫度探棒 (DS18B20) * 1 
  • 洞洞板 * 1 
  • 22k 電阻 * 1 
  • 幾根跳線
 線路連接方法:
  1. Arduino-GND to GND 
  2. Arduino-VCC to VCC 
  3. Temperature probe-GND to GND 
  4. Temperature probe-VCC to VCC 
  5. Temperature probe-Data to 2.2K resistor to VCC 
  6. LCD-GND to GND 
  7. LCD-VCC to VCC 
  8. LCD-SDA to Arduino A4/SDA 
  9. LCD-SLC to Arduino A5/SLC 
  10. Protoboard VCC/GND to 5V DC power source 
  11. Slide switch to VCC/GND (For LCD on/Off, but not shown below)
電路圖如下:




底下的影片中,一共有三個瓶子,分別裝著熱水,冰水和常溫的水。 我請我的兒子把溫度探棒分別置入到每一個瓶子裡,再觀查各別溫度的變化。


我兒子問我:「有沒有可能讓溫度降到零度或更低?」我們很快的從網路上找到了答案。其實很簡單,只要在冰塊上撒鹽。過了大約一分鐘,溫度就降到了-11度 C(我們最低該溫度降到到-14.31度 C)!看著溫度快速的上升又急快的下降真有趣!請看底下的影片:

 

 找個時間做這個Arduino 專案,再和小朋友一起同樂吧!

 Stonez

2015/03/01

Arduino - DFPlayer Mini MP3 Module


Arduino - Test DFPlayer Mini MP3 Module



I found DFPlayer mini MP3 module on China auction site Taobao when I was looking for a MP3 player module for an Arduino projects.  This module is quite small and it only require few pins connections to Arduino and a speaker to work.  Looks really nice for my little project.

Actually, the module is quite capable and complicated, if you were interested, please visit this page.

This tutorial here is just to show you how to connect DFPlayer module with Arduino and speaker and the Arduino sketch provided here just to play few sample sounds I collected from Internet.

First, I recycled a 2W, 4Omh small speaker from this little music box.


Material Needed:
  1. DFPlayer Mini module 
  2. Speaker - DFPlayer module support to to 3W
  3. SD card - 2GB ~ 32GB formatted with FAT or FAT32
  4. MP3 / WAV - audio files
  5. Arduino mini Pro
  6. Few jump wires
As you can see the illustration below I made in Power Point, hardware connection is quite simple
(Forget about the cross lines...these lines are NOT supposed to be crossed.. :)
* Note: You have to separate DFPlayer Mini Module power from Arduino power or you will hear very loud noises (It took me two days to figure out this!)

***********
UPDATE:  Someone left a message in this blog below, please try it out!

Hello everybody! There is another solution for getting rid of noise. Just put down DC voltage to 4.0 - 4.3 Volts. Arduino is still able to operate and DFplayer recommends to use 4.2V, my experiments prove this.

***********

Here is a photo of my Arduino with DFPlayer Mini connection:



*Important note for audio files. Careful read notes below will save you a lot of precious time!
  • DFPlayer Mini read both MP3 and WAV files.
  • All audio files must be placed under /mp3 folder.
  • Audio file must be named 0001.mp3, 0002.mp3.....0255.mp3 (4 letters not 2 or 3 letters)
  • Audio file names can have any characters after 4 digits, such as 0001_Bruno_Mars_Count_On Me.mp3 
  • Tested few under 1 second WAV files and they did not work
  • If one of the audio file is removed from SD cared, DFPlayer still can find it and play it! Weird! In the end, I formatted the SD card to make DFPlayer to play the music I specified.
  • Delay(seconds); You have to specify number of seconds delay for the audio file to play completely or the next audio file might be started before current audio is over!
  • mp3_play (74); means play audio file 0074.mp3
The code below is from the vendor's website and it worked without much modification.

Programming Code here:


/*
 * Copyright: DFRobot
 * name:  DFPlayer_Mini_Mp3 sample code
 * Author:  lisper 
 * Date:  2014-05-30
 * Description: sample code for DFPlayer Mini, this code is test on Uno
 *   note: mp3 file must put into mp3 folder in your tf card
 */

#include <softwareserial.h>
#include <dfplayer_mini_mp3.h>

void setup () {
 Serial.begin (9600);
 mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module 
 mp3_set_volume (10);
}

void loop () {        

 mp3_play (1); //play 0001.mp3
 delay (10000); //10 sec, time delay to allow 0001.mp3 to finish playing

 mp3_play (2);
 delay (5000);

 mp3_play (5);
 delay (5000);

 mp3_play (20); //play 0020.mp3
 delay (9000);

 mp3_play (81);
 delay (6000);

 mp3_play (74); //play 0074 mp3
 delay (6000);

}
Here is the video:
Done.

Arduino - 測試 DFPlayer Mini MP3 播放模組

最近在大陸拍賣網上找到一個 Arduino MP3 播放模組(DFPlayer Mini),它支援最大32GB SD卡,又可以由 Arduino 下個  Play 的指令就能由SD 卡上播放 MP3 & WAV檔案。加上體積很小一片又只要連接幾支腳位到 Arduino 就能運作了,二話不說就淘了兩片來試試它的功能。

DFPlayer Mini 它的功能真的很多, 有興趣的朋友可以到這裡閱讀 DFPlayer Mini 的介紹!

這個測試主要是測試 DFPlayer Mini MP3 播放模組的功能,所以只需要下列的東西即可:

  1. Arduino mini Pro
  2. DFPlayer Mini 模組 
  3. Speaker - 最高支援到 3W
  4. SD card - 2GB ~ 32GB 以 FAT or FAT32 格式化
  5. 洞洞板 / 跳線
  6. MP3 / WAV 格式的音效 or 音樂檔案

手上剛好有一個壞掉的音樂播放器,我把喇叭拆下來看了一下,剛好是 2W的,可以拿來用。


下方是我自己在 Power Point 上畫的線路示意圖:
(Forget about the cross lines...these lines are NOT suppose to be crossed.. :)
* 注意: 不要直接把 Arduino 的 5V 給 DFPlayer Mini 使用,一定要分別供給 DFPlayer Mini 電源,不然喇叭會發出很大的雜音,我花了兩天才發現這個問題。

以下照片是我實際連接的樣子:

* 以下是使用 DFPlayer Mini Module 的注意事項,請仔細閱讀,可以幫你節省很多時間!

  • DFPlayer Mini 可以讀取 MP3 & WAV 檔案格式,但試過檔案長度1秒以下無法播放。
  • 所有音樂檔案一定要放在 /mp3 資料夾裡
  • 音樂檔案名稱一定要使用 4 個字,如 0001.mp3, 0002.mp3.....0255.mp3 
  • 音樂檔案超過4個字後則無限制,像是 0001_Bruno_Mars_Count_On Me.mp3 是沒問題的。
  • 如果你從 SD 卡上刪掉某個檔案,DFPlayer Mini 還是有辦法把它播出來,好怪!後來我從新格式化 SD 卡才成功播放我要的音樂檔案。
  • Delay(sec); 這個指是是告訴 Arduino 你要播放音樂的長度,如果你給的秒數不足,而下個指令又是要播另一首,則 Arduino 就會把目前播放中斷,而繼續播下一首。
  • mp3_play (74); 這個指令是播放 0074.mp3 這個音樂檔。

Arduino 程式碼請參考上面。

請看下方實際運作影片:
完成。