1-wire not working correctly in parasite mode

I've got 2 ds1820 sensors (not b or s). Problem is when using parasitic mode. I got a cronjob that reads sensors every minute and its quite random when it gives right values or -127.00 and 85.00 for sensors.
When using arduino ide's serial monitor and opening and closing it multiple times it randomly works fine but most of the time it says that 0 sensors were detected and parasitic mode is OFF. When it works it says 2 sensors found and parasitic mode is ON

I got them connected 1 and 3 pin grounded and pin2 to arduino and 4.6k resistor as pull-up

But when using +5v in pin 3 it all works fine. So how to make parasitic mode work properly?

If someone knows how to make subdomain work with arduinos IP. Arduino is working with IP over internet but not with subdomain assigned to that IP.

What does the sketch look like?

#include <Ethernet.h>
#include <Server.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>

#define DHTPIN 3     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,100, 150 };
Server server(80);

// anturin data-jalka
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

int anturit = sensors.getDeviceCount();


// LDR
const int ldrPin = A0;
int ldr = 0;


// SETUP ---------------------------------------------
void setup() {                                
  
Ethernet.begin(mac, ip);
server.begin();
  
  Serial.begin(9600);                         

sensors.begin();  //1-wire

/* 
// DEBUG
  //parasite?
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

    // monta anturia löydetään  
    Serial.print(sensors.getDeviceCount(), DEC);
// DEBUG
*/

dht.begin();

delay(1000);
}                                             
//SETUP -----------------------------------------------

void loop() {
ldr = analogRead(ldrPin);

int h = dht.readHumidity();
int t = dht.readTemperature();


// call sensors.requestTemperatures() to issue a global temperature 
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
float anturi1 = sensors.getTempCByIndex(0);
float anturi2 = sensors.getTempCByIndex(1);


// print to usb
Serial.print(anturi1);
Serial.print("\n");
Serial.print(anturi2);
Serial.print("\n");
Serial.print(ldr);
Serial.print("\n");
//dht
    Serial.print(h);
    Serial.print("\n");
    Serial.print(t);
    Serial.print("\n");
 
//----------- ETHERNET ---------------------------

  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
client.println("<HTML>");
client.println("<HEAD>");
   client.println("<TITLE>Arduino webbaservero!</TITLE>");
client.println("</HEAD>");
          client.println("<BODY>");
            client.print("anturitietoja!");
            client.println("
");
            client.print(anturi1);
            client.print("c    ");
            client.print(anturi2);
            client.print("c");
            client.println("
");
            client.println("
");
            client.println("
");
            client.print("kosteus: ");
            client.print(h);
            client.print("%");
            client.print("  lampotila: ");
            client.print(t);
            client.print("c");
client.println("
");
client.println("
");
            client.print("valoisuus 1-1000:   ");
            client.print(ldr);
            
client.println("
");
client.println("
");
client.println("
");
            client.println("<img src='http://heller.huono.org/servduino.jpg'>");

          break; 
        }
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
       else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
}

//vika
}

Which version of the DallasTemperature library? Even the most recent version doesn't include DS1820 as a supported device type - but perhaps it has the same device ID as one of the supported chips?

I have no clue about ds1820 vs ds18b20. I ordered few ds18b20 so ill post updates after i get them.

The datasheets will say what the device ID byte is for each sort - have a look to see which devices have what values and look in your library sources to see which are supported...?

Ensure you are using the following library;

http://www.pjrc.com/teensy/td_libs_OneWire.html

I have a project using the DS18B20 and this library works perfectly.

From your code, it seems that you are not using this library so that could be the cause of your problems. The library posted above is the recommended version from the arduino website.

Cheers,
dan.

How does that lib differ? I now got it working! I added 100uF electrolytic capacitor between gnd and +5V and it seems to work just fine :open_mouth:

I know its an old thread, but still quite prominent in search results, so in case someone else comes here with the same problem.

The datasheet http://datasheets.maxim-ic.com/en/ds/DS18B20.pdf says clearly

"When the DS18B20 is used in parasite power mode, the VDD pin must be connected to ground".

If you leave the power pin (Vdd) unconnected when using parasitic power mode you will get unreliable operation: sometimes the correct reading and sometimes 85.5

Once connected properly I had good results from the sketch at Arduino 1-Wire Tutorial

It is connected to GND.