Author Topic: Aquarium temp sensor  (Read 9076 times)

plexer

  • Newbie
  • *
  • Posts: 38
Aquarium temp sensor
« on: October 10, 2015, 08:31:01 am »
So I've put together some code using a waterproof ds18b20 sensor and the digiled for feedback.

If the temp is above my setpoint it goes red, below it goes blue and normal it's green.

Code is below the weird thing is that it works perfectly if plugged in to my laptop for power but if I plug it in to an anker 5 port usb charger it only displays blue any idea why that may be?

Thanks.

Ben

Code: [Select]
// Based on NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license
#include <Adafruit_NeoPixel.h>
#include <OneWire.h>
#include <DallasTemperature.h>
 
// Which pin on the Digispark is connected to the DigiLED?
#define PIN 5
 
// How many DigiLEDs are attached to the Digispark?
#define NUMPIXELS 1

// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// For the WS2812B type through hole LED used by the DigiLED,  NEO_RGB + NEO_KHZ800 is the correct data format
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
 
int delayval = 10000; // delay for 10 seconds

//float

int temp_setpoint = 26; // ideal temperature is this
 
void setup()
{     
  // Start up the library
  sensors.begin();
  pixels.begin(); // This initializes the NeoPixel library.
  pixels.show(); // Initialize all pixels to 'off'
}
 
void loop()
{

  //read temperature from 1 wire device
 sensors.requestTemperatures();
 //float
 int read_temp = sensors.getTempCByIndex(0);
 
if (read_temp < (temp_setpoint - 2)) //if temp is less than 25 make led blue
{
  // blue
  //Serial.print("Blue");
  pixels.setPixelColor(0, pixels.Color(0, 0, 255)); //blue
  pixels.show();
  delay(delayval);

}
else if (read_temp > (temp_setpoint + 2)) //if temp is higher than 27 make led red
{
  // red
  //Serial.print("Red");
  pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //red
  pixels.show();
  delay(delayval);
}
else //temp is ok so make it green
{
  // green
  //Serial.print("Green");
  pixels.setPixelColor(0, pixels.Color(0, 255, 0)); //green
  pixels.show();
  delay(delayval);
}
 
 }

robmack

  • Newbie
  • *
  • Posts: 13
Re: Aquarium temp sensor
« Reply #1 on: October 10, 2015, 04:43:13 pm »
Is the ds18b20 receiving Vdd from the power supply(3-wire connection), or are you relying on the parasitic capabilities of the device for power (2-wire connection)?

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #2 on: October 11, 2015, 02:14:33 am »
It's using parasitic.

Ben

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #3 on: October 11, 2015, 02:20:06 am »
Just converted it to 3 wire but same result it's just weird.

Ben

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #4 on: October 11, 2015, 03:35:42 am »
Plugged in to a mobile phone charger it always stays blue.

Plugged in to the laptop it goes green, red if I warm the sensor and blue if I cool it which is the expected behaviour.

I have the 1 wire sensor data line connected to pin12 on the pro, I am using a free gnd connection once the digiled shield is inserted and I'm pulling vcc from the pro.

Ben

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #5 on: October 11, 2015, 03:55:45 am »
Which is why it's not working because the pin I'm using to power it only supplys 5v when powered by usb or vin :)

Let me go check.

Ben

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #6 on: October 11, 2015, 03:59:41 am »
Or not as it's being powered by usb.

Doh!

robmack

  • Newbie
  • *
  • Posts: 13
Re: Aquarium temp sensor
« Reply #7 on: October 11, 2015, 06:26:41 am »
Have you read this page:  https://developer.mbed.org/users/snatch59/notebook/onewirecrc/

Seems you might need to fool with the pull-up on the data line. Maybe set the pin to use the internal pullup or provision your circuit with an external pullup.
« Last Edit: October 11, 2015, 06:36:10 am by robmack »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Aquarium temp sensor
« Reply #8 on: October 11, 2015, 07:30:22 am »
Would definitely look at using an external pull up resistor. I've experienced read errors when the pull up was too high a value. Been using about 2k.

plexer

  • Newbie
  • *
  • Posts: 38
Re: Aquarium temp sensor
« Reply #9 on: October 11, 2015, 10:30:50 am »
Thinking further on this it could be the value of the resistor that I'm using it's just some I had laying around and is not even 4.7k.

Ben

digi_guy

  • Jr. Member
  • **
  • Posts: 87
Re: Aquarium temp sensor
« Reply #10 on: October 14, 2015, 09:03:29 pm »
Hey plexer, when you get this working can you report back? I'm working on some similar projects and it would be nice to see what you come up with.