# Android Bluetooth to Arduino and vice versa

**URL:** https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578
**Category:** Processing for Android
**Created:** [December 29, 2020, 8:52am UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578 "2020-12-29T08:52:21Z")
**Posts on this page:** 1
**Showing post:** 135

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [January 18, 2021, 12:25am UTC](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578/135 "2021-01-18T00:25:24Z")

</div>

hi noel

this is nice if can run via bluetooth

```auto
import processing.serial.*;

 int adcValue = 0; // value received from Serial 
 // String Unit="mA";
 // String Unit="kΩ";
 // String Unit="°C"; // We can use Unicode chars directly
String Unit="ANALOG READ";  
String Unit1="VALUE";   

// Unicode codes may be entered as well
 
 Serial myPort;
 PFont Segment, Units; 

 void setup() {
                          // Setup the display window 
  size(666, 280); // Size of the window
  Segment = createFont("Segment7", 150); // Assign fonts and size 
  Units = createFont("Arial", 40);
  textFont(Segment);
  textAlign(RIGHT); // Text align 
  fill(250,250,0); // Font color is yellow = red + green

 // println(Serial.list()); // List all the available serial ports
  // Then open the port you're using, my is the first, i.e. '0'
myPort = new Serial(this,"COM3", 9600); 
 // myPort = new Serial(this, Serial.list()[], 9600);
 // don't generate a serialEvent() unless you get a newline character:
   myPort.bufferUntil('\n');
 }

void draw()
{ // Let's start to display
  background(0,0,0); // set the background color black

  textFont(Segment);
  text(adcValue, 311, 250);
  
  textFont(Units);
  text(Unit,433,65);
text(Unit1,511,211);

}

void serialEvent(Serial myPort) 
{
 String inString = myPort.readStringUntil('\n'); // get the ASCII string:
 if (inString != null) 
    {
     inString = trim(inString); // trim off any whitespace
     adcValue = int(inString); // convert into an integer
     adcValue =int(map(adcValue, 0, 1023, 0, 1023)); // possible range adjusting
    }
 }

```

arduino

```auto
#include <SoftwareSerial.h>

SoftwareSerial LEDdisplej(2, 3); //RX pin, TX pin

int adcValue = 0;

void setup() {

      Serial.begin(9600);

  LEDdisplej.begin(9600); // Talk to the Serial7Segment at 9600 bps
  LEDdisplej.write('v'); // Reset the display - this forces the cursor to return to the beginning of the display
}

void loop() 
{
  adcValue = 0; // Filter - average from 16 values 
  for (int i = 1; i<=16; i++)
    adcValue = adcValue + analogRead(0);
  adcValue = adcValue/16;

 
  char tempString[10]; // Used for sprintf
  sprintf(tempString, "%4d",adcValue); // Convert into a string that is right adjusted
  //sprintf(tempString, "%d", adcValue); // Convert into a string that is left adjusted (requires digit 1 command)
  //sprintf(tempString, "%04d", adcValue); // Convert into a string with leading zeros
  //sprintf(tempString, "%4X", adcValue); // Convert int HEX, right adjusted
  
  LEDdisplej.print(tempString); // Send serial string out the soft serial port to the S7S
 
  Serial.println(tempString); // Works too, but we don't need trailing spaces ' ' in the front
  // Serial.println(adcValue);

  delay(100);
}

```

---

_[View the full topic](https://discourse.processing.org/t/android-bluetooth-to-arduino-and-vice-versa/26578)._
