Arduino und Bluetooth-Verbindung Feuchtigkeitssensor

Hallo, wir sind absolute Anfänger und brauchen dringend Eure Hilfe. Wir haben einen Arduino, einen Oled-Bildschirm und eine Feuchtigkeitssensor miteinander verbunden, um entsprechende Werte auf dem Oled-Bildschirm anzeigen zu lassen und hatten entsprechend ein kleines Programm hierfür programmiert. Nun möchten wir, dass die Werte per Bluetooth auf das Handy gespielt werden und haben auch schon ein entsprechendes Programm dafür auf dem Handy installiert. Wir hatten auch hier ein Programm erstellt. Allerdings funktioniert dies nicht. Die Verbindung zwischen Handy und dem Arduino steht zwar, aber wir wissen nicht, wie wir Informationen im Programm auf dem Smartphone empfangen können.
Das ist unser Programm bevor wir Bluetooth hinzugefügt haben. Es hat auch gut funktioniert und wir sind zufrieden damit.

#include <Arduino.h>// OLED Bildschirm
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SSD1306 and SSD1308Z are compatible

// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ U8X8_PIN_NONE); //Low spped I2C

int sensorPin = A0; //Wasserfechtigkeit

int sensorValue = 0;

void setup(void)
{
u8g2.begin();

Serial.begin(9600);

}

void loop(void) {

sensorValue = analogRead(sensorPin);

if(sensorValue>100&&sensorValue<250){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Super!");
}while ( u8g2.nextPage());

}

if(sensorValue<100){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Oh nein");
u8g2.drawStr(10,20,"giess ");
u8g2.drawStr(10,30,"deine Pflanze!");
}while ( u8g2.nextPage());
}

if(sensorValue>100&&sensorValue<250){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Super!");
}while ( u8g2.nextPage());

}

if(sensorValue>250){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Och nee!");
u8g2.drawStr(10,20,"Das ist ");
u8g2.drawStr(10,30,"zu viel");
}while ( u8g2.nextPage());
}

}

Nun haben wir uns an Bluetooth versucht und es kam dann dieses Programm raus:

#include <Arduino.h>// OLED Bildschirm
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SSD1306 and SSD1308Z are compatible

// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ U8X8_PIN_NONE); //Low spped I2C

#include <SoftwareSerial.h> // Software Serial Port

#define RxD 6
#define TxD 7

#define PINBUTTON 5 // pin of button

#define DEBUG_ENABLED 1

SoftwareSerial BT(RxD,TxD);

char blueToothVal;

int sensorPin = A0; //Wasserfechtigkeit

int sensorValue = 0;

String BT_input; // to store input character received via BT.

void setup()
{
Serial.begin(9600); //default baud rate of module

while (!Serial)

{Serial.begin(9600); //serieller Monitor wird gestartet, Baudrate auf 9600 festgelegt
pinMode(13,OUTPUT); //PIN 13 wird als Ausgang festgelegt

 // wait for serial port to connect. Needed for native USB port only

}
}

void loop() {
sensorValue = analogRead(sensorPin);

if (sensorValue <= 100)
{
BT.print("bitte giess mich!" );
BT.println("hi");
}
else (sensorValue >= 100);
{
BT.println("super");
}

sensorValue = analogRead(sensorPin);
if(sensorValue<100){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,20,"bewaessern ");
}while ( u8g2.nextPage());
}

if(sensorValue<250&&sensorValue>100){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Super!");
}while ( u8g2.nextPage());

}

if(sensorValue>250){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,30,"zu viel");
}while ( u8g2.nextPage());

delay(1000);
}
}

Den Code haben wir auch schon hochgeladen aber es wird keine Nachricht auf das Handy geschickt.

Wir hoffen jemand kann uns weiterhelfen.

