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