Hi, I am currently doing a project about a human body thermometer. The sensor I am using is the grove ultrasonic sensor which is the same sensor with the HC-SR04 with less input pin needed (If I am not wrong) . The code I created is down below.
#include "Ultrasonic.h"
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <LiquidCrystal_I2C.h>
Ultrasonic ultrasonic(7);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
LiquidCrystal_I2C lcd(0x27, 16, 2);
long range=200;
void setup() {
pinMode(9, OUTPUT);
int counter=0;
while(counter==0){
if (range<=1){
mlx.begin();
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Body Temp:");
lcd.setCursor(0,1);
lcd.print(mlx.readObjectTempC());
lcd.print("C");
tone(9, 500);
delay(1000);
noTone(9);
counter=1;
}
else{
range= ultrasonic.MeasureInCentimeters();
}
}
}
void loop() {
}
The sensor will suddenly pick up range<=1 without anything in its range and go in to the if section. Try to troubleshoot it by reading the value of range with a separate code but it never shows up to be 1 or less than 1. Is it the sensor is faulty or there is a bug/problem in my code?
Any help is appreciated, Thanks for helping!!