Würde ich gerne - bitte unbedingt das Post noch einmal korrigieren!
Markiere alles, was code ist und zusammengehört und drücke auf den Button </>
Das für alle Code.
Sonst ist das nicht lesbar und/oder verwendbar.
Danke

             Ich hoffe das ist jetzt so richtig.



  #include <Arduino.h>// OLED Bildschirm
  #include <U8g2lib.h>
  
  #ifdef U8X8_HAVE_HW_SPI
  #include <SPI.h>
  #endif
  #ifdef U8X8_HAVE_HW_I2C
  #include <Wire.h>
  #endif
  
  U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SSD1306 and SSD1308Z are compatible
  
  // U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //Low spped I2C
  
  int sensorPin = A0; //Wasserfechtigkeit
  
  int sensorValue = 0;
  
  void setup(void)
  {
  u8g2.begin();
  
  ```
  Serial.begin(9600);
  ```
  
  }
  
  void loop(void) {
  
  sensorValue = analogRead(sensorPin);
  
  if(sensorValue>100&&sensorValue<250){
  u8g2.firstPage();
  do {u8g2.setFont(u8g2_font_ncenB10_tr);
  u8g2.drawStr(10,10,"Super!");
  }while ( u8g2.nextPage());
  
  }
  
  if(sensorValue<100){
  u8g2.firstPage();
  do {u8g2.setFont(u8g2_font_ncenB10_tr);
  u8g2.drawStr(10,10,"Oh nein");
  u8g2.drawStr(10,20,"giess ");
  u8g2.drawStr(10,30,"deine Pflanze!");
  }while ( u8g2.nextPage());
  }
  
  if(sensorValue>100&&sensorValue<250){
  u8g2.firstPage();
  do {u8g2.setFont(u8g2_font_ncenB10_tr);
  u8g2.drawStr(10,10,"Super!");
  }while ( u8g2.nextPage());
  
  }
  
  if(sensorValue>250){
  u8g2.firstPage();
  do {u8g2.setFont(u8g2_font_ncenB10_tr);
  u8g2.drawStr(10,10,"Och nee!");
  u8g2.drawStr(10,20,"Das ist ");
  u8g2.drawStr(10,30,"zu viel");
  }while ( u8g2.nextPage());
  }
  
  }

Nun haben wir uns an Bluetooth versucht und es kam dann dieses Programm raus:

#include <Arduino.h>// OLED Bildschirm
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_ALT0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SSD1306 and SSD1308Z are compatible

// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //Low spped I2C

#include <SoftwareSerial.h> // Software Serial Port

#define RxD 6
#define TxD 7

#define PINBUTTON 5 // pin of button

#define DEBUG_ENABLED 1

SoftwareSerial BT(RxD,TxD);

char blueToothVal;

int sensorPin = A0; //Wasserfechtigkeit

int sensorValue = 0;

String BT_input; // to store input character received via BT.

void setup()
{
Serial.begin(9600); //default baud rate of module

while (!Serial)

{Serial.begin(9600); //serieller Monitor wird gestartet, Baudrate auf 9600 festgelegt
pinMode(13,OUTPUT); //PIN 13 wird als Ausgang festgelegt

```
 // wait for serial port to connect. Needed for native USB port only
```

}
}

void loop() {
sensorValue = analogRead(sensorPin);

if (sensorValue <= 100)
{
BT.print("bitte giess mich!" );
BT.println("hi");
}
else (sensorValue >= 100);
{
BT.println("super");
}

sensorValue = analogRead(sensorPin);
if(sensorValue<100){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,20,"bewaessern ");
}while ( u8g2.nextPage());
}

if(sensorValue<250&&sensorValue>100){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,10,"Super!");
}while ( u8g2.nextPage());

}

if(sensorValue>250){
u8g2.firstPage();
do {u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(10,30,"zu viel");
}while ( u8g2.nextPage());

delay(1000);
}
}

Viele Grüße

Es fehlt mindestens erstmal im setup() der Start vom Softwareserial....

Und dann vor dem veröffentlcihen von Code STRG-T in der IDE drücken und alle Leerzeilen raus, die da unnütz drin sind. Das liest sich eher niemand durch....