element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Sending serial data from Arduino to Android via Bluetooth - NOT ANSWERED Yet
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 23 replies
  • Answers 7 answers
  • Subscribers 396 subscribers
  • Views 5764 views
  • Users 0 members are here
  • bluetooth
  • arduino
Related

Sending serial data from Arduino to Android via Bluetooth - NOT ANSWERED Yet

Former Member
Former Member over 10 years ago

Hi all,

 

I've been working on my Arduino project for quite a while now, managed to process the incoming data in the Arduino and display it on LCD (data is coming from a simulation on the laptop). But I cannot manage to view this data on my Android App (used MIT App Inventor) via Bluetooth (HC-06). I have managed to do this but after a week I tested it again and found some errors (I think problem was with my hardware) therefore (silly me) I didnt save the sketch, therefore blocks in MIT App Inventor are 100% working.

 

Also, I am connecting RX pin of Bluetooth through a voltage divider with pin 7.  Any ideas pls?

 

Arduino sketch:

 

#include <SoftwareSerial.h>

#include <LiquidCrystal.h>

 

byte myByte; // Storing the incoming data from serial port

int txPin = 7;

int rxPin =6;

 

lcd(12,11,5,4,3,2) //pin of lcd   ****I know this is not the exact command

SoftwareSerial BlueToothConnect(txPin, rxPin);

 

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

 

void setup(){

lcd.begin(16,2);

Serial.begin(9600);  //Serial communication

 

}

