Temperature Sensor displaying -196.6 on Blynk App

Hi! I am using the ds18b20 temperature sensor and it is displaying data on the app. However, the issue I have is that it is constantly displaying -196.6 as the temperature on the app. I have tried a vanilla code with the serial monitor, and the sensor displays the data perfectly to the serial monitor, so I don’t think it’s an issue with the wiring or the sensor itself. I am using an Arduino Nano if that helps.



//fall detection
#include <Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
float ax=0, ay=0, az=0, gx=0, gy=0, gz=0;

//int data[STORE_SIZE][5]; //array for saving past data
//byte currentIndex=0; //stores current data array index (0-255)
boolean fall = false; //stores if a fall has occurred
boolean trigger1=false; //stores if first trigger (lower threshold) has occurred
boolean trigger2=false; //stores if second trigger (upper threshold) has occurred
boolean trigger3=false; //stores if third trigger (orientation change) has occurred

byte trigger1count=0; //stores the counts past since trigger 1 was set true
byte trigger2count=0; //stores the counts past since trigger 2 was set true
byte trigger3count=0; //stores the counts past since trigger 3 was set true
int angleChange=0;
//temperature
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//blynk
#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial (2,3); // RX, TX
#include <BlynkSimpleStream.h> 
char auth[] = "XGTJ9FJkD8tr0f9KFG7WoxFC6oksNOTR";

BlynkTimer timer;

void setup()
{
 timer.setInterval(2000L,soundSensor);
 timer.setInterval(1000L,tempSensor);
 timer.setInterval(3000L,sendSensor);

  Serial.begin(9600);
  Blynk.begin(auth,Serial);

   DebugSerial.begin(9600);  
 pinMode(13,OUTPUT);
 pinMode(A0,INPUT);
 Wire.begin();
 Wire.beginTransmission(MPU_addr);
 Wire.write(0x6B);  // PWR_MGMT_1 register
 Wire.write(0);     // set to zero (wakes up the MPU-6050)
 Wire.endTransmission(true);

sensors.begin();

 pinMode(11, OUTPUT);
 digitalWrite (11,HIGH);
}
void sendSensor()
{
  //for fall detection

 //2050, 77, 1947 are values for calibration of accelerometer
 // values may be different for you
 ax = (AcX-2050)/16384.00;
 ay = (AcY-77)/16384.00;
 az = (AcZ-1947)/16384.00;

 //270, 351, 136 for gyroscope
 gx = (GyX+270)/131.07;
 gy = (GyY-351)/131.07;
 gz = (GyZ+136)/131.07;

 // calculating Amplitute vactor for 3 axis
 float Raw_AM = pow(pow(ax,2)+pow(ay,2)+pow(az,2),0.5);
 int AM = Raw_AM * 10;  // as values are within 0 to 1, I multiplied 
                        // it by for using if else conditions 


 if (trigger3==true){
    trigger3count++;
    if (trigger3count>=10){ 
       angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5);
       if ((angleChange>=0) && (angleChange<=10)){ //if orientation changes remains between 0-10 degrees
           fall=true; trigger3=false; trigger3count=0;
             }
       else{ //user regained normal orientation
          trigger3=false; trigger3count=0;
       }
     }
  }
 if (fall==true){ //in event of a fall detection
Blynk.notify("the patient has fallen down!");
  
   fall=false;
  // exit(1);
   }
 if (trigger2count>=6){ //allow 0.5s for orientation change
   trigger2=false; trigger2count=0;
   }
 if (trigger1count>=6){ //allow 0.5s for AM to break upper threshold
   trigger1=false; trigger1count=0;
   }
 if (trigger2==true){
   trigger2count++;
   //angleChange=acos(((double)x*(double)bx+(double)y*(double)by+(double)z*(double)bz)/(double)AM/(double)BM);
   angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5); 
   if (angleChange>=30 && angleChange<=400){ //if orientation changes by between 80-100 degrees
     trigger3=true; trigger2=false; trigger2count=0;
       }
   }
 if (trigger1==true){
   trigger1count++;
   if (AM>=12){ //if AM breaks upper threshold (3g)
     trigger2=true;
     trigger1=false; trigger1count=0;
     }
   }
 if (AM<=2 && trigger2==false){ //if AM breaks lower threshold (0.4g)
   trigger1=true;
   }
//It appears that delay is needed in order not to clog the port

 Wire.beginTransmission(MPU_addr);
 Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
 Wire.endTransmission(false);
 Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
 AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
 AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
 GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
 GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
 GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
}
//for sound sensor
void soundSensor()
{
    int sensorVal=analogRead(A0);
    Blynk.virtualWrite(V1,sensorVal);

if (sensorVal>=500){
  digitalWrite(13,HIGH);
  Blynk.notify("a shout or loud noise detected near/from the patient");
}
else {
  digitalWrite(13,LOW);
}
}
  void tempSensor () {
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0) * 9.0 / 5.0 + 32.0;
  Blynk.virtualWrite(V5,temperature);
  
if (temperature>=100){
  Blynk.notify("the patient's temperature is over 100");
}
if (temperature<=95){
  Blynk.notify("the patient's temperature is below 95");
}
}

void loop ()
{

 Blynk.run();
  timer.run();
 }

-196.6 means “DEVICE DISCONNECTED” when using the Fahrenheit scale. You get -127 instead if using Centigrade.

Pete.

Oh. But I’m a little confused. My devices are all connected and it works fine when I print it to the serial monitor.

Yes, but that’s using a different sketch isn’t it?

Maybe compare the two sketches to find-out what you’ve missed out, or done differently?

Pete.

I just ran the sketch to print it from the serial monitor (the same sketch I was using before) and now I’m having the same issue; the temperature is -196.6/-127. I was using male to female jumper wires so I disconnected those and plugged the temperature sensor straight into the board and I’m still having this issue. I even brought out two new ones but they still give me the same readings. I am using a 5K pullup resistor and powering it through a USB connection.

So your problem clearly isn’t Blynk related.
Maybe do a bit of googling, or re-do your wiring with just the sensor and double-check everything.

Pete.

1 Like

Never mind, it worked! The Arduino Nano must’ve not been connected properly because I pushed it in further and then the readings were correct. Thank you!