Sei sulla pagina 1di 9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

DownloadArduinoANDBluetoothHC05Connecting
easily
Tools
ArduinoANDBluetoothHC05ConnectingeasilyAll
ShowAllItems
HelloEverybody,ThisismyfirstarticalonInstructable.com,I'msohappyforthat,andIwillstartbyHow
toconnectarduinowithbluetooth,IsufferedalotofproblemswhenItrytoconnectitasthewebsiteand
instructablearticaldid,SoidecidedTosharemyexperiencewithYou
ThebluetoothmoduleIwillusetodayisHC05whichissofamiliarandcheap,
MosttutorialonThewebsiteConnectthebluetoothwithdefaultRxandTxonthearduinoBoard,Ifaceda
lotofproblemandbluetoothdidn'tworkwill.
ButarduinosupportsomethingCalledSoftwareSerial,whichallowYoutochangeanyarduinoboardpin
toserialpin
http:/rduino.cc/en/Reference/SoftwareSerial
soAfterreadingthisarticleyouwillbeableto:
1)ConnectarduinoBoardwithPCByBluetooth,tosendandreceivedata.
2)ConnectarduinoBoardwithAnyandroiddevice.
soyoucansendyourinformation,LikeSensorsreading,fromarduinotoPCOrandroiddevice,andyou
canbuildyourHomeautomationsystembybluetooth,andcontrollingyourrobotwirelessly

Step1:Materialandconnection

http://instructables-pdf.abuouday.com/download.php

1/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

ShowAllItems
youneedtodothisexperiment:
1)ArduinoBoard"IusedArduinoUno".
2)BluetoothmoduleHC05.
3)Solderlessjumper.
4)BreadBoard.
5)Battery9V"Optional".
TheconnctionbetweenArduinoandbluetoothisliketheschematicabove

http://instructables-pdf.abuouday.com/download.php

2/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

Step2:ConnectArduinowithPC

http://instructables-pdf.abuouday.com/download.php

3/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

ShowAllItems
WenowwanttosendorreceiveDatabetweenarduinoandcomputer,firstweneedtomake
aCommunicationlinktoDefinitionarduinoBoardtothecomputer.
WewillneedasoftwarecalledTeraTermtoshowthedatareceivedorwhatwewanttosendthroughit.
YoucandownloadTeraTermoranyterminalemulatorsoftware,youcandownloadTeratermfromthis
link:
http://hp.vector.co.jputhors/VA002416/ttermv14.zip
TomakealinkbetweenyourArduinoandbluetooth,dothefollowing:
1)Gotothebluetoothicon,rightclickandselectAddaDevice
2)Searchfornewdevice,OurbluetoothmodulewillappearasHC05,andaddit
3)Thepairingcodewillbe1234.
4)aftermakeapairing,wecannowprogramthearduinoanduploadasketchtosendorreceivedata
fromComputer.

http://instructables-pdf.abuouday.com/download.php

4/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

Step3:ArduinoCode

ShowAllItems
AsImentionedbefore,IwillusesoftwareseriallibrarytomakepinD10&D11AsTx&Rxinsteadof
usingthedefaultRxandtx"D0&D1OnmostarduinoBoard".
thisprogrambelowallowustocontrolLEDconnectedtoD13Toblinkon/off,bypress#1fromPC
KeyboardtheLEDblinkon,andifwepress0LEDblinkoff!
http://instructables-pdf.abuouday.com/download.php

5/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

