As i am i total noob and i beginner i need some help whit my projekt.
I have downloaded a exemple for 3 ultrasonic sensors, and i have now got them
to show up on my 20x4 lcd.
Im tying to add one more sensor but i cant get in to show up in the lcd.
What i did was copy/paste the code and change some value to match the code.
Anyone know whats wrong? dont get any error uploading the code.
Thanks
David
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int trigPin1 = 22;
int echoPin1 = 23;
int trigPin2 = 24;
int echoPin2 = 25;
int trigPin3 = 26;
int echoPin3 = 27;
int trigPin4 = 28;
int echoPin4 = 29;
void setup() {
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
pinMode(trigPin4, OUTPUT);
pinMode(echoPin4, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void firstsensor(){ // This function is for first sensor.
Serial.begin (9600);
lcd.begin(20, 4);
int duration1, distance1;
digitalWrite (trigPin1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin1, LOW);
duration1 = pulseIn (echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
lcd.setCursor(0,0);
lcd.print("Längd ");
lcd.print(distance1);
lcd.print(" cm ");
delay(250);
if (distance1 < 30) { // Change the number for long or short distances.
digitalWrite (ledPin1, HIGH);
} else {
digitalWrite (ledPin1, LOW);
}
}
void secondsensor(){ // This function is for second sensor.
int duration2, distance2;
digitalWrite (trigPin2, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin2, LOW);
duration2 = pulseIn (echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
lcd.setCursor(0,1);
lcd.print("Bredd ");
lcd.print(distance2);
lcd.print("cm");
delay(150);
if (distance2 < 20) { // Change the number for long or short distances.
digitalWrite (ledPin2, HIGH);
}
else {
digitalWrite (ledPin2, LOW);
}
}
void thirdsensor(){ // This function is for third sensor.
int duration3, distance3;
digitalWrite (trigPin3, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin3, LOW);
duration3 = pulseIn (echoPin3, HIGH);
distance3 = (duration3/2) / 29.1;
lcd.setCursor(0,2);
lcd.print("Bredd ");
lcd.print(distance3);
lcd.print("cm");
delay(150);
if (distance3 < 10) { // Change the number for long or short distances.
digitalWrite (ledPin3, HIGH);
}
else {
digitalWrite (ledPin3, LOW);
}
}
void foursensor(){ // This function is for four sensor
int duration4, distance4;
digitalWrite (trigPin4, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin4, LOW);
duration4 = pulseIn (echoPin4, HIGH);
distance4 = (duration4/2) / 29.1;
lcd.setCursor(0,3);
lcd.print("Bredd ");
lcd.print(distance4);
lcd.print("cm");
delay(150);
if (distance4 < 10) { // Change the number for long or short distances.
digitalWrite (ledPin3, HIGH);
}
else {
digitalWrite (ledPin3, LOW);
}
}
void loop() {
Serial.println("\n");
firstsensor();
secondsensor();
thirdsensor();
delay(100);
}