Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The HC-05 Bluetooth module is the most economical and easiest way to go wireless. (Via Bluetooth)
This module makes it easy for you to wirelessly extend your serial interface, so you can control any program
running on your Laptop with serial port interface.
Usually this Bluetooth module is used with the Arduino, but it can be used with others
microcontrollers devices. Here its how its wired with an Arduino:
You need to remove the RX and TX cables when youre uploading the sketch to your
Arduino.
Sometimes people connect the TX from the Bluetooth module to the TX of the
Arduino thats wrong and it wont work. Make sure you connect it properly, the TX
into RX and the RX into the TX.
Note:
If the HC-05 Bluetooth Module asks for a password, Its 1234.
Upload this sketch below!
Make sure you remove the wires from RX and TX otherwise the code wont upload properly!
In the wiring diagram I am using a voltage divider because I believe it will be simpler
for most people to acquire the resistors than the IC. You only need to drop the
Arduino's TX voltage to 3.3V to match the RX of the HC-05. The Arduino's RX pin can
handle the HC-05 incoming TX signal which is 3.3V.
I used 2K and 1K ohms resistors in my circuit diagram to drop 5V to 3.3V but you can
use different resistor values.
Wiring code with default Rx , Tx
void setup() {
pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
Serial.begin(9600); // start serial communication at 9600bps
void loop() {
if( Serial.available() ) // if data is available to read
{
val = Serial.read(); // read it and store it in 'val'
}
if( val == 'H' ) // if 'H' was received
{
digitalWrite(ledpin, HIGH); // turn ON the LED
} else {
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
delay(100); // wait 100ms for next reading
Software serial library to make pin D10 & D11 As Tx & Rx instead of using the default Rx and tx " D0 &D1
On most arduino Board " .
#include <SoftwareSerial.h>
void setup()
{
bluetooth.begin(9600);
pinMode(ledGRN,OUTPUT);
pinMode(ledBLU,OUTPUT);
pinMode(ledRED,OUTPUT);
pinMode(ledWHI,OUTPUT);
}
void loop()
{
if (bluetooth.available())
{
BluetoothData=bluetooth.read();
if(BluetoothData==1)
{
digitalWrite(ledGRN,1);
bluetooth.println(GREEN ON);
}
if(BluetoothData==2)
{
digitalWrite(ledBLU,1);
bluetooth.println(BLUE ON);
}
if(BluetoothData==3)
{
digitalWrite(ledRED,1);
bluetooth.println(RED ON);
}
if(BluetoothData==4)
{
digitalWrite(ledWHI,1);
bluetooth.println(WHITE ON);
}
if (BluetoothData==0)
{
digitalWrite(ledGRN,0);
digitalWrite(ledBLU,0);
digitalWrite(ledRED,0);
digitalWrite(ledWHI,0);
bluetooth.println(LEDS OFF);
}
}
delay(100);
}
Arduino AND Bluetooth HC-05
Connect Arduino with PC
We now want to send or receive Data between arduino and computer , first we need to make
a Communication link to Definition arduino Board to the computer .
We will need a software called Tera Term to show the data received or what we want to send
through it .
this program below allow us to control LED connected to D13 To blink on/off , by
press # 1 from PC Keyboard the LED blink on , and if we press 0 LED blink off !
void setup() {
// put your setup code here, to run once:
blueTooth.begin(9600);
blueTooth.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (blueTooth.available()){
BluetoothData=blueTooth.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
blueTooth.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
blueTooth.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
After uploading This sketch go to tera term and press 0 or 1 and see the results