2014/01/28

Arduino 專案 - 以電視遙控器控臥室天花板電燈開關 (3) : Arduino Project - Switch Bedroom Light with TV remote Part 3

上次把電子零件通通焊到板子上了,今天來完成這個專案吧!
首先,要先找到提供電源給Arduino 的方法。看了網路上很多人都說自製變壓器要小心安全的問題,大都建議用現成的變壓器,所以我拿了手上一個手機變壓器來當做電路板的電源。

After I soldered all components on the perfboard, let's complete this project today! First, I need to find a way to provide power to our perfboard. Many people on the internet recommended to use a mobile phone charger instead of making one themselves due to safety concerns. So I got a spare HTC charger for my project as shown below. 


把USB電線剪斷小端(MicroUSB) 到適合的長度,把外皮剝開,裡面會有四條不同顏色的電線如下圖,紅是正極,黑是負極。把正負極焊到電路板上。

Carefully cut the microUSB end and pelled the shielding off the cable. In there, you will be four wires with GREEN, WHITE, RED, BLACK. Solder the RED and BLACK to positive and negative on your perfboard. 
再把正負極焊在電路板上後,記得插電到電路板上先試試功能是否正常。
After soldered the wires, plug charger and test your board to see if it's working.



這是我房間裡的燈,它由開關來開啟,每次開關一次,它會循環:3個燈/關,5個燈/關,2個燈/關,小夜燈/關。

My bedroom light looks like this below. It has a switch located at the entrance of the bedroom. The switch works like this. For every switch on/off, it cycles through 3 lights/off, 5 lights/off, 2 lights/off, night lights/off.


把螺絲鬆開後,即可拿下玻璃片。
Carefully loosen the screen on the bottom and remove the decorative glass away.


把中間螺絲柱轉下來,記得順便把所有的燈泡轉下來,取下固定燈枱的兩個螺絲後,裡面還有兩條110V電線,我們即可拆下燈架。
Remove the center long screw as well as all light bulbs. Then remove two fixing screws on the light base set, but there are two more wires inside we need to take care!


再把下圖110V的電黑/紅電線上的膠布用刀片劃個幾刀即可取下膠布。緊接著,小心的取下框架。
小秘訣:注意看下方的照片裡,我有用一條小的電線把燈框架綁在上方的鐵柱上,這樣作業時才不會需要一直拿著燈架,手真的會很酸喔!
Carefully remove the isolation tape and detach the 110v wires with a utility knife.
Tip: If you look at the photo below, I tight a red wire to the steel beam and the light frame. Therefore, you don't need hold the light frame and try to detach isolation tape at the same time. This save me a lot of effort.



把燈的框架取下後放在地上。找個適當位置放置電路板。
記得,電路板放的位置不能擋到燈泡及螺絲要固定的位置。
Position the perfboard in an idea location without blocking the light bulbs from installing and removing later as well as avoid the screw's holes and wires.


燈座因為空間有限,我用電鑽在燈枱座上鑽個洞,把變壓器放在橙枱座內框裡,電路板則是放在外邊。
Since there is limited space on the light frame, I placed the phone charger inside the light base and the perfboard outside the light base. Drill a hole on the light base to allow the USB charging cable to go through.


找一片絕緣的材質(我是用一片塑膠片把它在電路板底下)再用束線帶把它固定好。
接著,我再用電鑽在燈座灰色的地方鑽個洞,找支螺絲把電路板鎖上固定好。
Place an isolation material between light base and perfboard (I found a piece of plastic from a cookie case) and tight them together with a cable tight.
Drill a hole on the light base and tight the perfboard and light base with a screw as shown below.


接線的方式如下圖,由天花板上的110V 正負極各接到手機的變壓器,它會提供5V電源給電路板。另外110V負極再接到燈座本身,正極接到電路板的繼電器模組 "常開",再由"共用"極接回到燈座上。
Phone charger retrieves power from 110v power line from the celling. Phone charge constantly provide power to the perfboard. See the illustration below for my complete wiring.  

