temp sensor not reading at all
-
hey guys
ive tried to modify two of the built in designs to make them work together, but i think ive stuffed up the dallas temprature probethe temprature is never updated or sent to the controller
anyone able to advise what ive missed?
i only have the one temprature sensor hooked up// Enable debug prints //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define COMPARE_TEMP 1 #define MAX_ATTACHED_DS18B20 16 #define LIGHT_SENSOR_ANALOG_PIN 0 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; bool receivedConfig = false; bool metric = true; unsigned long SLEEP_TIME = 120000 ; // 120000 Sleep time between reports (in milliseconds) int lastLightLevel; #define CHILD_ID_TEMP 1 #define CHILD_ID_LIGHT 2 // Enable repeater functionality for this node //#define MY_REPEATER_FEATURE // Initialize motion message MyMessage temp(CHILD_ID_TEMP,V_TEMP); MyMessage light(CHILD_ID_LIGHT, V_LIGHT_LEVEL); //========================= // BATTERY VOLTAGE DIVIDER SETUP // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 #define VBAT_PER_BITS 0.003363075 #define VMIN 1.9 // Vmin (radio Min Volt)=1.9V (564v) #define VMAX 3.0 // Vmax = (2xAA bat)=3.0V (892v) int batteryPcnt = 0; // Calc value for battery % int batLoop = 0; // Loop to help calc average int batArray[3]; // Array to store value for average calc. int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point //========================= void before() { // Startup up the OneWire library sensors.begin(); } void setup() { sensors.setWaitForConversion(false); numSensors = sensors.getDeviceCount(); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Lounge Node enviroment", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); present(CHILD_ID_TEMP, S_TEMP); } void loop() { //light sensor int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.print("Light Level:"); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { send(light.set(lightLevel)); lastLightLevel = lightLevel; //temprature sensors.requestTemperatures(); // query conversion time and sleep until conversion completed int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(temp.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } batM(); // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(SLEEP_TIME); } } void batM() //The battery calculations { delay(500); // Battery monitoring reading int sensorValue = analogRead(BATTERY_SENSE_PIN); delay(500); // Calculate the battery in % float Vbat = sensorValue * VBAT_PER_BITS; int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); // Add it to array so we get an average of 3 (3x20min) batArray[batLoop] = batteryPcnt; if (batLoop > 2) { batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]); batteryPcnt = batteryPcnt / 3; if (batteryPcnt > 100) { batteryPcnt=100; } Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %"); sendBatteryLevel(batteryPcnt); batLoop = 0; } else { batLoop++; } }
-
@markjgabb the debug output of the node is likely the best first step for troubleshooting.
-
-
ok think i have partially found the issue, when i re did it for a simpler setup, it seems that im measureing temprature of -127 im not even sure what the means, i assume its an error but not sure what its telling me
-
God I'm an idiot. Must of picked up the wrong resistor.
10k resistor won't help me much
-
If your Dallas DS18B20 was purchased on ebay or amazon or elsewhere other than DigiKey, Mouser, etc, it is likely counterfeit and will not work in parasitic power mode and will give a -127.
Here's a sketch to help determine of the Ds18B20 is genuine and rule-out shoddy counterfeits:
https://github.com/cpetrich/counterfeit_DS18B20
I wasted countless days and days with remote sensors only to find they were counterfeit.