Author Topic: Using DS18B20 or DS18S20 with Moteino  (Read 11440 times)

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Using DS18B20 or DS18S20 with Moteino
« on: December 06, 2013, 02:02:23 AM »
     Wanted to run this by everyone before I dove in.  I want to use a moteino as a node for taking temperature readings throughout a greenhouse I am building.  Perhaps three or four separate sensors in use.  I wanted to run this from battery power, and so don't want to directly connect the DS18B20s or DS18S20s to my power source creating a constant parasitic drain.  Is there any reason I can't use a digital pin, for example D14 or D15, in place of Vcc for the source to my weak pull up resistor?  I was thinking of running a 4.7kohm resistor between D15 and D14.  Use D14 as my data line, and D15 as my Vcc for Temperature sensor.  I've been reading up on these sensors, and everything I find is with them wired to a 5volts source.  I don't have much else going on thus far with the temperature gathering node.  I was going to use a separate digital I/o pin to power each of the temperature sensors, so that only when reading from that sensor would I be providing power to it.    Any insight when using a 3.3volt source?  Will the 4.7kohm pull-up resistor do the job?    Thanks, Marcello 

*******************************************************************************
3.3v from Moteino D15  -----.----------------------- VCC on DS18B20
                   |
                   X (4,7kOhm)
                   |
Data I/O Moteino D14 -----.----------------------- Data on DS18B20

Ground on Moteino  ----------------------------- Ground on DS18B20
******************************************************************************

     I've got a gateway and two nodes all talking together well.  The gateway connected to a Raspberry Pi ready to log everything.  I just really don't want to damage any of these Moteinos before I actually get to seeing them doing the job I'd intended for them. 

Spexx

  • NewMember
  • *
  • Posts: 30
  • Country: de
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #1 on: December 06, 2013, 03:12:45 AM »
This is no problem, you can connect the Vcc from the sensor directly to a digital output of the Moteino. For power saving, you can set the Vcc output to low and only activate it before reading the temperature with a delay of approx 10ms.

On my tests the DS18B20 works fine with voltages below 3V, with 3.3V and a 4.7kOhm resistor there shouldn't be any problems.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #2 on: December 06, 2013, 08:36:18 AM »
Spexx put it well so I won't repeat. The 4.7K can be a 10K though, more common value, or pretty much any kiloohm resistor you got around. The lower the value the higher the quiescent current, so if you're on a battery you might want a higher value to keep that low. Better yet you might use a digital pin to power the DS like Spexx I think mentioned. Say on D4 ... connect the Vcc of the sensor to D4, turn D4 HIGH and delay a little bit, then read sensor and then turn D4 back off.

The dallas sensor requires a long delay while reading though .. so not ideal to use on battery... but if you're clever and sleep the AVR and don't need measurements every second you might be OK.

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #3 on: December 06, 2013, 10:23:00 AM »
Thank you both for the replies. 

You've both answered all my questions.  Spexx - thanks for the timing tip after waking up the sensor.   

And yes I will be putting it all to sleep the majority of the time.  That was why I was making sure I could drive the sensor from the micro.  I'll give the 10k a try. 

I was going to use the Narcoleptic library to put everything to sleep. I was going to shoot for an updated temperature every 5 minutes.  Down the road I'm guessing I'll have a couple solar panels and some 12 volt batteries, but for now conserving power is paramount. 

Now I've got to figure out how to warm a 300 gallon tank of water for my aquaponics system and the Tilipia I was going to try and grow without breaking the bank.  Working on solar heating ideas but it is still very much a work in my mind. 


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #4 on: December 06, 2013, 12:20:26 PM »
Reading temp at 5 minutes will really keep current consumption down.

Sounds like a great project! I only wish I had the time to make some aquaponics.
Any chance to make a writeup and post it in the projects forum? Some other articles about the coffee maker and kitchen scale by another user got picked up on hackaday and many other sites ;)

KanyonKris

  • Full Member
  • ***
  • Posts: 113
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #5 on: December 06, 2013, 04:57:03 PM »
Would a 20k pull-up work? Taking a quick look at the datasheet I don't see why not. If so you can use the 20k internal pull-up of the ATmega on the Moteino and thus not need any additional components. Here’s how to enable the internal pull up:

pinMode(4, INPUT); // set pin 4 to input
digitalWrite(4, HIGH); // turn on pull-up resistor

More info here – http://arduino.cc/en/Tutorial/DigitalPins

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #6 on: December 07, 2013, 11:14:39 AM »
     KanyonKris - that would be really cool if I could use that insight to minimize components.  I will give it a try and see if there is enough current to drive the temperature sensor.  I've got tomorrow free to get the temperature sensor up and running. 

     I'll take some pictures while I work on this one, and will try and write something up as I go along.

     I work in automotive, and was just asked for a device to put under the hood which could remotely read, and log temperatures.  A friend works on a lot of modified cars where they are fitted with newer fuel injection systems.  It is always amazing to see how little thought is giving to the positioning of air intake.  He would like to be able to show people quickly why things aren't working right due to excessive temperatures in the intake air.  They are always more interested in cosmetics than function.   