由110V接到手機變壓器上時,記得絕緣要做好,不然可能會短路造成災害可不好⋯⋯
我用的是絕緣膠布,多纔幾圈才安全!畢竟大家只是因為樂趣來 DIY,沒必要賠上身家財產。 
When connect 110v power line to phone charger, please make sure the isolation is done properly. I used the isolation tape and tight them 3~4 times to ensure it's isolated. After all, there is no reason to risk your life or property for the sake of DIY.


如上面說明,我由天花板上的110V 正負極各接到手機的變壓器,它會提供5V電源給電路板如下圖:
As mentioned before, I placed the phone charger inside the light base.


如下圖:110V負極再接到燈座本身,正極接到電路板的繼電器模組 "常開"(左側),再由繼電器模組"共用"(中間)極接回到燈座上。一定要接繼電器模組 "常開",不然你原來的電燈開關就會失效了!

See below: Connect 110v positive to relay "NO or Normally Open" on the left, and COM "Common connection" in the middle should  connect back to 110v negative. 


把從繼電器模組"共用"(中間)極(原來的正極)接回到燈座。
See the wiring below, both positive and negative are now connecting back to the celling 110v wire.

好了,裝上一兩個燈泡試試原來牆上的開關是否和原來一樣能正常的工作。接著,再試試搖控器是否能正常的開關電燈,我很幸運,一切都能正常運作。注意看下方紅色圈起來的地方,它是我上次固意延伸出來的紅外線接收器,我原本把它放在電燈玻璃的裡面,但搖控無法控制,不知是不是距離太遠的關係,只好再把它拉出來外緣,讓搖控更順暢。

Ok, before you tighten the light frame and decorative glass back to the celling, try to put on few light bulbs and test out the remote to see if they are working as expected.  See the red circle below, that's the IR receiver that I used an extended wire from my perfboard to the rim of the light to get better IR reception.


試試用電視搖控器來改變燈的顏色!
I tried use the TV remote to change the LED color on the perfboard.


再變不同的顏色!
Change the color agagin with my TV remote.


各位可以看看實際運作的影片如下:
Please check the fully functional system in video as below.



第一個Arduino實用專案終於完成!!
This is first practical Arduino project that I have done by myself!!

2014/01/19

Arduino 專案 - 以電視遙控器控臥室天花板電燈開關 (2) : Arduino Project - Switch Bedroom Light with TV remote Part 2

上次完成 Arduino 用TV搖控器來開關燈 開發原型後,一直到今天才把它完全的做在一個麵包板上。由於是電子相關的新手,真是花了很多功夫才完成。在過程中,我還把正負極裝反,害我以為 Arduino mini pro 被我燒毀了! 找了好久,還好我有發現這個問題,不然,你也看不到這個例子了!

After I completed Remote control light switch with Arduino and TV remote project last time, I was looking for ways to move all components on to a perfboard and ready for a permanent setup. Due to I am really new to electronics, it took me a lot of time to get the job done. During the process, I accidentally soldered the power source positive to negative and negative to positive. I was panic and, for once, I thought I had burned the Arduino mini pro.  I was happy that I found the problem and solved it after few hours...


對沒學過焊接的新手,把零件焊到電路板上,真的是很不容易!! 看我焊的跟狗啃的沒兩樣。
For a newbie like me whom never learn how to solder, soldering components to the perfboard is really challenging!

我到電子零件店買了這個編號 KT-8 的電路板。
使用長的接腳,拿它來當固定 Arduino mini pro 的工具。
I bought this perfboard coded "KT-8" in an electronic component shop and it only cost NT$10.
With the long connection pins, I utilized them to fix Arduino mini pro in place on the perfboard.

一開始先選定這個角落當作 Arduino mini pro 固定位置,要記得把五個 pin 腳朝外,這樣要上傳程式比較方便。
Pick up the corner of the KT-8 perfboard as the fix position. Don't forget to face the five pins towards outside of the KD-8 for easier connection to the USB uploader later.