void loop(){

if(Serial.available(){

lcd.clear();

while(Serial.available()>0){       //Until data is being found in Serial, turn on serial on Bluetooth

BlueToothConnect.begin(9600);

myByte = Serial.read(); //reading the myByte data

lcd.write(myByte);  //showing data on LCD

Serial.write(myByte) ; //Showing data on serial monitor

 

txPin = digitalWrite(myByte);   //writing myByte content on pin 7 (txPin)

BlueToothConnect.write(txPin);   //  BlueToothConnect.print(txPin);  //displaying content of txPin to be view on Android display

 

}

 

Message was edited by: Lor B

  • Sign in to reply
  • Cancel

Top Replies

  • neilk
    neilk over 10 years ago in reply to Former Member +2 verified
    Hi lorrainebarbara I've never used SoftwareSerial successfully, although I've been trying to recently to reprogram an HC05 (Master/Slave Bluetooth). This requires the use of SoftWare serial ad so far I…
  • Former Member
    Former Member over 10 years ago in reply to neilk +2 suggested
    Hi neilk , Thank you so much I have managed to incorporate (and change) some of the program you ve published, worked Here is my whole sketch. Thanks alot for your help!! //Sending data serially to Android…
  • gadget.iom
    gadget.iom over 7 years ago in reply to happyforever +2 suggested
    Are you trying to send sensor values or text typed into the serial monitor? All of the other references to bluetooth.print are commented out. Try putting: bluetooth.print("Sending Init String"); // Test…
  • clem57
    0 clem57 over 10 years ago

    On first glance I do not see any AT commands? I would expect them either in your code or issued by the BlueToothConnect for pairing with the Android with a code like 4321 or whatever you decide. Did you show ALL the code? Attach if you can.

    Also there is a particular firmware level that can affect you listed by another AT command. See Using the HC-06 Bluetooth Module | MCU on Eclipse for details and to understand it may affect you here.

    Hope this helps,

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    yep all code there. No i dont have the AT commands, i guess i have to add them as well then, I will try that. Thanks image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 10 years ago in reply to Former Member

    lorrainebarbara Hi

     

    If you have HC06, then it should already be in Slave mode and 9600 Baud by default. - shouldn't need AT commands at this stage

     

    I use a voltage divider between the Arduino Tx and HC06 Rx

     

    Have you paired the HC06 with your Android device? If you had it working, it may have become unpaired

     

    txPin = digitalWrite(myByte);   //writing myByte content on pin 7 (txPin)

    BlueToothConnect.write(txPin);   //  BlueToothConnect.print(txPin);  //displaying content of txPin to be view on Android display

    Seems a bit confused - why are you trying to output to the software serial Tx pin with a digital Write?

     

    Finally, can I suggest you go back to basics and prove that you can send data to your Android device, via Bluetooth, using the Arduino hardware Rx/Tx pins, as shown in my blog: http://www.element14.com/community/people/neilk/blog/2014/07/18/app-inventor-and-arduino-part-2--send-data-from-arduino-to-android-app

     

    Using your own Android App, of course.

     

    Hope this helps

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to neilk

    Hi Neil,

     

    Thanks for your response. Yes I have paired with my Android device, the BT LED stops flashing.

     

    txPin = digitalWrite(myByte);   //writing myByte content on pin 7 (txPin)

    BlueToothConnect.write(txPin);   //  BlueToothConnect.print(txPin);  //displaying content of txPin to be view on Android display

     

    Since my incoming data is stored in variable myByte, I am trying to write that data in txPin (pin 7 of Arduino) which is connected with RX pin of my BT module (HC-06) also through a voltage divider. I think I have the wrong commands. image

    I already saw your blog yes, I will try to send simple data instead of my complex data which I need to receive on my Android App, at least from there I could see and determine if I can send data to my device.

    will let you know.

     

    Thanks alot

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 10 years ago in reply to Former Member

    Hi lorrainebarbara

     

    Just  to clarify - the LED on your HC06 stops flashing when the connection from your Master Bluetooth device (Android, or you can do from a PC using a terminal emulator) is established - not when it's paired image

     

    So if it stops flashing then it's obviously paired and connected...........

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to neilk

    Ok good to know image

    Then i guess I have managed to pair them. I think the problem is how im handling the varible to send it on the RX pin of my BT.

     

    Thanks again

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 10 years ago in reply to Former Member

    Hi lorrainebarbara

     

    I've never used SoftwareSerial successfully, although I've been trying to recently to reprogram an HC05 (Master/Slave Bluetooth). This requires the use of SoftWare serial ad so far I haven't got anybody else's sketches to work!!

     

    So I decided to make a very simple example; it works, and here it is:

     

    /*  Demonstration of sending data to an Android App via Bluetooth. This example
        uses SoftwareSerial on pins 2 and 3
       
       Characters are read in from the keyboard, output on the Serial Monitor and written to
       the Bluetooth device using SoftwareSerial
         
        Neil Kenyon
        05 June 2015  
    */
       
    #include <SoftwareSerial.h>`
    
    #define rxPin 2                     // define SoftwareSerial rx data pin
    #define txPin 3                     // define SoftwareSerial tx data pin
    
    SoftwareSerial blueTooth(rxPin, txPin);  // create instance of SoftwareSerial
    
    void setup()
    {
      Serial.begin(9600);            // Start hardware Serial
      blueTooth.begin(9600);         // Start SoftwareSerial
    }
    
    void loop()
    {
        char c;
         if (Serial.available())
         {
           c = Serial.read();
          
           Serial.println(c);             // Write the character to the Serial Monitor
          
           blueTooth.write (c);           // Write the character to Bluetooth
         }
    }

     

    It actually works with the very simple Android app given in my blog.

     

    Hope you can get it working

     

    Neil

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to neilk

    Hi neilk,

     

    Thank you so much image I have managed to incorporate (and change) some of the program you ve published, worked image Here is my whole sketch. Thanks alot for your help!! image

     

    //Sending data serially to Android via Bluetooth from Arduino

     

     

    #include <SoftwareSerial.h> //Libary used for Software Serial (Using other pins instead of 0 and 1)

    //Since pin 0 and pin 1 are being used by the Arduino USB cable

    #include <LiquidCrystal.h> //Library used for LCD

     

     

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  //Initilizing Arduino pins

     

    #define rxPin 8                    // define SoftwareSerial rx data pin on pin8

    #define txPin 9                     // define SoftwareSerial tx data pin on pin9

     

    int potPin = 0;                        // Define the Analog input

     

    SoftwareSerial blueTooth(rxPin, txPin);  // create instance of SoftwareSerial(8, 9 respectively)

     

     

    void setup()

    {

      lcd.begin(16, 2); //Setting up LCD columns and rows

      Serial.begin(9600);            // Start hardware Serial

     

     

      pinMode(potPin, INPUT);

      blueTooth.begin(9600);       // Start SoftwareSerial

    }

     

    void loop()

    {

        byte incomingData; //incoming data

         if (Serial.available())  //If there is data in serial port

         {

            delay(100); //Delay of 100ms

            lcd.clear(); //Clear the LCD display

        

           while(Serial.available()>0) {

          

           incomingData = Serial.read();//read the values in 'incomingData'

         

           lcd.write(incomingData); // ASCII character printed on LCD

          

           Serial.write(incomingData);   //Write the characters on the Serial Monitor

           //Serial.println(incomingData);             // Write the characters to the Serial Monitor

          

           blueTooth.write(incomingData);        // Write the characters to Bluetooth

         }

      }

    }

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • neilk
    0 neilk over 10 years ago in reply to Former Member

    hi lorrainebarbara

     

    Happy to help image. It moved my understanding on as well!

     

    If you are happy, please mark my answer as helpful or correct. Thanks.

     

    Any more problems, feel free to post. There are lots of very helpful people in this forum image

     

    Best wishes

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 10 years ago in reply to Former Member

    hi lorrainebarbara Thankyou image

     

    All the very best

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube