I have a FLORA connected successfully to a DS1820B waterproof temperature sensor. I can run the Dallas Temperature test code (see http://milesburton.com/Dallas_Temperatu ... ol_Library) and it detects temperature just fine.
My goal is to store the temperature detected by the sensor into a variable and then develop a switch case around it.
I am having trouble coding the "storing" part. The library has a command getTempF and I want to use that. How do I call that command and then cause it to store the value detected (in F) into a variable I can later use in my switch case?
Thanks!
Chris Craft
Educator
Columbia, SC
DS1820B value stored as a variable?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: DS1820B value stored as a variable?
Code: Select all
// returns temperature in degrees F
float getTempF(uint8_t*);
Code: Select all
float temperatureF = getTempF(address); // address
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Thanks for your quick reply.
We are creating a dog collar that "reads" the temperature of the dog (through the temp sensor near the skin) and lights up a neopixel that corresponds with the temp. We've sewn on blue (cool), white (less cool), rose pink (warm) and red (dangerous).
Our intent is to have it used on police K9's to keep them safe in summer. It's hot here in SC and each year a K9 or two dies due to overheating.
Just for fun, I've added a picture in case you're curious. It's a proof of concept (or MVP) right now, but it's a neat project the kids are working on.
I couldn't attach the picture (said it was invalid) so here's a link to it https://www.dropbox.com/s/32q7pqls7cvwg ... 7.jpg?dl=0.
Chris
We are creating a dog collar that "reads" the temperature of the dog (through the temp sensor near the skin) and lights up a neopixel that corresponds with the temp. We've sewn on blue (cool), white (less cool), rose pink (warm) and red (dangerous).
Our intent is to have it used on police K9's to keep them safe in summer. It's hot here in SC and each year a K9 or two dies due to overheating.
Just for fun, I've added a picture in case you're curious. It's a proof of concept (or MVP) right now, but it's a neat project the kids are working on.
I couldn't attach the picture (said it was invalid) so here's a link to it https://www.dropbox.com/s/32q7pqls7cvwg ... 7.jpg?dl=0.
Chris
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: DS1820B value stored as a variable?
Nice project!
To test for temperature ranges, use an if/else structure something like this:
To test for temperature ranges, use an if/else structure something like this:
Code: Select all
if (temperature > 100)
{
// set led to red
}
else if (temperature > 90)
{
// set led pink
}
else if (temperature > 80)
{
// set led white
}
else
{
// set led blue
}
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1820B value stored as a variable?
Chris, just some thoughts. If you are using "neopixels" they will show all colors in one pixel, you don't need individual pixels. instead of using the waterproof ds18b20 and it's bulk you could use the chip itself and then waterproof the entire package somehow.
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Thanks, those are great thoughts. I'm a novice at this, so this helps a bunch.
Turns out I accidentally lied, I'm using LED Sequins for this, not NeoPixels. Oops!
Turns out I accidentally lied, I'm using LED Sequins for this, not NeoPixels. Oops!
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1820B value stored as a variable?
I saw that in the picture. There are these to consider https://www.adafruit.com/product/1260
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Would anyone be willing to review my code? It doesn't work yet, but I think I'm close. Thanks for the help!!
Code: Select all
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
int temperature;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int redled = 12;
int blueled = 6;
int whiteled = 9;
int pinkled = 10;
void setup(void)
{
Serial.begin(9600);
sensors.begin();
float getTempF(uint8_t*);
pinMode(redled, OUTPUT);
pinMode(blueled, OUTPUT);
pinMode(whiteled, OUTPUT);
pinMode(pinkled, OUTPUT);
}
void loop(void)
{
if (temperature > 100)
{
digitalWrite(redled, HIGH);
delay(2000);
digitalWrite(redled, LOW);
}
else if (temperature > 90)
{
digitalWrite(pinkled, HIGH);
delay(2000);
digitalWrite(pinkled, LOW);
}
else if (temperature > 80)
{
digitalWrite(whiteled, HIGH);
delay(2000);
digitalWrite(whiteled, LOW);
}
else
{
digitalWrite(blueled, HIGH);
delay(2000);
digitalWrite(blueled, LOW);
}
}
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1820B value stored as a variable?
Code: Select all
sensors.requestTemperatures(); // Send the command to get temperatures
TempC = sensors.getTempCByIndex(0));
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Thanks, I thought I was doing that with this line...
I will replace that with the code you reference. Thanks!
Code: Select all
float getTempF(uint8_t*);
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1820B value stored as a variable?
Your line is called a definition it tells the compiler there is a function that takes a int and returns a float. That's all it does.
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Ok friends, I really need some help. I think I'm close, but my lack of coding knowledge is causing me and my students to agonize over this.
When I run the code here, it *seems* to detect the temperature once and one LED *does* light up. However, there isn't a loop effect. I'm almost certain my trouble is in the if, else code. Take a look and help me and my kids out?
As an aside, I showed them the blog post about this project, they were SO EXCITED! I doubt Becky Stern ever sees these posts, but if she does, she needs to know she's made a huge impact on some of my students. They got the idea to use the Flora after seeing several of her wearables videos. </aside>
When I run the code here, it *seems* to detect the temperature once and one LED *does* light up. However, there isn't a loop effect. I'm almost certain my trouble is in the if, else code. Take a look and help me and my kids out?
As an aside, I showed them the blog post about this project, they were SO EXCITED! I doubt Becky Stern ever sees these posts, but if she does, she needs to know she's made a huge impact on some of my students. They got the idea to use the Flora after seeing several of her wearables videos. </aside>
Code: Select all
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float TempF;
int redled = 12;
int blueled = 6;
int whiteled = 9;
int pinkled = 10;
void setup(void)
{
Serial.begin(9600);
sensors.begin();
// float getTempF(uint8_t*);
pinMode(redled, OUTPUT);
pinMode(blueled, OUTPUT);
pinMode(whiteled, OUTPUT);
pinMode(pinkled, OUTPUT);
}
void loop(void)
{
TempF = sensors.getTempFByIndex(0);
if (TempF > 100)
{
digitalWrite(redled, HIGH);
}
else if (TempF > 90)
{
digitalWrite(pinkled, HIGH);
}
else if (TempF > 70)
{
digitalWrite(whiteled, HIGH);
}
else
{
digitalWrite(blueled, HIGH);
}
}
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: DS1820B value stored as a variable?
Your code looks right. I'd add a Serial.println(TempF); after you read the temperature so you can see what the reading is in the Serial Monitor.
And I'll let Becky know that she has fans. :)
And I'll let Becky know that she has fans. :)
- crafty184
- Posts: 21
- Joined: Tue Oct 08, 2013 12:14 pm
Re: DS1820B value stored as a variable?
Thanks, Bill.
It's still doing what it's been doing, in that it will detect the temperature when it starts, but the LED never changes, even if the temp sensor detects a different temperature.
I welcome any thoughts, this is driving me nuts.
It's still doing what it's been doing, in that it will detect the temperature when it starts, but the LED never changes, even if the temp sensor detects a different temperature.
I welcome any thoughts, this is driving me nuts.
- Franklin97355
- Posts: 23911
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1820B value stored as a variable?
What values do you get for the temperature after you added the code to print them out?
Please be positive and constructive with your questions and comments.