我不想一開始就把 Arduino mini pro 的腳位焊死,這樣我可以較彈性的應用,所以也買了底下這樣的接口,所以我可以任意調動我要用的 pin 。我只有把大概用的到的腳位加上接口,其它的就留著作為固定的用途。

I picked up the connection pins as shown below to solder them on the side of Arduino mini pro, so I could have the flexibility to change connection to the pins later in the project.  As you can see, I saved couple of empty spots on the Arduino mini pro, so I could use them to fix it to the perfboard later.


找四個留下的空 pin 腳,焊上排針來支撐 Arduino mini pro。我把排針剪下一支一支的共四支,等一會再把這四個排針焊到麵包板上。

Decided four empty spots and used the connection headers came with Arduino mini pro and soldered them together. Later, these connection headers would become the supporting material on the perfboard for Arduino mini pro. The connection headers are in a row of 20, so I cut down a single header totaling 4 of them and make them into supporting materials.



Photo above:  Long connection pins for fixing Arduino mini pro in place on the perfboard.

我的工作桌...
My soldering table...


固定 Arduino mini pro 後,焊上 LED,電阻,再接上線路,記得先測試一下。
我在這裡測試時,發現它不會動,花了好久時間才發現是正負接反了!
After fixed Arduino mini pro in position, solder RGB LED, resistors, and wires. 
Remember to test the whole setup before move forward. 




Photos of soldering work here:

因為繼電器模組上有一個洞,所以我先用電鑽在電路板挖個洞,再用螺絲把它鎖住。
但固定單邊不夠勞固,所以我又用一條束帶把繼電器模組緊緊的繫在電路板上。
Drilled a hole on the perfboard, and took a screw to fix the relay module on the perfboard. However, fixed on one side is not enough, so I took a cable tight to keep the relay module tightly on the perfboard.


Photos of entire board here:

我刻意把紅外線接收器的線做長一點,想說把它延伸到天花板燈的外緣,這樣遙控訊號才不會被我燈上的裝飾玻璃給擋住。結果測試後發現這根本不需要,因為紅外線接收訊號功能很強,我試著隔著 Macbook Air 的螢幕,居然還可以接收的到!

I intended to make the IR receiver wire extra longer, so I could extend the IR receiver outside the bed room light or it might be obscured by the decorative glasses. After few tests, I found out the IR receiver could even receive the TV remote signal even I intended put it behind my Macbook Air display!

看一下這兩周以來的成果如下,接下來要為它接上電源及安裝到天花板上,才算真正的完成。
After two weeks of hard working, here is the project I had so far. Next time, I will need to find a 5V power source for the perfboard and think how to place it into bed room light.

Video of the working project on perfboard.







2014/01/15

Change font type and size for Arduino IDE

When I started Arduino IDE the first time, I couldn't believe the default font size is so blurry and small. I finally found a way to change the default fonts and make the fonts more clearly.
Let's change the font size and type in this tutorial.

As you can see below, the default fonts is so blurry Arduino IDE:




