.. Original article at http://text.maze.io/2010/01/28/arduino-1-wire-temperature-sensor-hacking _______ ____________ _______ _\__ /_________ ___ _____ | _ _ \ _ | ____\ _ / | |/ _ \ | / / / / | | | /___/ _ | | / / |___/___/ /___/____|________|___ | |_| |___|_____/ \__/ |___| (c) 2010 Wijnand 'maze' Modderman - http://maze.io/ Arduino 1-Wire Temperature Sensor Hacking ========================================= .. image:: http://i.maze.io/6acbb1fb.jpg :align: left :alt: Arduino Duemilanove :class: figure 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 `_. .. image:: http://i.maze.io/288acf7e.jpg :align: right :alt: DS18S20 :class: figure 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 ... 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"); } .. _Arduino: http://www.arduino.cc/ .. _Duemilanove: http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove .. _DS18S20: http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2815