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
  • 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
  • Replies 4 replies
  • Subscribers 392 subscribers
  • Views 1143 views
  • Users 0 members are here
Related

Sending serial data from Arduino to Android via Bluetooth

april123
april123 over 7 years ago

Hi,

I'm working on a project, and one of the things I need to do is to make my phone ring, when I push a button on arduino. I'm using App Inventor, and I want that every time that I push the button, the number 5 will be sent (in bytes) from arduino, to the my App Inventor's application (and then when the application gets the number 5, it makes the sound works). Unfortunately, the algorithm that I wrote doesn't work, and I don't know why.  This is the algorithm that I wrote, I markered the relewant lines. Thanks in advance! (btw I'm using Arduino 101)

 

#include <CurieBLE.h>

#include <SoftwareSerial.h> //using other pins instead of 0 and 1

#define RxPin 8 //define software rx data pin on pin8

#define TxPin 9 //define software tx data pin on pin9

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

SoftwareSerial blueTooth(RxPin, TxPin);

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central

BLEUnsignedCharCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

 

const int ledPin = 13, noisePin = 11, button=2; // pin to use for the LED

 

void setup() {

  Serial.begin(9600);

  blueTooth.begin(9600);

  // set LED pin to output mode

pinMode(ledPin, OUTPUT);

pinMode(noisePin, OUTPUT);

pinMode(button,INPUT_PULLUP);

  // begin initialization

  BLE.begin();

 

  // set advertised local name and service UUID:

  BLE.setLocalName("LED");

  BLE.setAdvertisedService(ledService);

 

  // add the characteristic to the service

  ledService.addCharacteristic(switchCharacteristic);

 

  // add service

  BLE.addService(ledService);

 

  // set the initial value for the characeristic:

  switchCharacteristic.setValue(0);

 

  // start advertising

  BLE.advertise();

 

  Serial.println("BLE LED Peripheral");

}

 

void loop() {

  // listen for BLE peripherals to connect:

  BLEDevice central = BLE.central();

 

  // if a central is connected to peripheral:

  if (central) {

    Serial.print("Connected to central: ");

    // print the central's MAC address:

    Serial.println(central.address());

 

    // while the central is still connected to peripheral:

    while (central.connected()) {

      // if the remote device wrote to the characteristic,

      // use the value to control the LED:

      if (switchCharacteristic.written()) {

        if (switchCharacteristic.value()==1) {   // any value other than 0

          Serial.println("LED on");

          digitalWrite(ledPin, HIGH);         // will turn the LED on

        }

        if (switchCharacteristic.value()==0) {  // a 0 value

          Serial.println(F("LED off"));

          digitalWrite(ledPin, LOW);          // will turn the LED off

        }

        if(switchCharacteristic.value()==2){

        Serial.println ("piezo off");

        digitalWrite (noisePin, LOW);

      }      if (switchCharacteristic.value()==3){

        Serial.println ("piezo on");

        digitalWrite (noisePin, HIGH);

      }

      }

      if(digitalRead(button)==1) //the button was pushed

       {

        byte data=5;

        blueTooth.write(data);

       }

    }

 

    // when the central disconnects, print it out:

    Serial.print(F("Disconnected from central: "));

    Serial.println(central.address());

  }

}

  • Sign in to reply
  • Cancel
Parents
  • BigG
    BigG over 7 years ago

    I see you are using a clock timer in AI2, but what parameters have to used for timerinterval and when do you activate or enable this timer. A simpler method to consider is to use the BLE notifier service and then all you do is register to read the info in AI2, and then you do not need to use a timer at all.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • preksha
    preksha over 6 years ago in reply to BigG

    Kindly provide the .aia file so i can get to know the things clearly.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • preksha
    preksha over 6 years ago in reply to BigG

    Kindly provide the .aia file so i can get to know the things clearly.

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