(https://en.osdn.jp/projects/ttssh2/releases/) Arduino support something Called Software Serial , which allow You to change any arduino board pin to serial pin. http://arduino.cc/en/Reference/SoftwareSerial To link your bluetooth module with laptop:
- power up HC-05 using Arduino
- for Windows user, go to control panel and "Add Device"
- the default password for HC-05 is "1234"
- after pairing up, you can compile and upload the code to Arduino
- sometimes you may fail to upload the program to Arduino board. Try to disconnect or turn off the bluetooth module while uploading the problem. After that, connect or power up the bluetooth module again.
- Open Tera term software (have to install it first from the link above), go to file > new connection. From the pop-up window, choose "serial" and related serial port.
- Congrats, you have done!
Arduino Code:// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11 >>> Rx
// D10 >>> Tx
// arduino>>bluetooth
// D11 >>> Rx
// D10 >>> Tx
// you will need arduino 1.0.1 or higher to run this sketch
#include <SoftwareSerial.h>// import the serial library
#define temp A0 // I used a potentiometer to replace it
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
int tempValue = 0;
#define temp A0 // I used a potentiometer to replace it
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
int tempValue = 0;
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
pinMode(temp,INPUT);
}
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
pinMode(temp,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
if (BluetoothData=='2'){// if number 2 pressed ....
tempValue = analogRead(temp); // read the value from potentiometer
Genotronex.print("Current temperature:");
Genotronex.print(tempValue);
Genotronex.println("Celcius");
}
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
if (BluetoothData=='2'){// if number 2 pressed ....
tempValue = analogRead(temp); // read the value from potentiometer
Genotronex.print("Current temperature:");
Genotronex.print(tempValue);
Genotronex.println("Celcius");
}
}
delay(100);// prepare for next data ...
}
delay(100);// prepare for next data ...
}
(putty can be used instead of tera term)
No comments:
Post a Comment