Urgent help needed to fix the temperature sensor

code:
#include "Ultrasonic.h"
#include <math.h>
Ultrasonic ultrasonic(7);
const int B = 4275; // B value of the thermistor
const long R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
int percentage;

void setup()
{
Serial.begin(9600);
}
void loop()
{

//ultrasonic
long RangeInCentimeters;

Serial.println("The distance to obstacles in front is: ");
RangeInCentimeters = ultrasonic.MeasureInCentimeters();
percentage = map(RangeInCentimeters, 5, 20, 0, 100);
Serial.println(percentage);
//Serial.println("%");
delay(1000);

//temperature 
int a = analogRead(pinTempSensor);

float R = 1023.0/a-1.0;
R = R0*R;

float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

Serial.print("temperature = ");
Serial.println(temperature);

delay(1000);

}

hi i met some error as i trying to use the temperature sensor it gave me the error " warning: overflow in implicit constant conversion [-Woverflow]"

and also how do to do a conversion can be programmed such that the ultrasonic
sensor reading can be mapped to 0-100% for the water level (e.g. 5cm distance mapped to 100%
and 30cm mapped to 0%).

tks in advance, btw im a newbie here trying to learn it for my school project

Post code, not pictures of code.
Post error messages, not pictures of error messages.

okay i will do next time, sry about that im a newbie

Why not do it this time?

1 Like

Please post the code.

100,000 will not fit into a 16 bit integer int. You need a long or an unsigned long.

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).

1 Like