Codes doesn't work (arduino,MIT)

Hello, I have to do a project, but it´s my first project with arduino and MIT together, what causes me to ask for help, because my program doesn't give me any informations in label2, from the arduino.
Thanks in advance!

1 Like

Use Serial.println("your text") instead of Serial.print("your text") to send your messages on separate lines.

To receive separate lines one at a time, follow this standard advice:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Thank you for your answer, i think i did everything you told me (screenshots),but where do i check if length of list(split list result) >= expected list length and which timerinterval should i use ? I´ve also uploaded the aia file.

Arduino.aia (3.1 KB)

Your AI2 blocks looks okay for detection of those 3 sentences, but you need an else clause to catch and display other incoming data.

Your sketch in post 1 (hard to read from screen shots) lacks the required println() commands to separate lines.

Think of a way to test your incoming measurements to break off extra text to just get the numbers, or to identify different types of readings.

Upload your corrected sketch's .ino file for further analysis.

In my arduino file I only print the sentences with my mySerial funcion, so I don´t have any useless informations and I also set the right baudrate for my mySerial function, but it´s still not working.
Also I can´t upload a .ino file, so I converted it to a .txt file maybe now it´s better for you to read. I really don´t know what I could try to get this thing working. Arduino.aia (3.1 KB) arduino.txt (2.8 KB)

For the benefit of the other board readers, here is your code inline:

#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial (2,3);
LiquidCrystal_I2C lcd(0x27,20,4);


#define SENSOR_PIN_A A1
#define SENSOR_PIN_D 7



int ThermistorPin = A0;
int Vo;
float R1 = 10000; // value of R1 on board
float logR2, R2, T;
float c1 = 0.001129148, c2 = 0.000234125, c3 = 0.0000000876741; //steinhart-hart coeficients for thermistor
int ana11=11;
int ana10=10;
int ana9=9;
int i=0;
int v;
int D;
 

void setup() {
  Serial.begin(9600);
  mySerial.begin(38400);
  pinMode(SENSOR_PIN_D, INPUT);
  pinMode(ana9,OUTPUT);

    lcd.init();
    lcd.backlight();
    lcd.clear();

 

  for (int x=0; x<10; x++) {
    int v = analogRead(SENSOR_PIN_A);
    delay(10);
    }
 
}

void loop() {

  // -----------------------------------------------------------

  D=digitalRead(SENSOR_PIN_D);
  delay(0);
 // Serial.println(D); 
  delay(10);
//-----------------------------------------------------------------------------------------------------------------
   Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0); //calculate resistance on thermistor
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temperature in Kelvin
  T = T - 273.15; //convert Kelvin to Celcius
 // T = (T * 9.0)/ 5.0 + 32.0; //convert Celcius to Farenheit


/*  Serial.print("Temperatur: "); 
  Serial.print(T);
  Serial.println(" C"); */

  delay(10);

      if(T<35 && D==0){
        noTone(9);
        analogWrite(ana11,0);
        analogWrite(ana10,255);
        analogWrite(ana9,0);

        
        mySerial.println("Kein Problem erkannnt!");

        delay(100);
        
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Kein Problem ");
        lcd.setCursor(0,1);
        lcd.print("erkannt!");

       delay(10);
      
      }

     
    
     if(T>35&&T<45 && D==0){
      noTone(9);
      analogWrite(ana11,255);
      analogWrite(ana10,100);
      analogWrite(ana9,0);

      mySerial.println("Erhöhte Warnstufe!");

      delay(100);
    
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Erhöhte ");
      lcd.setCursor(0,1);
      lcd.print("Warnstufe!");

      delay(10);
      
      }
  
  
     if(T>45 || D==1){
      analogWrite(ana11,255);
      analogWrite(ana10,0);
     
      mySerial.println("Hohe Warnstufe!");
      delay(100);
        
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Hohe");
      lcd.setCursor(0,1);
      lcd.print("Warnstufe!");
  
       for(i=550;i<1400;i++){
        tone(9,i);
        delay(2);
       }
       for(i=1400;i>550;i--){
         tone(9,i);
         delay(2);
       }
     delay(10);
     }
}

I see 2 separate text streams, Serial and MySerial.

Serial is set to 9600 baud, a conservative and well supported value.
mySerial is set to 38400 baud, which might be too fast for a BlueTooth chip default rate.

We have no idea how you wired two serial communication streams and where they end up.

Your Ai2 Clock Timer does not show its newly received text anywhere unless it exactly matches one of 3 values.

That's not very helpful for debugging.

Hi, I did some videos about Arduino and App Inventor communication. Maybe, they can help u