tve

  • NewMember
  • *
  • Posts: 14
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #7 on: December 17, 2013, 03:07:56 AM »
FYI, if you have a choice I'd always opt for the DS18B20 over the DS18S20. The B version has 12 bits accuracy vs. 9-bits (0.5 degrees C) for the S and does a 9-bit conversion in 94ms vs. 750ms. You can get 10-bits resolution in 190ms, which is the sweet spot for me. I use the parasitic power version so I only need to run two wires to the sensors (a pair of cat5 wires works great). Note also that you can make all sensors on a wire acquire the reading at the same time and then read them one-by-one, so it's not N times 190ms.

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #8 on: December 17, 2013, 11:36:08 AM »
     I've got the ds18s20 working flawlessly using two pins on the micro and ground.  I wasn't able to get it to working using the internal 20k pull-up resistor.  I am running a 4.7k resistor between the power feed pin and the data pin.  It is working from 3.3 volt source pin.  So no connection needed directly to power for the sensor.  Everything can be shut down easily.  My first Node is in the backyard providing sensor data every 5 minutes to the base station in the form of ascii text for now. 
     I will be switching to the ds18b20s as soon as they arrive.  I got a bunch from amazon that were submersible.  At least I think they are submersible.  We'll see.  I am working on an aquaponics project so this will be important soon.  I'll be happy if they are withing a couple degrees of accuracy.  There will be on Dht22  in the mix as well.  I will get some pictures, and code up for anyone interested.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #9 on: December 17, 2013, 12:31:43 PM »
Awesome, can't wait. Please link pictures if possible, rather than embedding them in the forum, or send them to me directly and I'll post them in my Flickr Moteino-projects set: http://www.flickr.com/photos/15304611@N03/sets/72157637196933564/

If you have a flickr account it's very easy to grab the BB code for sharing a picture and just post it in here.

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #10 on: December 18, 2013, 03:33:13 PM »
     Got my DS18b20s in the mail today way ahead of schedule.  According to Amazon I wasn't going to receive them until next year unless I paid for faster shipping.  I knew they were trying to juice me.  Anyway, will get these in the loop.  Get some pictures on Sunday and start uploading everything.  I will put pictures to flickr and embed the links as suggested.  Just moved to codebender to write my code.  This is really cool.  I have three copies of everything on three different computers which has been a real hassle.  Now I just start up a web app and I'm good to go.  All my code is online.  Haven't looked into what it will take to share that code, but I have a feeling it will be easy.

damonb

  • NewMember
  • *
  • Posts: 26
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #11 on: December 18, 2013, 10:44:27 PM »
guys, IMHO you are chasing diminishing returns powering a DS18B20 from a DIO pin.
Data sheet says DS18B20 stand-by current is 1μA max, 750nA typical. The leakage current on a ATmega328P DIO pin can be up to 1μA, and the chip itself draws at least 4.5μA in sleep mode.
I have several temperature measuring nodes on my JeeNode network (http://jeelabs.net/projects/cafe/wiki/ - JeeNode is similar to Moteino). Once per minute they each sample temperature and their own battery voltage, and send the data to the monitoring station via the RFM12B. They are powered by a single AA alkaline cell via a 3.3V booster (http://jeelabs.net/projects/hardware/wiki/AA_Power_board), so current draw from the AA is about 2.5x the current that the DS18B20, μC and radio chip draw directly from 3.3V. The DS18B20 is connected directly to the 3.3V rail and uses a 4k7 pull-up on the data line connected to the DIO pin. In other words, no special power conservation measures.
One of these nodes was installed with a partly spent AA that was reading 1.2V when put into service. After running continuously for 15 months it is still going (cell voltage is now down to 0.9V). The nodes that started 15 months ago with a full AA cell are now reading about 1.3V.
So even with 4 DS18B20s attached, you should get >1year battery life as long as the μC is programmed carefully. For example, be sure to put the μC back to sleep while it waits the 750ms needed for the DS18B20s to do their 12-bit conversion, and make sure the DS18B20s all convert at the same time to minimise the number of times the μC has to wake-up.
« Last Edit: December 18, 2013, 10:59:15 PM by damonb »

hexibot43

  • Jr. Member
  • **
  • Posts: 78
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #12 on: December 18, 2013, 11:53:54 PM »
Damonb
     Thanks for your insight.  I am more than getting the idea.  Doesn't seem like it is worth the effort to be so power conservative.  My daily job as a mechanic has me using all kinds of battery operated tools that drive me crazy trying to keep the batteries all charged.  Batteries and there ability to die at the most inopportune moment has much influenced my thinking.  And yet, yesterday while cleaning up I found an old project I had made to switch between eproms images for a Honda computer.  It was a simple pic chip based device that had a simple 16x2 screen, and two buttons .  It shutdown waiting for a key input.  It has to have been at least a year since it was last used.  I pressed one of the buttons and it immediately came to life.  Surprise the hell the me.  The battery was still good.  I'm going to just drive the ds18b20s via the 3.3v regulated power from the moteino.  I will follow the path of simplicity.  My code just got that much simpler.  Thanks,  Mab     

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #13 on: December 19, 2013, 07:12:27 AM »
Damon, You said you had it all figured out how to sleep the uC while doing the A/D conversion and everything else. Any chance you could share some of that code for those that are looking to use the DS18X20 sensors?

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Using DS18B20 or DS18S20 with Moteino
« Reply #14 on: December 19, 2013, 07:42:21 AM »
I second the request.

A temperature sampler and logger is high on my list.