I have created a small Arduino sensor system which is supposed to send data to the ardutooth app. The device connects and values show up in the serial monitor, but in the app, nothing seems to work. Can anyone tell what's wrong by looking at this code?
//Code made quickly by Maciej Wojciechowski, expect nonoptimal performance. Feel free to edit and improve.
#include <SoftwareSerial.h>
#include "DHT.h"
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int trigPin = 11;
int echoPin = 12;
long duration, cm, inches;
SoftwareSerial BTserial(7, 8); //RX and TX pin
void setup() {
BTserial.begin(9600); //Initializes BT module
Serial.begin(4800); //Initializes Serial monitor, for debug
dht.begin(); //Starts up DHT-11 module
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); //Sets which pin to use for input and output
//LED to make sure everything works
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
delay(2000); //small pause for DHT-11
float t = dht.readTemperature(); //Sets t variable to temperature
float h = dht.readHumidity(); //Sets h variable to humidity
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); //pulses the trigger pin, ensures a clean pulse
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH); //Sets the value of duration to duration between input and output
cm = (duration/2) / 29.1;
inches = (duration/2) / 74;
//Divide by 2 then by a set value found online.
//now we tell the arduino to print values via BT
BTserial.print(t);
BTserial.print(",");
BTserial.print(h);
BTserial.print(",");
BTserial.print(cm);
BTserial.print(",");
BTserial.print(inches);
BTserial.print(";");
Serial.print("\r\n");
Serial.print(t);
Serial.print("*C");
Serial.print("\r\n");
Serial.print(h);
Serial.print("%");
Serial.print("\r\n");
Serial.print(cm);
Serial.print("cm");
Serial.print("\r\n");
Serial.print(inches);
Serial.print("inches");
Serial.print("\r\n");
Serial.print("----------------------");
delay(20);
//LED light
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
}
This is the app: https://play.google.com/store/apps/details?id=com.frederikhauke.ArduTooth
Thanks in advance.