Error while compileing the code for counting hour and sensor value.

Hello Sir,

I want to make a hour counter and rpm for my bike. I had written following codes for that but while compiling these codes. many errors are comming. one of those code is "'lcd' does not name a type".
please help me to compile the following codes.

regards
Roshan

#include <LiquidCrystal.h>
#include <EEPROM.h>
int address = 0;
float x= 254.4 ;
float y= millis()/60000; // to count decimal of hours
int RPM = 0;// starting value of sensor
float f=1.5; //change value of f for calibration
LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
lcd.print("Hello Roshan");//welcome message in lcd
lcd.println("welcome");

void setup() {
if(EEPROM.get(address,x)>x)
{
x=EEPROM.get(address,x); //for getting eeprom value last stored when re powered
}else{
x=x;
}
lcd.begin(16,2);

// put your setup code here, to run once:

}

void loop() {
RPM = analogRead(A0)*f;// calculation of sensor value
if (digitalRead(13)== 1) //when pin 13 will be high proceed to next step else update eeprom
{
if(digitalRead(14)==1) //when pin 14 will be high calculate x i.e. progressive hours
{
x+=y;
}
else {
x=x;
}} else {
EEPROM.update(address,x);
}
}
lcd.setCursor(0,1); //printing value of sensor in lcd in 1st line
lcd.print("RPM=");
lcd.print(RPM);
lcd.setCursor(0,2); //printing value of hours in second line of lcd
lcd.print("Engine Hrs.-");
lcd.print(x);
delay(100);
}

What about moving the code that is not about variable declaration into setup()?

You should format your code properly and use proper indentation. It's really hard to read your code. Also use code tag while posting your code.

Is that LiquidCrystal is part of your Arduino library.

Hello sarouje sir,

I am new to programming so,
If the following code is readable and understandable. Please help to rectify the errors

#include <LiquidCrystal.h>
#include <EEPROM.h>
int address = 0;
float x= 254.4 ;
float y= millis()/60000; // to count decimal of hours
int RPM = 0; // starting value of sensor
float f=1.5; //change value of f for calibration

void setup()

LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
lcd.print("Hello Roshan"); //welcome message in lcd
lcd.println("welcome")
{
if(EEPROM.get(address,x)>x)
{
x=EEPROM.get(address,x); //for getting eeprom value last stored when re powered
}else{
x=x;
}
}

void loop() {
RPM = analogRead(A0)*f; // calculation of sensor value
if (digitalRead(13)== 1) //when pin 13 will be high proceed to next step else update eeprom
{
if(digitalRead(14)==1) //when pin 14 will be high calculate x i.e. progressive hours
{
x+=y;
}
else {
x=x;
}} else {
EEPROM.update(address,x);
}
}
lcd.setCursor(0,1); //printing value of sensor in lcd in 1st line
lcd.print("RPM=");
lcd.print(RPM);
lcd.setCursor(0,2); //printing value of hours in second line of lcd
lcd.print("Engine Hrs.-");
lcd.print(x);
delay(100);
}

Well put aside this for the time being and go first read a bit about programming in C/C++

Understand how the syntax needs to work and the role of { and } and what I meant by moving the code into the setup function...

Also read the posts at the top of the forum especially the one titled Read this before posting a programming question ... and Please read how to use this forum for tips on how to make forum posts, and get the most out of using this forum. Thanks!

void setup()

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Where is the opening curly bracket of the setup() function ?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You need to write your code in stages:

  1. Write code for the LCD Display, debug it and get it working.
  2. Write code for the EEPROM read and write, debug it and get it working.
  3. Write code for the RPM detection and Calculation, debug it and get it working.
  4. Write code for the Hour Calculation, debug it and get it working.
  5. Combine the LCD Display code and the RPM Detection and Calculation, debug it and get it working.
  6. Combine this code with the Hour Calculation Code, debug it and get it working.
  7. Combine this code with the EEPROM code, debug it and get it working.

It may sound long and laborious but in the end it means you minimise errors and learn statement structure.

Tom... :slight_smile:

else{
  x=x;
}

Well, that's certainly useful!

LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
  lcd.begin(16,2);
  lcd.print("Hello Roshan");                                  //welcome message in lcd
  lcd.println("welcome");
  if(EEPROM.get(address,x)>x)
  {
     x=EEPROM.get(address,x);                                    //for getting eeprom value      last stored when re powered
  }
  else
  {
     x=x;
  }
}

I havent tried connecting an lcd before, but i just formatted your code here. Compare with yours.

Also read other members comments. I agree with Tom's suggestion, start simple and progress one functionality at a time.