Hello, I tried to run my code in arduino and it keeps telling me that microsecondsToCentimeters’ was not declared in this scope. Though I don’t see any problem with it and I think it should work perfectly. please help me, it already took to much time from me.
This is the code that I tried to run
#include <LiquidCrystal.h>
const int pingPin = 7; // Trigger pin Ultrasonic Sensor
const int echoPin =6; // Echo pin of Ultrasonic Sensor
const int motorPin =2;
const int puzzer =4;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13,12,11,10,9,8);
// Then we initialize all the devices used in the project
void setup() {
Serial.begin(9600); //Starting Serial Terminal
delay(2000);
lcd.begin(16,2);
pinMode(puzzer, OUTPUT);
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, HIGH);
lcd.setCursor(1,1);
lcd.print("pump on");
}
void loop() {
long duration, cm, lev;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin,INPUT);
duration = pulseIn(echoPin, HIGH);
cm = microsecondsToCentimeters(duration);
lev = 32 - cm;
lcd.setCursor(1,0);
lcd.print("level");
lcd.setCursor(11,0);
lcd.print("cm");
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(lev);
/*After that we check conditions if water level is LOW or water level is HIGH and take
actions accordingly.*/
if (lev>28 && lev<32)
{
digitalWrite(motorPin, LOW);
lcd.setCursor(1,1);
lcd.print("pump off");
}
if (lev>8 && lev<15)
{
digitalWrite(puzzer, HIGH);
delay(500);
digitalWrite(puzzer, LOW);
delay(500);
digitalWrite(puzzer, HIGH);
delay(500);
digitalWrite(puzzer, LOW);
delay(500);
digitalWrite(motorPin, HIGH);
delay(500);
lcd.setCursor(1,1);
lcd.print("pump on");
delay(500);
}
}