Search

Recent

Tags

Arduino 1-Wire Temperature Sensor Hacking

Posting not tagged on jan 28, 2010

Arduino Duemilanove

So, I have an Arduino Duemilanove (wtf is wrong with those Arduino people and their board names?) and I decided it was time to get some progress with hacking the Dallas Semiconductor temperature monitors I got from Maxim IC.

DS18S20

The sensors are DS18S20 sensors, 1-Wire temperature monitors. Using them in the Arduino was made easy by Robin James’ OneWire library.

The pinout on the Arduino uses 1 digital pin, ground and +5.5V with a 4.7kΩ pullup resistor.

The schematics are as follows:

       .-------------------.
       o d0             a5 o
       o d1    A D      a4 o
       o d2    R U      a3 o
       o d3    D E      a2 o
       o d4    U M      a1 o
       o d5    I I      a0 o
       o d6    N L         |
       o d7    O A     vin o
       o d8      N     GND o    R1
       o d9      O     GND o    ___
       o d10     V     +5V o---|___|---o
       o d11     E    +3V3 o           |
       o d12         RESET o           |
+------o d13               |           |
|   +--o GND               |           |
|   |  o AREF              |           |
|   |  |                   |           |
|   |  '-------------------'           |
|   +---------------------------+      |
+-------------------------------)------+
                                |      |    ____
                                +------^---|    | IC1
                                |      +---|    |
                                |      |  -|____|
                                |      |    ____
                                +------^---|    | IC2
                                |      +---|    |
                                |      |  -|____|
                                |      |    ____
                                +------^---|    | IC3
                                |      +---|    |
                                |      |  -|____|
                                |      |    ____
                                +------^---|    | IC4
                                       +---|    |
                                          -|____|

As you can see I can stack multiple sensors on the same 1-Wire bus. You can practically stack endless amounts of 1-Wire devices on this bus, as long as the bus can deliver sufficient power.

Some example code:

#include <OneWire.h>
...

void getTemperature(byte *addr) {
  byte present = 0;
  byte data[12];
  int i, hByte, lByte, tRead, tSign, cTemp;

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1); // start conversion, enable parasite power
  delay(1000);       // now we wait!
  present = ds.reset();
  ds.select(addr);
  ds.write(0xEE);    // read scratchpad
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  lByte = data[0];
  hByte = data[1];
  tRead = (hByte << 8) + lByte;
  tSign = (tRead & 0x800);
  if (tSign) { // test MSB
    tRead = (tRead ^ 0xffff) + 1; // 2's comp
  }
  cTemp = (5000 * tRead);
  if (tSign) {
    Serial.print("-");
  }
  Serial.print(cTemp);
  Serial.print("\n");
}

Add to

Post your feedback

You can use this form to leave your feedback. Your insights are always appreciated.

Tools

View document source in text/plain