Suggestion about project with arduino and Xbee

Hello I have 3 x arduinio UNO , 2 x temeprature sesnor and 3 x Xbee s2C( two endpoint mode and one coordinator). Each xbee are connect to one Arduino. Xbee are in API mode.

Arduino1 --- Xbee(coordinator)

Arduino2 --- Xbee(endpoint)
---- Temperature Sensor

Arduino3 --- Xbee(endpoint)
---- Temperature Sensor
What is my project?

My project consist in get the temperature of one zone and if that temperature pass a threshold, that data is send to Arduino 1 and Arduino 1 do something for X time.

What happen if a data come from Arduino 3 and in that time Arduino 1 is do something because it recevie data from Arduino 2? I want that Arduino can do something(power ON LED ) at same time in X time(for example data from Arduino 2 it make that Arduino 1 power ON LED for 1 minute but data from Arduino 3 it make that Arduino 1 power ON LED for 3 minute).

That escenario will overlap Arduino's 1 tasks

Anybody have a suggestion??

I include arduino 2 code is you need it. Arduino 3 is similar to Arduino2

#include <DHT.h>
#include <Bridge.h>
#include <AltSoftSerial.h>
#include <stdio.h>
//#include <SoftwareSerial.h>
#include <XBee.h>
// Definimos el pin digital donde se conecta el sensor
#define DHTPIN 2
// Dependiendo del tipo de sensor
#define DHTTYPE DHT11

//const int size_buffer=56;
boolean begin_tx=false;
int timeout=3000;
float limite = 28.0;

// Inicializamos el sensor DHT11
DHT dht(DHTPIN, DHTTYPE);
XBee xbee2 = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();

//AltSoftSerial XBee;
AltSoftSerial xBee;
//SoftwareSerial XBee(5, 6);//rx,tx
void setup() {

// Inicializamos comunicación serie
Serial.begin(9600);
xBee.begin(9600);
//XBee.begin(9600);
// Bridge.begin();
//xbee2.setSerial(XBee);

// Comenzamos el sensor DHT
dht.begin();

}

void loop() {

// Esperamos 5 segundos entre medidas

// Leemos la humedad relativa
float h = dht.readHumidity();
// Leemos la temperatura en grados centígrados (por defecto)
float t = dht.readTemperature();
// Leemos la temperatura en grados Fahrenheit
float f = dht.readTemperature(true);

// Comprobamos si ha habido algún error en la lectura
if (isnan(t)) {
Serial.println("Error obteniendo los datos del sensor DHT11");
return;
}

// Calcular el índice de calor en Fahrenheit
float hif = dht.computeHeatIndex(f, h);
// Calcular el índice de calor en grados centígrados
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humedad: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(" %\t");
Serial.print("Índice de calor: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(" \n");

if((t100)<=(limite100)){
String t_string = String(t,2);
xBee.print(t_string+" *C");
}

delay(4000);

}

You have an Arduino multitasking problem rather than an Xbee problem.

For your "Arduino1" you need to remove delay() from the main loop and use the "blink without delay" example
https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay to do multitasking.

ok Interesting, is that applicable for three or more operations at the same time or there are some limitation?

Victors0991:
ok Interesting, is that applicable for three or more operations at the same time or there are some limitation?

You are only limited by the amount of memory. Each timer variable uses 4 bytes of RAM. For 10 timers that's 40 bytes.

o ok ..but this solution cannot be scalable but works with arduino, If I want to do multiple task usingtheread, what kind of device should I need to use?

Hello but if I need to do a task that have 1min or more,tht code not working inmediately becasue currentmillis - past is lower that duration(1min)

Victors0991:
Hello but if I need to do a task that have 1min or more,tht code not working inmediately becasue currentmillis - past is lower that duration(1min)

See Integer Constants - Arduino Reference
"By default, an integer constant is treated as an int with the attendant limitations in values. "

Try declaring the number using the UL suffix

const unsigned long duration = 60000UL;

Thanks for replying. I do nott understand your answer. Can you explain me?
My problem is that arduino is power on and millis() function is 0 so if I have a interval with value 60000(1min), the difference between millis and past_value are lower that interval so condition
Current_millis - past_vslue >= interval is not true until current millis is higher than interval

Perhaps you need

if(currentMillis - previousMillis >= interval){
  previousMillis = currentMillis;
}
else{
  // do something while the timer is still running
}

If this doesn't help then post your question in the Programming questions section. Programming Questions - Arduino Forum
Perhaps some kind person can write the code for you.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.