hi everyone... i'm new at app inventor, but i was able to do an app that can on-off what i want, but what i want to do now it's an app that show me the data from a DHT11 . .. this is what i do, but it shows me nothing on lines "temperatura...., humedad.... & Nivel agua"
ARDUINO CODE:
#include <Wire.h> // incluye libreria para interfaz I2C
#include <DHT.h> // importa la Librerias DHT
#include <DHT_U.h>
#include <SoftwareSerial.h> // libreria que permite establecer pines digitales
// Definimos el pin digital donde se conecta el sensor DHT TEMPERATURA HUMEDAD
#define DHTPIN 2
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11
SoftwareSerial miBT(11, 12); // pin 11 como RX, pin 12 como TX
int TRIG = 10; //DISTANCIA ULTRASONIDO
int ECHO = 9;
int DURACION;
int DISTANCIA;
/// BLUETOOTH
char DATO = 0; // variable para almacenar caracter recibido
///DHT11
int TEMPERATURA;
int HUMEDAD;
DHT dht(DHTPIN, DHTTYPE); // creacion del objeto, cambiar segundo parametro // por DHT11 si se utiliza en lugar del DHT22
///fin DHT22
void setup(){
//bluetooth
miBT.begin(38400); // comunicacion serie entre Arduino y el modulo a 38400 bps
// INICIAR DHT
dht.begin(); // inicializacion de sensor
//DISTANCIA ULTRASONIDO
pinMode (TRIG, OUTPUT);
pinMode (ECHO, INPUT);
Serial.begin(9600);
}
void loop(){
//DISTANCIA ULTRASONIDO
digitalWrite(TRIG, HIGH);
delay(1);
digitalWrite(TRIG, LOW);
DURACION = pulseIn(ECHO, HIGH);
DISTANCIA = DURACION / 5.82;
//BLUETOOTH
if (miBT.available()){ // si hay informacion disponible desde modulo
DATO = miBT.read(); // almacena en DATO el caracter recibido desde modulo
TEMPERATURA = dht.readTemperature(); // obtencion de valor de temperatura
HUMEDAD = dht.readHumidity(); // obtencion de valor de humedad
Serial.println(TEMPERATURA);
Serial.println("|");
Serial.println(HUMEDAD);
Serial.println("|");
Serial.println(DISTANCIA);
Serial.println("|");
}
delay(1000);
}
Here is the standard advice for multiple values on a line in BlueTooth text ...
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.
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.
In your case,
use print() everywhere except at the last value per line, where you need println() to end the line
thanks, but NOPE... i do eveything u say but it's the same.. don't send any data
NOW, when i open the app and select the bluetooth, it shows:
"----Select list item: List index too large
Select list item: Attempt to get item number 2 of a list of length 1: [""] -----"
ARDUINO CODE:
#include <Wire.h> // incluye libreria para interfaz I2C
#include <DHT.h> // importa la Librerias DHT
#include <DHT_U.h>
#include <SoftwareSerial.h> // libreria que permite establecer pines digitales
// Definimos el pin digital donde se conecta el sensor DHT TEMPERATURA HUMEDAD
#define DHTPIN 2
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11
SoftwareSerial miBT(11, 12); // pin 11 como RX, pin 12 como TX
///DHT11
int SENSOR = 2; // pin DATA de DHT22 a pin digital 2
int TEMPERATURA;
int HUMEDAD;
DHT dht(DHTPIN, DHTTYPE); // creacion del objeto, cambiar segundo parametro // por DHT11 si se utiliza en lugar del DHT22
///fin DHT22
void setup(){
//bluetooth
miBT.begin(9600); // comunicacion serie entre Arduino y el modulo a 38400 bps
// INICIAR DHT
dht.begin(); // inicializacion de sensor
Serial.begin(9600);
}
void loop(){
//BLUETOOTH
if (miBT.available()){ // si hay informacion disponible desde modulo
}
//loop DHT
TEMPERATURA = dht.readTemperature(); // obtencion de valor de temperatura
HUMEDAD = dht.readHumidity(); // obtencion de valor de humedad
Serial.print(TEMPERATURA);
Serial.print("|");
Serial.print(HUMEDAD);
Serial.println("|");
delay(1000);
}
first of all, thanky U for your time and patience, but it's my first time building an app for arduino, and working with blocks codes and app inventor.... this is what i change.. and everythings work.. except the variables
thanks @Juan_Antonio ... i'm thinking it's the cellphone... i made EXACTLY as the sample U send me and it's ok when i select bluettoth... but when i press "Check temperature" it freezing and the cell send me a message that the app it's not responding.. and it close....
@Juan_Antonio on my original project??... 2000... i change it to 500 but nothing happend... and also separate values by comma, instead of | ... but nothing
In example "5.- App requests temperature and humidity to the Arduino. The Arduino sends values" I didn't use Clock.
Try example. 7.- App gets the value of two potentiometers. but...
Do not use potentiometers.
This code
int value_pot0;
int value_pot1;
String value;
void setup() {
Serial.begin(9600);
}
void loop() {
value_pot0 = random(0,1023);
value_pot1 = random(0,1023);
value = (String) value_pot0 + "," + (String) value_pot1;
Serial.println(value);
delay(200); // It should be slower than the Clock Interval.
}
thanks again @Juan_Antonio and i know , in fact, i copy everything in your sample.... the code... the fisical mount of arduino ... and the app---- but it dosn't work.... thats why i'm thinking it's my smartphone...
Location permission allowed?... yes...
i surrender... i made all the samples but noeone send me any data.... but everythings work.. i can turn on / off everything i want... i can read the data on the monitor and screen of arduino... THE ONLY thing i can't do.. it's recive the data on the app-----
I better hire a professional... this is beyond me
THANKS TO ALL FOR YOUR TIME AND HELP-----
Dear David (@David_Vyhmeister ),
but is your Arduino code the one you posted in your first message ?
If so, please be aware that it's not sending anything on the BT line.
In your code you use the:
Serial.println(TEMPERATURA);
Serial.println("|");
......
and so on, but the Serial.print() just sends to the PC monitor.
To send to the BT line you shall send data by using the miBT serial line instead.
In this way
miBT.print(TEMPERATURA);
miBT.print("|");
.......
'till the last sending, in which you shall use the miBT.println("|") to close the frame.
(i.e. just print for the values and the delimiters, and println for the the last one).
Also by reading your Arduino code: why are you waiting characters from the BT to allow reading the sensors? This means that your AI2 code is triggering the readings ? In my understanding the aim of your application is to send sensors' data from the Arduino board to the phone. In this case you don't have to wait nothing from the phone and just to send out every second (your delay(1000)) the acquired values. Something like:
void loop()
{
//DISTANCIA ULTRASONIDO
digitalWrite(TRIG, HIGH);
delay(1);
digitalWrite(TRIG, LOW);
DURACION = pulseIn(ECHO, HIGH);
DISTANCIA = DURACION / 5.82;
TEMPERATURA = dht.readTemperature(); // obtencion de valor de temperatura
HUMEDAD = dht.readHumidity(); // obtencion de valor de humedad
Serial.print("TEMPERATURA: "); // value to the PC monitor
Serial.println(TEMPERATURA); // each value on a new line (only on PC monitor)
miBT(TEMPERATURA); // value to the BT
miBT.print("|"); // data separator to the BT
Serial.print("HUMEDAD: "); // value to the PC monitor
Serial.println(HUMEDAD);
miBT.print(HUMEDAD); // value to the BT
miBT.print("|"); // data separator
Serial.print("DISTANCIA :"); // value to the PC monitor
Serial.println(DISTANCIA);
miBT.print(DISTANCIA); // value to the BT
miBT.println("|"); // close the BT frame
delay(1000);
} // end loop