element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs MIT App Inventor and Arduino Part 2 - send data from Arduino to Android and display
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: neilk
  • Date Created: 18 Jul 2014 4:06 PM Date Created
  • Views 11756 views
  • Likes 4 likes
  • Comments 53 comments
  • android
  • bluetooth
  • hc06
  • mit
  • arduino_tutorials
  • arduino tutorials
  • appinventor
  • arduino_tutorial
  • arduino tutorial
  • arduino
Related
Recommended

MIT App Inventor and Arduino Part 2 - send data from Arduino to Android and display

neilk
neilk
18 Jul 2014

MIT App Inventor and Arduino Part 2 - send data from Arduino to Android and display


I found numerous links via Google for this example; unfortunately a lot of them were the same tutorial posted in different places by the same person. None of them included the Arduino sketch! However, the sketch tuned out to be entirely trivial

 

I won't bother giving any of the links, because the the whole thing is unbelievably simple!

 

Here is the Design screen for the App:

 

                                                              image

The screen is very similar to the previous app, except the On and Off buttons are replaced by 2 Labels: Label2 has the default text of "Data from Arduino" and Label3 is given the default text of "0", in Red with a larger font.


As in the previous App, there is a  Bluetooth Client and we also need to add a  Clock component to act as a timer.  These are both non-visible on the display and are shown below the bottom of the Android device screen.

 

In the Blocks screen we retain the 2 Blocks relating to selecting and connecting to Bluetooth and the Block responsible for disconnecting  from Bluetooth. We  dispense with the Button Blocks.


We then add the following new Block to receive and display the data:

image

In the Design screen, I left the default timer interval on the Clock at 1000mS because we want to have time to actually read the Android display.

 

The Arduino Sketch turned out to be very simple:

 

/*   Demonstration sketch to send data to an Android App via Bluetooth - essentially simple; this is just serial output of integer data.

     The Bluetooth module is connected across the Arduino Rx and Tx lines as before.

      A 10k pot is connected across +5v and ground; the slider is connected to analog input 0, to supply varying data.

 

     Neil Kenyon

     15 July 2014

*/

int potPin = 0;                                  // Define the Analog input

void setup()

{

  Serial.begin(9600);

  pinMode(potPin, INPUT);

}

void loop()

{

    int value = analogRead(potPin);    // read the value of the Analog Input

    Serial.println(value);                     // Print the value; can also be seen on Serial Monitor

    delay(1000);                                   // Don't send too fast or the Android buffer will flood - this worked for me

}

 

This seems to work well enough to demonstrate the ease with which we can send data from the Arduino to the Android App.


Edited on 10 August 2015........problems can arise if the Arduino Transmission and Android Receive delay times are set identically. This wasn't a problem for my set up, but seems to be for others. If you leave the Arduino delay at 1000mS, then reduce the clock/timer delay in App Inventor to 950mS, it should be good image



There are two attachments; the second one - Data_from_Arduino_A.zip does some extra error checking which some Android devices seem to need more than others.

Attachments:
Data_from_Arduino.zip
Data_from_Arduino - A.zip
  • Sign in to reply

Top Comments

  • Former Member
    Former Member over 10 years ago +2
    Thank you for all your help, I have now (after some playing) successfully able to receive accelerometer data via bluetooth to an android device!!!!! Thanks!
  • Former Member
    Former Member over 10 years ago +2
    I found that the following youtube video was very helpful: https://www.youtube.com/watch?v=DkGGilznfG8
  • Former Member
    Former Member over 10 years ago +2
    Hey everybody... Could You Do Me a Favour? I got problem here when I'm trying to make android app using AppInventor2. I'm going to make android app to showed data "TempValue", "MoistureValue", "ldrvalue…
  • neilk
    neilk over 7 years ago in reply to t-lesh

    Hi t-lesh

     

    A few questions for you:

     

    1. Does your program actually work and output data to the LCD display?
    2. Have you managed to get my simple example to work?

     

    It's important to start slowly if you are new to programming and take it step by step, not moving on until you have the current step working.

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • t-lesh
    t-lesh over 7 years ago

    Hi Neil

     

    I am new to programming and I have managed to write a program using a couple of sensors for hydroponics project which is due shortly. I have decided to add the HC-06 Bluetooth module to the project so to get the sensor values on my android device.

     

    The code goes as follows

     

    //Including Libraries

    #include <dht.h>7

    #include <LiquidCrystal.h>

     

     

    //Assigning pins for LCD

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

    dht DHT;

     

     

    //Assigning pins for Temp&Humid sensor

    #define DHT11_PIN 7

     

     

    //Assigning pins on the Arduino

    const int fan = 9;

    const int led =13;

    int sensorPin = A0; // select the input pin for LDR

    int sensorValue =500 ; // variable to store the value coming from the sensor

     

     

    void setup(){

      lcd.begin(16, 2); // defining LCD Characters

      Serial.begin(9600); //communication speed

     

      // making pins as INPUT & OUTPUTS

      pinMode(9, OUTPUT);

      pinMode(A0, INPUT);

      pinMode(led, OUTPUT);

    }

     

     

    void loop()

    {

    // LOOP For Temp & Humid

      while(1){

      DHT.read11(DHT11_PIN);

      int chk =DHT.temperature;

      lcd.setCursor(0,0);

      lcd.print("Temp: ");

      lcd.print(DHT.temperature);

      lcd.print((char)223);

      lcd.print("C");

      lcd.setCursor(0,1);

      lcd.print("Humi: ");

      lcd.print(DHT.humidity);

      lcd.print("%");

     

     

      if ( chk>=26){

        digitalWrite(fan,1);

        delay(100);

       }

      if(chk<26)

       {

          digitalWrite(fan, 0);

          delay(100);

          }

      delay(1000);

      //Loop for the LDR and PULP

     

     

     

     

    sensorValue = analogRead(sensorPin); // read the value from the sensor

    Serial.println(sensorValue); //prints the values coming from the sensor on the screen

    if(sensorValue<800){

    digitalWrite(led,true);

    delay(50);

     

     

    }else

    {digitalWrite(led,false);

    delay(50);}

    //digitalWrite(13,1);

    delay(50);

    }

     

     

    }

     

    It will be much apprecated if you could help me interface the readings of the vakues with my bluetooth module.

     

    Thanks Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tonkog777
    tonkog777 over 8 years ago

    Hi neilk

    I have a problem. I want to receive message by Arduino, and send message to my android phone, and display it. but I dont know how to do it. Would you teach me how to do it, please. Thank you neilk.

     

    ps: I want to use arduino UNO, CNY 70, HC-05, VC0706, SD card to achieve Use Eyes To Control Shooting Function. Would you tell me how to achieve it. Thank you !!!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 8 years ago in reply to fabijes

    Hi fabijes.

     

    Have you demonstrated your ability to transmit data via Bluetooth from your Arduino to an Android App, as in my original posting?

     

    If not, then you must be able to do that first.

     

    I assume your accelerometer generates 3 values - x,y,z. I suggest you look here for a possible solution to your problem.

     

    https://www.element14.com/community/thread/44533/l/reading-arduino-csv-data-in-app-inventor

     

    Hope this helps

     

    Good luck

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fabijes
    fabijes over 8 years ago

    good day neil please i need your help i try send data from accelerometer with bluetooth to a android app can you help with it?? i new with this things pleasee help me i have trying your code only in the monitor serial and its work perfect but i have to probe it with other app designed

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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