First, go to the menu "File"-> "Preferences". You may setup the font size you prefer. I prefered size 18. (See red square with 18 in it. That's my prefered font size.) Then at the bottom of the preference box, there is the path to the file preferences.txt  (see image below)


We need use a text editor to change preferences.txt's content to make font clear.


Use a text editor to open the preferences.txt file in the path shown above. After the file is opened, find "editor.antialias=false" and change false to true. If you want to, you may also change the font size directly in the editor. (See read mark below).

** Don't forget to save the file and restart Arduino IDE for these changes to work.




After restart Arduino IDE, you will see the fonts are much clear and bigger than before!



Thank you!
---------------END----------------------

改變 Arduino 編輯器字型讓它更容易編寫程式


一開始使用 Arduino 時,不知道你是不是和我一樣,覺得Arduino  編輯器的內定字型實在是太不清楚了!今天來改變它的內定字型吧!

Arduino 編輯器模糊又不清楚的字如下:


























先到檔案->打開設定 畫面如下, 先設定你要的字型大小(在紅框位置,我設定18)
再看清楚它設定檔 preferences.txt 的位置,這個 preferences.txt  我們稍候需要用編輯器來變更它的內容,以便讓字變的更清楚。









使用文字編輯工具,我用的是 pico,依先上面顯示的位置,開啟 preferences.txt。在其檔案內容中找到 editor.antialias=false這一行,然後把 false 改成 true 再存檔起來。你也可以在這裡直接改變不同字型或是大小,如底下紅框所示。存檔後,要記得關掉 Arduino 編輯器再重新開啟,這些改變才會生效。






















重新開啟 Arduino 編輯器,你看,字型是否清楚多了!


v



2014/01/14

Arduino 專案 - 以電視遙控器控臥室天花板電燈開關 (1) - Arduino Project - Switch Ceiling Light with TV remote Part 1

這一兩個月來,一直在看 Arduino 的相關資料,終於有一個 "勘用" 的東西...
It's been a month a or two that I have been studying Arduino related information.
Finally, I came up with a useful cases for a project that could potentially solve my pain point.

睡覺前,在寒冷的冬天,要從床上起關燈時,總覺得很麻煩...
所以當初看到 Arduino, 第一個想完成的 project 就是,利用電視遙控器來控制天花板上的燈了...上網找了一下資料,沒想到已有很多前輩已經有寫類似的,所以就參考來用了!這是我做初版,coding 太久沒寫了,所以很亂,還好能運作...
It must be happened to you before that in a very cold night watching TV or movie in bed and you were ready for bed. You turned off the TV or DVD player with remote control easily. However, for the bedroom light, you just had to get out of the bed to turn the light off. What a pain point!!

So, my first project is called "Remote control light switch with Arduino and TV remote".  After I searched the internet, there are many examples already out there, such as IR receiver, relay module, RGB LED shift hue and most of them have codes that I could utilize on my project.  It's been a long time since my last coding, so the code is kind of messy, but it worked!


零件清單(全部在台灣拍賣上取得: Components used list (All acquired on auction sites) 
Arduino mini pro * 1 = NT$125

Arduino USB 上傳模組 
(Arduino USB upload module) *1 = NT$140 
5V / 10A 125V 繼電器模組 (Relay module) * 1 = NT$65
IR 接收器 (IR Receiver) * 1 = $4
RGB LED *2 = $6
一些線材 (Some wires) $10
家裡電視 or DVD遙控器 (TV or DVD remote) Free

麵包板 (Breadboard ) * 1
創作過程樂趣 (Effort and enjoyment of this creativity, priceless) * 1 無價! 

模組搖控功能如下:(Remote module Function)

Assign two button on your TV or DVD remote to control:

Button 1: A) LED 小燈亮
橘色 (取代原本小夜燈), B) LED 彩色循環,C) LED Off 
_________ Switch among A) LED bed room night light B) Shift RGB LED colour hues C) LED offButton 2: 切換繼電器開關 (以後把110V燈接上去,就可以開關了)
________ Turn light switch (I have to plug 110V power plug on the relay later)

設定的 Button 要是最不常用的,最好是電視關掉時,按下去的鈕不會有任何反應。像電源鈕就不建議,以免使用時關燈時又把電視打開.... 那就很 Orz..
You can share the TV remote for this project, so there is no need to use a separate remote. Make sure the buttons you are going to use are less frequently used on the remotes. Power buttons on the remote are not recommended, since it's likely that you turn off the light, but the TV or DVD is turned on. I assume that's not something you would like to see.
模組線路圖:(My first drawing of the wiring chart)

原型電路板 +電視遙控器:
Here is prototype + TV remote used for the project

小燈 +LED 彩色循環 +繼電器關關。注意聽,影片中有切換繼電器的聲音。
Bed room night light -> Shift LED colour hue -> LED off
Relay on / off (Listen carefully, you can hear the relay switch in the video)




PS:你可以多設幾支搖控器,以免要用的那支沒在床邊,還是得起床!像我設了兩支臥室常用的。
PS:  You may setup few more remote for the same function. Just in case, the light remote is not with you and then you need to get out of the bed eventually. In  my project, I have setup 2 most frequently used remote in the bed room.

接下來: 我要想想如何才能裝到天花板的電燈裡!
What's next, I need to figure out how to connect this module to the light on the celling.



2014/01/12

Another Arduino Editor - Sublime 2 Text for Mac

P.S: This tutorial was written back in 2014 and here is the English version.

I just started to learn Arduino and found out its IDE is not best one available; the fonts are not clear and quite small, no line numbers(V1.6 has line number now, Ya!!), and no being able to refer to variables during coding and no auto-complete funcationality.

After few search⋯⋯I found Sublime 2 + Stino plugin

If you are using a Mac and you do not like Arduino IDE, then you should give this editor a try:
 Sublime 2 + Stino plugin

Installation:
  1. Download and install  Sublime 2 Text from here http://www.sublimetext.com/2
  2. Download latest Stino plugin:https://github.com/Robot-Will/Stino Just checked, the latest plugin was released in July-2015  
  3. Start  Sublime 2 Text application
  4. Select [Preference] -> [Browse Packages...]
  5. Uncompress "new-stino.zip" and place unzipped file into "packages" folder
  6. Close Sublime 2 Text application
  7. Re-start Sublime 2 Text application
  8. Setup type of your Arduino board by Select [Arduino] -> [Board]: The Arduino board I am using is Arduino Mini Pro, so I just select Arduino Mini Pro
  9. Setting the Serial Port by select [Arduino] -> [Board] -> [Serial Port]:In my case my serial port is located at  /dev/tty.usbserial-FTX1JDSJ
  10. Done.
Now you can try to open Arduino sample Blink for Sublime text to compile. Select [Arduino]-> [Samples]-> [01. Baisc]  -> [Blink()] , then try to  [Compile] / [Upload]. If you couldn't successfully compile or upload, there must be some steps missing or something wrong. Try to repeat the installation process again.


Below screenshot is from Sublime 2 Text Editor and as you can see it looks much better as well as it provide auto-complete and finding the variables you use in your projects.  Now, give it a try!

P.S: After installation, you must select the correct type of Arduino board AND correct Serial Port or the compile will fail!!





















Enjoy it!
=====================================

Arduino 好用編輯器 Sublime 2 Text for Macbook 


最近在學 Arduino 發現它的編輯器實在是字體不清楚,又難用。

所以⋯⋯我找到了 Sublime 2 + Stino plugin  。

若你是使用Mac的人,覺得 Arduino 的編輯器不好看也不好用的的人可以試試
 Sublime 2 + Stino plugin

安裝方法:(上次沒寫安裝方法,連我自己都忘了!)
  1. 下載並安裝 Sublime 2 Text http://www.sublimetext.com/2
  2. 下載 Stino plugin:https://github.com/Robot-Will/Stino 剛剛看的,最新版在2015年7月更新的。
    經常看一下Stino 網址,看它有沒有更新:  https://github.com/Robot-Will/Stino
  3. 開啟 Sublime 2 Text
  4. 選擇 Preference -> Browse Packages...
  5. 把 new-stino.zip 解壓縮後,放到 packages 的資料夾內
  6. 關閉 Sublime 2 Text
  7. 重新開啟 Sublime 2 Text
  8. 設定你的 Arduino 板子, 選擇 Arduino -> Board: 我的板子是 Arduino mini Pro 
  9. 設定 Serial Port, 選擇 Arduino -> Board -> Serial Port:我的是 /dev/tty.usbserial-FTX1JDSJ
  10. 完成
你可以試著從 Arduino-> Samples-> 01. Baisc  -> Blink() 打開, 並試著 Compile / Upload, 若無法成功執行,表示你的設定過程序有問題...再試試上面步驟看看!


Sublime 2 Text 的編輯器長的像底下這樣, 好看多了...
而且它有自動完成,自動找出變數等許多種好用的功能,快試試吧!

P.S: 安裝完後,一定要選對你使用的 Arudino 板子,不然會 compile error!
像我是用 Arduino mini pro Atmeg32 5V 32bit的