# Code Arduino Not Working

**URL:** <https://forum.arduino.cc/t/code-arduino-not-working/1139560>\
**Category:** Nano 33 BLE\
**Created:** [June 19, 2023, 4:18pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560 "2023-06-19T16:18:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanadelrey123d](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@lanadelrey123d](https://forum.arduino.cc/u/lanadelrey123d)\
**Post date:** [June 19, 2023, 4:18pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/1 "2023-06-19T16:18:39Z")

</div>

Hello, I am having trouble receiving data to my appInventor. I think my code is wrong. Can someone please have a look at it and tell me if it seems wrong because i am not receiving anything in my monitor serial nor my app. It's my first time using Nano 33 BLE.  
#include \<ArduinoBLE.h\>  
int NbTopsFan; // Nombre de tours d'hélices  
float Calc; // Calcul du volume  
float Q; // Calcul du débit  
int hallsensor = 2; // PIN DIGITALE 2

BLEService bleuart("19B10010-E8F2-537E-4F6C-D104768A1214"); // UUID du service BLE UART, on crée un service  
BLECharacteristic txCharacteristic("19B10010-E8F2-537E-4F6C-D104768A1214", BLEWriteWithoutResponse, 20); // UUID de la caractéristique d'écriture

void rpm() {NbTopsFan++;}  
void setup() {  
Serial.begin(9600);  
pinMode(hallsensor, INPUT);  
attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);  
if (!BLE.begin()) {  
Serial.println("starting Bluetooth® Low Energy module failed!");  
while (1);}

BLE.setLocalName("Arduino Nano BLE 33");  
BLE.setAdvertisedService(bleuart); //Définit le service BLE annoncé  
bleuart.addCharacteristic(txCharacteristic);  
BLE.addService(bleuart);  
BLE.advertise();  
Serial.println("En attente de la connexion BLE...");}

void loop() {  
BLEDevice central = BLE.central();  
if (central) {  
Serial.print("Connecté à : ");  
Serial.println(central.address());  
while (central.connected()) {  
NbTopsFan = 0;  
delay(1000);  
Q = (NbTopsFan / 9.5);  
Calc = (Q / 60) + Calc;  
String To\_App = String(Calc, 3) + "," + String(Q, 3);  
Serial.println(To\_App);  
txCharacteristic.writeValue(To\_App.c\_str(), To\_App.length());  
delay(200);}  
Serial.print("Déconnecté de : ");  
Serial.println(central.address());}  
}

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [June 19, 2023, 5:05pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/2 "2023-06-19T17:05:28Z")

</div>

I suggest you read the forum guidelines and follow them. If you do that you are likely to get much more help. Code needs to be posted in code tags. This link will get you started: [How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966)

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 19, 2023, 5:32pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/3 "2023-06-19T17:32:08Z")

</div>

You have two sketches pasted together.

Sketch #1

```arduino
#include <ArduinoBLE.h>
int NbTopsFan; // Nombre de tours d'hélices
float Calc; // Calcul du volume
float Q; // Calcul du débit
int hallsensor = 2; // PIN DIGITALE 2

BLEService bleuart("19B10010-E8F2-537E-4F6C-D104768A1214"); // UUID du service BLE UART, on crée un service
BLECharacteristic txCharacteristic("19B10010-E8F2-537E-4F6C-D104768A1214", BLEWriteWithoutResponse, 20); // UUID de la caractéristique d'écriture

void rpm() {
  NbTopsFan++;
}
void setup() {
  Serial.begin(9600);
  pinMode(hallsensor, INPUT);
  attachInterrupt(digitalPinToInterrupt(hallsensor), rpm, RISING);
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");
    while (1);
  }

  BLE.setLocalName("Arduino Nano BLE 33");
  BLE.setAdvertisedService(bleuart); //Définit le service BLE annoncé
  bleuart.addCharacteristic(txCharacteristic);
  BLE.addService(bleuart);
  BLE.advertise();
  Serial.println("En attente de la connexion BLE...");
}

void loop() {
  BLEDevice central = BLE.central();
  if (central) {
    Serial.print("Connecté à : ");
    Serial.println(central.address());
    while (central.connected()) {
      NbTopsFan = 0;
      delay(1000);
      Q = (NbTopsFan / 9.5);
      Calc = (Q / 60) + Calc;
      String To_App = String(Calc, 3) + "," + String(Q, 3);
      Serial.println(To_App);
      txCharacteristic.writeValue(To_App.c_str(), To_App.length());
      delay(200);
    }
    Serial.print("Déconnecté de : ");
    Serial.println(central.address());
  }
}

```

Sketch #2

```arduino
#include <MD_MAX72xx.h>
#define	MAX_DEVICES	2

const int maxX = MAX_DEVICES * 8 - 1;
const int maxY = 7;

#define	CLK_PIN 13
#define	DATA_PIN	11
#define	CS_PIN 10

#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2

MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);

int x = 0;
int y = 0;

void setup() {
  mx.begin();
  mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
  mx.clear();

  pinMode(VERT_PIN, INPUT);
  pinMode(HORZ_PIN, INPUT);
  pinMode(SEL_PIN, INPUT_PULLUP);
}

// the loop function runs over and over again forever
void loop() {
  int horz = analogRead(HORZ_PIN);
  int vert = analogRead(VERT_PIN);
  if (vert < 300) {
    y = min(y + 1, maxY);
  }
  if (vert > 700) {
    y = max(y - 1, 0);
  }
  if (horz > 700) {
    x = min(x + 1, maxX);
  }
  if (horz < 300) {
    x = max(x - 1, 0);
  }
  if (digitalRead(SEL_PIN) == LOW) {
    mx.clear();
  }
  mx.setPoint(y, x, true);
  mx.update();
  delay(100);
}

```

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 19, 2023, 6:46pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/4 "2023-06-19T18:46:26Z")

