Reading Temp sensors

Hi All
Yes another beehive monitor.
I'm working through my project in line with my skill level and as I learn new things I will add to the project.
Currently I have 2 DS18B20 sensors reading the "Brood" and "Super" temperature and a DHT22 reading the roof temp and humidity.
It appears in my code that the Brood box is being read, then the DHT22 doing the roof temp and humidity, then the Super is being read, then the DHT22 again. See the serial monitor pic below.

I have searched around and been able to get the code working after a few months of slow learning. I have joined, changed and learnt code so pretty happy with my progress so far.But I cant figure this little one out so your help is appreciated.

[code]
#include <OneWire.h>
#include <DallasTemperature.h>
#include <dht.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
dht DHT; // Creats a DHT object

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Addresses of 3 DS18B20s
uint8_t sensor1[8] = { 0x28, 0x6A, 0x48, 0x7C, 0x0C, 0x00, 0x00, 0xC4 };
uint8_t sensor2[8] = { 0x28, 0xFA, 0x14, 0x7B, 0x0C, 0x00, 0x00, 0x47 };
//uint8_t sensor3[8] = { 0x28, 0x61, 0x64, 0x12, 0x3F, 0xFD, 0x80, 0xC6 };

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{
  sensors.requestTemperatures();
  
  Serial.print("Brood Box: ");
  printTemperature(sensor1);
  
  Serial.print("Flow Super: ");
  printTemperature(sensor2);
  
  //Serial.print("Sensor 3: ");
 // printTemperature(sensor3);
  
  Serial.println();
  delay(1000);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
  Serial.write(0xC2);
  Serial.write(0xBA);
  Serial.print("C    ");
  //Serial.print(DallasTemperature::toFahrenheit(tempC));
  //Serial.print((char)176);
  //Serial.println("F");

  //Uncomment whatever type you're using!
  int readData = DHT.read22(dataPin); // DHT22/AM2302
  //int readData = DHT.read11(dataPin); // DHT11

  float t = DHT.temperature; // Gets the values of the temperature
  float h = DHT.humidity; // Gets the values of the humidity

  // Printing the results on the serial monitor
  Serial.print("Temperature Roof Cavity = ");
  Serial.print(t);
  Serial.print(" ");
  Serial.write(0xC2);
  Serial.write(0xBA);//Serial.print((char)176);//shows degrees character
  Serial.print("C  ");
  //Serial.print((t * 9.0) / 5.0 + 32.0);//print the temperature in Fahrenheit
  //Serial.print(" ");
  //Serial.print((char)176);//shows degrees character
  //Serial.println("F ");
  Serial.print("Humidity Roof Cavity = ");
  Serial.print(h);
  Serial.println(" % ");
  Serial.println("");

 // delay(1000); // Delays 10 seconds

}

[/code]

It appears in my code that the Brood box is being read, then the DHT22 doing the roof temp and humidity, then the Super is being read, then the DHT22 again.

What do you want it to do ?

See the serial monitor pic below.

It would be easier to do if you selected teh text, copied it to the clipboard and posted it here in code tags

I'll guess that you don't want the roof cavity data every time you measure one of the other sensors.

If that's the case, move the code that reads and prints that data out of printTemperature into a function of its own and call it from loop.

wildbill:
I'll guess that you don't want the roof cavity data every time you measure one of the other sensors.

That's correct. I'd like it to read Brood box, Flow super then roof temp and humidity.
Ill try changing the code and see how I go.

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