Project 47 from Electronics For Dummies (9 in 1 Books) - lcd.setCursor(7,1);

I am about 10 days into the world of Arduino. I am making a project from the Electronics for Dummies book, and I am having problems with programming. :o

I copied the program exactly how it is from the book, and made sure to have all the wires plugged into the bread board and UNO-R3 exactly.

The problem is at lcd.setCursor(7,1);

I try to upload the program, but it replies with, "lcd" was not declared in this scope" ...This project is a Ultra Sonic Proximity Sensor. I copied it exactly as the book says, but won't upload.

`` lcd.setCursor(7,1); //<-----PROBLEM
lcd.print(distance);
lcd.print(" ");

// Flash the LED if the object is close
If (distance < close)
{
digitalWrite(4, HIGH);
delay(50);
digitalWrite(4, LOW);
delay(50);
}
else
{
delay(100);
}


:slight_smile:

Post the complete code. Can't see the error in that snippet. That line is where the error is but the problem is before that.

Please edit your post and fix the tags. The code goes between the two tags not between two sets of them.

Here is the full code from the project.

``//ULTRA SONIC PROXIMITY SENSOR!
//October 10th 2018
//Biggest project yet
//The object in view will be displayed on LCD every 0.5 seconds, until 10 cm's in range
//
//Arduino Digital Pin Connections:
//
// 2 - Ultrasonic Trigger
// 3 - Ultrasonic Echo
// 4 - LED
// 8 - LCD RS
// 9 - LCD CLOCK
// 10 - LCD D0
// 11 - LCD D1
// 12 - LCD D2
// 13 - LCD D3

#include <LiquidCrystal.h>

// Create the LCD and assign the interface pins LiquidCrystal lcd (8, 9, 10, 11, 12, 13);

int close = 10; //The distance that triggers the LED

void setup() {

// Initialize the LCD and siplay the headings
lcd.begin(16, 2);
lcd.print("Proximity Sensor");
lcd.setCursor(0, 1);
lcd.print("Range: ");

// Set the pin modes
pinMode(2, OUTPUT); // Trigger Pin
pinMode(3, INPUT); // Echo Pin
pinMode(4, OUTPUT); // LED On

}

void loop() {

float distance;
int pulseLength;
digitalWrite(2, LOW);
delayMicroseconds(20);
digitalWrite(2, HIGH);
delayMicroseconds(100);
digitalWrite(2, LOW);

// Get the echo pulse and calculate the distance
pulseLength = pulseIn(3, HIGH);
distance=pulseLength / 58.774;

//

lcd.setCursor(7,1);
lcd.print(distance);
lcd.print(" ");

// Flash the LED if the object is close
If (distance < close)
{
digitalWrite(4, HIGH);
delay(50);
digitalWrite(4, LOW);
delay(50);
}
else
{
delay(100);
}

}``

You failed at code tags yet again. Before posting, please click the Preview button and make sure your post is correctly formatted.

RYEGUY32:
I copied the program exactly how it is from the book

Are you sure of that? Because this:

RYEGUY32:

// Create the LCD and assign the interface pins LiquidCrystal lcd (8, 9, 10, 11, 12, 13);

Should be two lines:

// Create the LCD and assign the interface pins
LiquidCrystal lcd (8, 9, 10, 11, 12, 13);

Ahhh, there is the problem. Make it 2 lines!

I pressed the Code button, before and after, I just assumed I posted it correctly. I'll make sure next time.

I'll try this out tomorrow. I just took the project apart.

Thanks! 8)