What code to BLYNK on DS18B20 on one wire?

What code to BLYNK on DS18B20 on one wire ?

the Dallas Temperature “TwoPin_DS18B20” example works fine…


//  Basic reading of sensors on a network
/*
//
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
//Chip = DS18B20
// order of discovery
//Roof    ROM = 28 CC C2 E9 3 0 0 63
//Kitchen ROM = 28 61 EB E9 3 0 0 7E
//highTemp ROM = 28 B3 F2 D8 5 0 0 4D


// 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
*
*	30/12/2015	Blynk version v0.3.1
*		Temp Sensor Terminations: 5V, GND, Data	
*		Source						Cable type		Terminations
*		Freetronics				Cat5e					5V Wh/Bl, GND Bn, Data Bl 
*		Core electronics	High Temp 		5V Wh/Or, GND Wh, Data Wh/Bl			Mil-Spec Wire
*		China							Water Resist 	5V , GND , Data -->	Rd, Bk, Yl  	TBD
*
*		NOTE: Starting or Stoping the Serial monitor on the PC will reset the Arduino.
*/

#include <OneWire.h>
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

OneWire  ds(2);  // on pin 10 (a 4.7K resistor is necessary)

char auth[] = "auth"; 	// 30/12/2015

SimpleTimer timer;

float celsius;

void setup(void) {

	delay( 100 );   // allow some time (50 ms) after powerup and sketch start, 
				  // for the Etherten Wiznet W5100 Reset IC to release and come out of reset.
					
  Serial.begin(9600);
	
	Blynk.begin(auth);	// auto ethernet setup, DHCP, defaults: Name: WIZnetFEFEED MAC: DE:ED:BA:FE:FE:ED
	
	while (Blynk.connect() == false) {
    // Wait until connected true
	}

	// Setup timer functions to be called every x milli seconds. Widgets set to PUSH
  timer.setInterval(1000L, sendUptime);		// V5 widget
  
	timer.setInterval(5000L, sendV0Temp);	// History graph 
	timer.setInterval(5000L, sendV1Temp);	// History graph 
	timer.setInterval(5000L, sendV2Temp); // History graph 
	timer.setInterval(5000L, sendV3Temp);	// History graph
  
  Serial.println("Sketch: BlynkTempLogger0");
	
	} // setup

void sendV0Temp()	// V0 function.  Set widget to PUSH
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, celsius);
}
void sendV1Temp()	// V0 function.  Set widget to PUSH
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  int i = 0;
	Blynk.virtualWrite(V1, i);
}

void sendV2Temp()	// V2 function.  Set widget to PUSH
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  int i = 0;
	Blynk.virtualWrite(V2, i);
}

void sendV3Temp()	// V3 function.  Set widget to PUSH
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  int i = 0;
	Blynk.virtualWrite(V3, i);
}

/*0
BLYNK_READ(V4)	// Blynk functions only operate when the phone app is active.
{								// History graph is not updated live.  change time base to update running app screen.
	//int i = 100;
	Blynk.virtualWrite(V4, celsius);	// send value to V0 widget
}
*/

void sendUptime()	// V5 function.  set widget to PUSH
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}


void loop(void) 	// Main loop
{
	Blynk.run();
	timer.run();
	
  byte i;
  byte present = 0; // initialize device present variable
  byte type_s;      // device type
  byte data[12];   // data array
  byte addr[8];   // address array
  //float celsius;
  
  if ( !ds.search(addr)) {  // search finds device 8 Byte ROM address
    Serial.println("No more addresses.");  // no new addresses
    Serial.println();
    ds.reset_search();  // clear state. for next start search from begining
    delay(250); // bus held low period
    return;
  }
  
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);  // print 8 element array ROM address
  }
  // CRC check Byte 7
  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:  // my devices
      Serial.println("  Chip = DS18B20"); // my devices
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();   // one wire reset, device asserts a presence pulse
  ds.select(addr);  // get device address
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(500);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();  // one wire reset, device asserts a presence pulse
  ds.select(addr);       // get device ROM address
  ds.write(0xBE);        // Read Scratchpad of device

  Serial.print("  Data = ");
  Serial.print(present, HEX); // first "1" in print to line
  Serial.print(" ");          // whitespace
  for ( i = 0; i < 9; i++) {  // we need 9 bytes of data that represents the temperature
    data[i] = ds.read();
    Serial.print(data[i], HEX); // print each byte to serial
    Serial.print(" ");        // whitespace
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);  // 
  Serial.println();
// End of setup ??



// Start reading ??
  // 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) {     // mine is 0
    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;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.println(" Deg C");
  Serial.println("  ");
	
} // loop

Here’s another quick one: https://gist.github.com/structure7/13c9cf278843a74e688c0252067ed806

Where to enter the address of the sensor, and how to do so was esp8266 (WEMOS D1 R2)

Do you have just one sensor or more? If you have only one, entering the address is not required.

1 Like

I have more sensors.

1 Like

How to do to degrees Celsius ?

You can just replace the F with C… should be
sensors.getTempC(tempSensor1);

1 Like

Thank you.
Everything works well. :slight_smile:

:tada: Woo hoo! Good to hear!

And did you ever at Eventor BLYNK. E.g. V1 If the temperature is higher than 25 degrees Celsius it gives a signal to pin 2 (D2 - wemos d1) (eg relay with buzzer)

No I haven’t played with any of the eventor stuff yet.