I have a waterproof DS18B20 that I have wired up to an Arduino Mini Pro. Red to #8 pin, Yellow to A1 pin with 4.7K resistor between, and Black to ground. But I get very weird reading.
This is my code
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS A1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Fahrenheit=0;
float Celcius=0;
void setup() {
Serial.begin(9600);
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(8,HIGH);
sensors.requestTemperatures();
delay(1000);
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.getTempFByIndex(0);
digitalWrite(8,LOW);
}
When I compile I get this in red. What am I doing wrong and how do I fix this?
/Users/ME/Documents/Arduino/pool_filler_NEW/pool_filler_NEW.ino:24:35: warning: invalid conversion from 'const OneWire*' to 'OneWire*' [-fpermissive]
DallasTemperature sensors(&oneWire);
^
In file included from /Users/ME/Documents/Arduino/pool_filler_NEW/pool_filler_NEW.ino:1:0:
/Users/ME/Documents/Arduino/libraries/Arduino-Temperature-Control-Library-master/DallasTemperature.h:46:2: note: initializing argument 1 of 'DallasTemperature::DallasTemperature(OneWire*)'
DallasTemperature(OneWire*);
gbenna:
I have a waterproof DS18B20 that I have wired up to an Arduino Mini Pro. Red to #8 pin, Yellow to A1 pin with 4.7K resistor between, and Black to ground.
This reads like you have the 4k7 in the signal line rather than a pullup to 5v.
Arduino 1-Wire Tutorial see the diagram. The instructions might also be useful. I understand you are switching the power to DS18B20. I bet you don't have a good reason for doing that, and it might be the cause of your problem.
Make the text of the sketch look nice.
Use '{' and '}' always in the same way.
Use indents, spaces, comma's in a nice way.
Use newlines in a nice way.
Add comment.
You can also press Ctrl+T
If you do that, then you will see immediate what is wrong.
When the compiler has a warning or error, scroll up and find the first error. The rest might be caused by the first error.
The compiler tells that there is function-definition in the function setup() and that it is not allowed.
I have done this on another project and powering from pin is fine. I has worked I bridge between the Yellow and the Red wire with a 4.7k resistor. I want to turn on and off sensor because I want to save energy. Only checking the temperature every two hours.
I am just not sure where the error in coding is. If I look at my code and the code you posted. The parts I have are the same. Except that I am using pin A1 instead of pin 2. Reading up on this, I see that an Analog pin does work. And like I said I has worked before in another project. Unless an update to the library has changed things. Can you help me find the problem with my code that is causing the error.
So I found the problem as to why it wasn't working. I had included
sensors.begin(); in the void setup(){
Once I removed that everything works fine. Although I still I am getting the error message.
If someone could tell be what that is all about I would appreciate it.
Can you make the sketch look nice and show it to us. Then we have proof that you can press Ctrl+T.
If you keep the text layout as a big mess, then you keep on making these mistakes.
When the compiler encountered an error, find the first error, the compiler gives the linenumber. Turn on the linenumbers in the settings, and you should easily find the line with the problem. I think that the line with the first found error is also highlighted. Sometimes the problem is in the line before that, but the compiler is pretty accurate to tell what is wrong.
gbenna:
So I found the problem as to why it wasn't working. I had included
sensors.begin(); in the void setup(){
Once I removed that everything works fine. Although I still I am getting the error message.
I can't explain or even understand why everything is fine, although "fine" would probably mean no error messages, so I guess you can't either. The error message may be caused by you removing
I'm sorry. I didn't post all of my code as there is a lot of other stuff that is not related to the temperature.
By fine I mean that the sensor come on when asked to and read the correct temperature and goes off. It repeats in the loop as desired. Looking at the code Line 24 is DallasTemperature sensors(&oneWire); and line 35 is float Celcius=0; Although I changed it. It was float Fahrenheit=0; and I still get the error message. Also the error message was there before and after I removed sensors.begin();. The only thing that changed after I removed sensors.begin(); is the DS18B20 started recording the correct temperature.
gbenna:
The only thing that changed after I removed sensors.begin(); is the DS18B20 started recording the correct temperature.
You amaze me.
I now see that there might be something like this on Henry's Bench. I guess it has to with having only one sensor. I doubt that removing that code was the real solution to whatever the problem was. Don't expect it to work if you later want to use more than one.
Btw these sensors are not really waterproof - the metal sheath is, but where the wires come out is not . If you submerse the lot , it will probably fail in a few hours .
hammy:
Btw these sensors are not really waterproof - the metal sheath is, but where the wires come out is not . If you submerse the lot , it will probably fail in a few hours .