I have about six ds18b20, assigned with six Virtual ports. when a gauge is added it rolls through all the six temps even if only one virtual port is chosen on the app. I wanted to have a reading for each one but it reads all of them.
#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h> // This part is for Ethernet stuff
#include <OneWire.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
OneWire ds(2); // on pin 7 (a 4.7K resistor is necessary) make sure you change this from the original pin 10 to an unused pin.
int adr;
float s1;
float s2;
float s3;
float s4;
float s5;
float s6;
float s7;
char auth[] = "8ad631f3a1f145679ca588a566bd3ab1"; // Put your Auth Token here. (see Step 3 above)
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
// Serial.print("ROM =");
for( i = 0; i < 8; i++) { //we need to drop 8 bytes of data
}
adr = (addr[7]);
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes to drop off
data[i] = ds.read();
}
Serial.println();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
if(adr == 0x28, 0xFF, 0xF0, 0x3C, 0x2E, 0x04, 0x00, 0xEF) { //replace ??? with value of sensor number 1
s1 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 0x28, 0xFF, 0x68, 0x3F, 0x2E, 0x04, 0x00, 0xEE) { //replace ??? with value of sensor number 2
s2 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 0x28, 0xFF, 0x64, 0x3F, 0x2E, 0x04, 0x00, 0xCF) { //replace ??? with value of sensor number 3
s3 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 0x28, 0xFF, 0x7C, 0x81, 0x2D, 0x04, 0x00, 0xED) { //replace ??? with value of sensor number 4
s4 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 0x28, 0xFF, 0xC9, 0x72, 0x3B, 0x04, 0x00, 0x12) { //replace ??? with value of sensor number 5
s5 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
if(adr == 0x28, 0xFF, 0x75, 0x3F, 0x2E, 0x04, 0x00, 0x7E) { //replace ??? with value of sensor number 6
s6 = fahrenheit; //change celsius to fahrenheit if you prefer output in Fahrenheit
}
Serial.print(" Sensor 1 = ");
Serial.print(s1);
Serial.print(" Sensor 2 = ");
Serial.print(s2);
Serial.print(" Sensor 3 = ");
Serial.print(s3);
Serial.print(" Sensor 4 = ");
Serial.print(s4);
Serial.print(" Sensor 5 = ");
Serial.print(s5);
Serial.print(" Sensor 6 = ");
Serial.print(s6);
Blynk.virtualWrite(V5, s1);
Blynk.virtualWrite(V6, s2);
Blynk.virtualWrite(V7, s3);
Blynk.virtualWrite(V8, s4);
Blynk.virtualWrite(V9, s5);
Blynk.virtualWrite(V10, s6);
}