The bluetooth shield used in this project is a great way to detach the Arduino from your computer. What is even better, is that the shield allows you to control your arduino from your mobile phone or other bluetooth enabled device through simple Serial commands. In this tutorial we will connect a Grove Chainable RGB LED to the bluetooth shield directly, and send simple commands using the Bluetooth SPP app on a Samsung Galaxy S2 to change the colour of the LED (Red , Green and Blue)
/* This project combines the code from a few different sources. This project was put together by ScottC on the 15/01/2013 http://arduinobasics.blogspot.com/
Bluetooth slave code by Steve Chang - downloaded from : http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield
Grove Chainable RGB code can be found here : http://www.seeedstudio.com/wiki/Grove_-_Chainable_RGB_LED#Introduction
*/
#include <SoftwareSerial.h> //Software Serial Port
#define uint8 unsigned char #define uint16 unsigned int #define uint32 unsigned long int
#define RxD 6 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD) #define TxD 7 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)
#define DEBUG_ENABLED 1
int Clkpin = 9; //RGB LED Clock Pin (Digital 9) int Datapin = 8; //RGB LED Data Pin (Digital 8)
SoftwareSerial blueToothSerial(RxD,TxD);
/*----------------------SETUP----------------------------*/ void setup() { Serial.begin(9600); // Allow Serial communication via USB cable to computer (if required) pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6 pinMode(TxD, OUTPUT); // Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin 7 pinMode(13,OUTPUT); // Use onboard LED if required. setupBlueToothConnection(); //Used to initialise the Bluetooth shield
pinMode(Datapin, OUTPUT); // Setup the RGB LED Data Pin pinMode(Clkpin, OUTPUT); // Setup the RGB LED Clock pin
}
/*----------------------LOOP----------------------------*/ void loop() { digitalWrite(13,LOW); //Turn off the onboard Arduino LED char recvChar; while(1){ if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield recvChar = blueToothSerial.read(); Serial.print(recvChar); // Print the character received to the Serial Monitor (if required)
//If the character received = 'r' , then change the RGB led to display a RED colour if(recvChar=='r'){ Send32Zero(); // begin DataDealWithAndSend(255, 0, 0); // first node data Send32Zero(); // send to update data }
//If the character received = 'g' , then change the RGB led to display a GREEN colour if(recvChar=='g'){ Send32Zero(); // begin DataDealWithAndSend(0, 255, 0); // first node data Send32Zero(); // send to update data }
//If the character received = 'b' , then change the RGB led to display a BLUE colour if(recvChar=='b'){ Send32Zero(); // begin DataDealWithAndSend(0, 0, 255); // first node data Send32Zero(); // send to update data } }
//You can use the following code to deal with any information coming from the Computer (serial monitor) if(Serial.available()){ recvChar = Serial.read();
//This will send value obtained (recvChar) to the phone. The value will be displayed on the phone. blueToothSerial.print(recvChar); } } }
//The following code is necessary to setup the bluetooth shield ------copy and paste---------------- void setupBlueToothConnection() { blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400 blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave" blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here delay(2000); // This delay is required. blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable Serial.println("The slave bluetooth is inquirable!"); delay(2000); // This delay is required. blueToothSerial.flush(); }
//The following code snippets are used update the colour of the RGB LED-----copy and paste------------ void ClkProduce(void){ digitalWrite(Clkpin, LOW); delayMicroseconds(20); digitalWrite(Clkpin, HIGH); delayMicroseconds(20); }
You don't need to download a library to get this project running. But if you plan to use bluetooth shields to get 2 Arduinos to communicate to each other, then I would advise that you download the library files (which are just examples) from the Seeedstudio site : here.
Visit this site to setup your phone or laptop for bluetooth communication to the shield - here
The app used on my Samsung Galaxy S2 phone was "Bluetooth SPP"
You will initially need to enter a pin of '0000' to establish a connection to the Bluetooth shield - which will appear as "SeeedBTSlave" or whatever text you place on line 90 of the Arduino code above.
Warning !
Not all phones are compatible with the bluetooth shield. If you have used this shield before - please let me know what phone you used - so that we can build a list and inform others whether their phone is likely to work with this project or not. Obviously - those phones that do not have bluetooth within - will not work :). And I have not tried any other apps either
I got it to work very easily with my Samsung Galaxy S2 using the free Bluetooth SPP app from the google play store.
This was fun, but I want to make my own app ! Have a look at my latest 4-part tutorial which takes you step-by-step through the process of building your own app using the Processing/Android IDE. You can build your own GUI interface on your Android Phone and get it to communicate via Bluetooth to your Arduino/Bluetooth Shield. Click on the links below for more information:
Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Introduction Nextion is a programmable human machine interface (HMI) that can be customized and designed to simplify the interaction between you and your project. This Nextion Enhanced module (NX4827K043) with a resistive touch screen display, has some additional features not seen in previous traditional versions of the Nextion series. A built in real time clock (RTC) Accessible flash memory (32MB) GPIO functionality Faster clock speed Before you connect the Nextion Enhanced module to your project, you need to design your interface with the free Nextion Editor. The editor can be downloaded here. In this project, I will be designing a simple dynamic interface, which will allow me to interact with a stepper motor in two different ways. The first interface will let me control the direction and speed of the stepper motor through the use of a simple GUI. I will have left and right arrows for the direction, and up and down arrows for the speed. I will also map the Expansion board...
PART THREE If you happened to land on this page and missed PART ONE , and PART TWO , I would advise you go back and read those sections first. This is what you'll find in partone : Downloading and setting up the Android SDK Downloading the Processing IDE Setting up and preparing the Android device Running through a couple of Processing/Android sketches on an Andoid phone. This is what you will find in part two : Introducing Toasts (display messages) Looking out for BluetoothDevices using BroadcastReceivers Getting useful information from a discovered Bluetooth device Connecting to a Bluetooth Device An Arduino Bluetooth Sketch that can be used in this tutorial InputStream and OutputStream We will now borrow some code from the Android developers site to help us to establish communication between the Android phone and the Bluetooth shield on the Arduino. By this stage we have already scanned and discovered the bluetooth device and made a successful connection. We now need to create ...
Comments
Post a Comment