TosendtheControlcommandsfromComputertoarduino,Gototheteraterm,Runit,and
chooseSerial,andselectthebluetoothSerialfromthelistasShownonthepicture.
Thecodebelow:
//ThisprogramshownhowtocontrolarduinofromPCViaBluetooth
//Connect...
//arduino>>bluetooth
//D11>>>Rx
//D10>>>Tx
//WrittenByMohannadRawashdeh
//forhttp://www.genotronex.com/
//youwillneedarduino1.0.1orhighertorunthissketch
#include<SoftwareSerial.h>//importtheseriallibrary
SoftwareSerialGenotronex(10,11)//RX,TX
intledpin=13//ledonD13willshowblinkon/off
intBluetoothData//thedatagivenfromComputer
voidsetup(){
//putyoursetupcodehere,torunonce:
Genotronex.begin(9600)
Genotronex.println("BluetoothOnpleasepress1or0blinkLED..")
pinMode(ledpin,OUTPUT)
}
voidloop(){
//putyourmaincodehere,torunrepeatedly:
if(Genotronex.available()){
BluetoothData=Genotronex.read()
if(BluetoothData=='1'){//ifnumber1pressed....
digitalWrite(ledpin,1)
Genotronex.println("LEDOnD13ON!")
}
if(BluetoothData=='0'){//ifnumber0pressed....
digitalWrite(ledpin,0)
http://instructables-pdf.abuouday.com/download.php

6/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

Genotronex.println("LEDOnD13Off!")
}
}
delay(100)//preparefornextdata...
}
AfteruploadingThissketchgototeratermandpress0or1andseetheresults
ThisVideoshowtheresultsofthiscode.

Step4:ConnectarduinoToandroidDevice
ShowAllItems
afterwefinishedfromconnectingarduinowithPCBybluetooth,let'smovetohowwecanconnect
arduinoToandroiddevice.
atfirstyouneedaterminalemulatoronyourandrioddevicetosendorreceivedatatoarduino.
YoucandownloadthisappfromGoogleplay.
https://play.google.com/storepps/details?id=arduino.bluetooth.terminal&feature=search_result#?
t=W251bGwsMSwxLDEsImFyZHVpbm8uYmx1ZXRvb3RoLnRlcm1pbmFsIl0.
http://instructables-pdf.abuouday.com/download.php

7/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

afterthat,youcanusethesamearduinoSketchandcontrolLEDBlinkingonorOfffromandroiddevice.
justtypeandtsend#1tomakeLEDBlinkon,or0toblinkoff.
thisvideobelowshowhowtocontrolarduinoI/Ofromandroidtablet.

Step5:ReceivingDatafromarduino
ShowAllItems
ThelastarduinoSketchthatiwrote,usedtosendcommandsfromPCOrandroiddevicetoandroid,
NowinthisprogramiwillusearduinotoCalculatethetimesincethestartoftheprograminsecond,and
senditViabluetoothtoanypairingdevice.
thecodebelow
//ThisprogramshownhowtocontrolarduinofromPCViaBluetooth
//Connect...
//arduino>>bluetooth
//D11>>>Rx
//D10>>>Tx
//WrittenByMohannadRawashdeh
//forhttp://www.genotronex.com/
//youwillneedarduino1.0.1orhighertorunthissketch
#include<SoftwareSerial.h>//importtheseriallibrary
SoftwareSerialGenotronex(10,11)//RX,TX
intledpin=13//ledonD13willshowblinkon/off
longpreviousMillis=0//willstorelasttimeLEDwasupdated
//thefollowvariablesisalongbecausethetime,measuredinmiliseconds,
//willquicklybecomeabiggernumberthancanbestoredinanint.
longinterval=1000//intervalatwhichtoblink(milliseconds)
intledState=LOW//ledStateusedtosettheLED
longCounter=0//counterwillincreaseevery1second
voidsetup(){
http://instructables-pdf.abuouday.com/download.php

8/9

4/17/2016

Download Arduino AND Bluetooth HC-05 Connecting easily

//putyoursetupcodehere,torunonce:
Genotronex.begin(9600)
Genotronex.println("BluetoothOnpleasewait....")
pinMode(ledpin,OUTPUT)
}
voidloop(){
//putyourmaincodehere,torunrepeatedly:
unsignedlongcurrentMillis=millis()
if(currentMillispreviousMillis>interval){
//savethelasttimeyoublinkedtheLED
previousMillis=currentMillis
Counter+=1

Genotronex.println(Counter)

//iftheLEDisoffturnitonandviceversa:
if(ledState==LOW)
ledState=HIGH
else
ledState=LOW
//settheLEDwiththeledStateofthevariable:
digitalWrite(ledpin,ledState)
}
}
attheend,Youcanvisittheorginalarticalinarabiclanguageonmywebsite
http://www.genotronex.com/
Hopemyfirstarticalhereisusefultoyou,thankyouforyourtime,

http://instructables-pdf.abuouday.com/download.php

9/9

Potrebbero piacerti anche