</div>

```arduino
//BLECharacteristic txCharacteristic("19B10010-E8F2-537E-4F6C-D104768A1214", BLEWriteWithoutResponse, 20); // UUID de la caractéristique d'écriture
BLECharacteristic txCharacteristic("19B10010-E8F2-537E-4F6C-D104768A1214", BLERead, 20); // UUID de la caractéristique d'écriture

```

You want the central app to read the characteristic, not write to it.

With this change, using Light Blue, I can see the data output of calc and Q.

@xfpd

> You have two sketches pasted together.

??

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 19, 2023, 6:58pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/5 "2023-06-19T18:58:09Z")

</div>

> [@cattledog](#):
>
> > You have two sketches pasted together.
> 
> ??

@cattledog - The original "sketch" had two `setup()` and two `loop()` ... so I separated and posted them.

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 19, 2023, 7:00pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/6 "2023-06-19T19:00:51Z")

</div>

> [@xfpd](#):
>
> The original "sketch" had two `setup()` and two `loop()`

Strange. I don't see any edits of the original post. I would have thought the forum tracks everything.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 19, 2023, 7:10pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/7 "2023-06-19T19:10:36Z")

</div>

You are right... I must have double-pasted... oops. Sorry.

---

<div class="post-metadata">

**Author:** ![lanadelrey123d](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@lanadelrey123d](https://forum.arduino.cc/u/lanadelrey123d)\
**Post date:** [June 19, 2023, 7:28pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/8 "2023-06-19T19:28:27Z")

</div>

Sorry I didn't understand. I posted one sketch not two.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 19, 2023, 7:29pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/9 "2023-06-19T19:29:46Z")

</div>

Yes, I made a mistake by pasting a second sketch. Sorry. (I would like to delete it, but that would make the thread read strange)

---

<div class="post-metadata">

**Author:** ![lanadelrey123d](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@lanadelrey123d](https://forum.arduino.cc/u/lanadelrey123d)\
**Post date:** [June 19, 2023, 8:27pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/10 "2023-06-19T20:27:50Z")

</div>

Thank you so much, you really did correct my code. I have one more question please if you familiar with app inventor.

 ![Capture d’écran 2023-06-19 222702](https://europe1.discourse-cdn.com/arduino/original/4X/6/6/8/6689bead6278c4386fbc617aa2d3d66a3e82e6f4.png)  
 ![Capture d’écran 2023-06-19 222621](https://europe1.discourse-cdn.com/arduino/original/4X/e/e/5/ee5f0cf091b8dd46a58238ed3c699f715f8ea4a1.png)  
 ![Capture d’écran 2023-06-19 222553](https://europe1.discourse-cdn.com/arduino/original/4X/1/2/8/128867827b0e81d721c04863196455af29abc8ed.png)  
Please Help me SOS

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 19, 2023, 9:00pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/11 "2023-06-19T21:00:22Z")

</div>

I do not know much about app inventor, but there is a [forum](https://community.appinventor.mit.edu/) where you might be able to ask your questions.

---

<div class="post-metadata">

**Author:** ![lanadelrey123d](https://avatars.discourse-cdn.com/v4/letter/l/57b2e6/32.png) [@lanadelrey123d](https://forum.arduino.cc/u/lanadelrey123d)\
**Post date:** [June 20, 2023, 7:04am UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/12 "2023-06-20T07:04:54Z")

</div>

Hello, I don't receive anything in my BlueLight App. I can connect the BLE and that's it. And i only see the values in my serial monitor. And when i disconnect from the app. The serial monitor stops. I want to receive the data in my app. Can you please help me

 ![Capture d’écran 2023-06-20 090235](https://europe1.discourse-cdn.com/arduino/original/4X/d/7/b/d7b77b81733096b45ecf8a72f4c907e44fd14b75.png)

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 20, 2023, 3:38pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/13 "2023-06-20T15:38:09Z")

</div>

> [@lanadelrey123d](#):
>
> I don't receive anything in my BlueLight App

I can see the data on my phone, so there maybe and issue with how you are using LightBlue.

After you connect you should be able to go to the bottom of the screen and see the characteristics.

 ![Screenshot_20230620_082250_LightBlue](https://europe1.discourse-cdn.com/arduino/original/4X/4/a/7/4a7f51d57cc89ba20580726c286f04dee12124f2.jpeg)

Then press the little arrow to navigate to the screen for that characteristic. Then select the data format to be UTF-8 String and press the READ AGAIN button.

 ![Screenshot_20230620_081738_LightBlue](https://europe1.discourse-cdn.com/arduino/original/4X/c/f/e/cfe6496847c3afe5cfc870aea328f0b99ee47e84.jpeg)

I am testing with a pwm signal of 500Hz on pin4 jumpered to pin3.  
The 52.632 value is 500/9.5 = Q.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 17, 2023, 3:38pm UTC](https://forum.arduino.cc/t/code-arduino-not-working/1139560/14 "2023-12-17T15:38:52Z")

</div>

Closed on December 17, 2023, 3:38pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
