0

I have an Arduino Uno microprocessor connected with a temperature sensor, I am able to print the temperature on the Serial Monitor successfully.

The idea is, I wanna dump the value of the temperature into a label sitting on MIT app inventor 2 project via Bluetooth. Anybody has an idea how to do that?

What should I add to the following code to be able to send the data via Arduino.

const int dataPin = 8;
int temperature = -1;
int humidity = -1;


void setup() {
 Serial.begin(115200);

}

int readDHT11(){
  uint8_t recvBuffer[5];
  uint8_t cnt = 7;
  uint8_t idx = 0;
  for(int i = 0; i<5; i++){
    recvBuffer[i] = 0;
  }

  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, LOW);
  delay(18);
  digitalWrite(dataPin, HIGH);

  delayMicroseconds(40);
  pinMode(dataPin, INPUT);
  pulseIn(dataPin, HIGH);

  unsigned int timeout = 10000;
  for(int i = 0; i<40; i++){
      timeout = 10000;
      while(digitalRead(dataPin) == LOW){
          if(timeout == 0) return -1;
          timeout--;
      }
  unsigned long t = micros();

  timeout = 10000;
  while(digitalRead(dataPin) == HIGH){
      if(timeout == 0) return -1;
      timeout--;

  }  

  if ((micros() - t) > 40) recvBuffer[idx] |= (1 << cnt);
  if(cnt ==0){
    cnt = 7;
    idx++;
  }else{
    cnt--;
  }



  }

  humidity = recvBuffer[0];
  temperature = recvBuffer[2];
  uint8_t sum = recvBuffer[0] + recvBuffer[2];
  if(recvBuffer[4] != sum) return -2;
return 0;  

}

void loop() {
  int ret = readDHT11();
  if(ret!=0) Serial.println(ret);
  Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %\t");

  Serial.print("Temperature: "); Serial.print(temperature); Serial.print(" C\n");

  delay(500);
}

Thanks!!

1

1 Answer 1

1

Take a look here. This tutorial was really helpful for me when I was a beginner. Hope that it will helps you too!

Good luck.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.