i did a project and this showed. help please?
#include <LiquidCrystal.h>
#define trigPin 1
#define echoPin 2
#define powerPin 0
#define groundPin 3
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(powerPin, OUTPUT);
pinMode(groundPin, INPUT);
lcd.begin(16, 2);
}
void loop() {
digitalWrite(powerPin, HIGH);
float duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) * 0.0344;
if (distance >= 400 || distance <= 2) {
lcd.print("ERR");
}
else {
lcd.print("Distance = " && distance);
delay(500);
}
delay(500);
}
Do we have to guess the error message?
This?lcd.print("Distance = " && distance);
?
(Using pin zero is not a great idea - the serial interface has dibs)
Aside from the error that wasn't posted, this line may not do what you expect:
delayMicroseconds(2);
Notes and Warnings
This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.
there was no error message
Try this change
else {
lcd.print("Distance = " && distance);
delay(500);
}
to
else {
lcd.print("Distance = ");
delay(500);
lcd.print (distance);
delay(500);
}
Your code happily compiles on my system for a Nano. No "exit status 1" message.
alecjensen:
i did a project and this showed. help please?
#include <LiquidCrystal.h>
#define trigPin 1
#define echoPin 2
#define powerPin 0
#define groundPin 3
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(powerPin, OUTPUT);
pinMode(groundPin, INPUT);
lcd.begin(16, 2);
}
If you are going to power the ultrasonic range sensor through Pin 0 and Pin 3 you should set both pins to OUTPUT, then set the Power pin to HIGH and the Ground pin to LOW.