Hello all
I have a problem. I am making a range finder and if the distance is less than 10 cm a red LED should light up and the buzzer should make a noise, but I get an error message in my code. can anyone help me?
(if the adstand is larger than 10 cm, a green LED lights up)
thank you in advance
Kind regards
Cisse
[#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup() {
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration0.036/2;
distanceInch = duration0.0133/2;
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print("inch");
delay(10);
if(distanceCm ==<10) // here is the error message
digitalWrite(12, HIGH); // red LED turns on
digitalWrite(11, HIGH);// buzzer turns on
digitalWrite(13, LOW);// green LED turn off
else(
digitalWrite(12, LOW);// red LED turns off
noTone(13);// buzzer turns off
digitalWrite(13, HIGH);// green LED turn on
)
}