#include <Servo.h>
#include <LiquidCrystal.h>
int ultra = 0;
int distance = 0;
Servo servo_11;
LiquidCrystal lcd_1(5, 6, 7, 8, 9, 10);
int readUltrasonicDistance (int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
servo_11.attach(11);
lcd_1.begin(16, 2);
}
void loop()
{
ultra = 0.006783 * readUltrasonicDistance(12, 12);
Serial.print(ultra);
lcd_1.print("hi");
if (ultra >= 80 && ultra <=130) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
Serial.println(" : Safe");
servo_11.write(180);
lcd_1.print("Safe");
}
if (ultra > 35 && ultra < 80) {
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
Serial.println(" : Beware");
servo_11.write(90);
lcd_1.print("Beware");
}
if (ultra <= 35) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
Serial.println(" : Dangerous");
servo_11.write(0);
lcd_1.print("Dangerous");
}
if (ultra > 129) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
Serial.println(" = 404.error");
servo_11.write(0);
lcd_1.print("error");
}
delay(10);
}
Tell us what part is not working ?
Never power a motor from the 5v pin on an Arduino.
who in loop readUltrasonicDistance
();
the
Ultrasonic Distance sensor
Trigger & Echo on Pin 12?
-
the text no working and showing randon latters
-
its a servo monetor so its ok for the 5v
yes you know how Ultrasonic Distance sensor works? its working fine dont warry abt it
BTW Is the serial monitor set to 9600 ?
Does it display things properly ?
Show us a good image of your βactualβ wiring.
You do know you have to position the LCD print location before you send your text to the LCD .
wdym i wrote this the 9600 is the serial monitor.
where shold i put this?
Does the text on the serial monitor look okay ?
Here is an example to print to the LCD.
lcd.setCursor(0, 1); // <βββ<<<<< select where to start printing
// 111111
// 0123456789012345
// Counter = xx
lcd.print(" Counter = ");
Does the text on the serial monitor look okay ?
no. its looking like this
Not, it is not. You can destroy the Arduino, and even if you don't, it will create havoc for the rest of the circuitry.
Remove the servo, because it is part, or all of the problem.
You code is printing to two (2) devices.
- SERIAL monitor
- LCD
- Does your serial monitor display the correct text.
- Your LCD display text is all garbage, you need to set the print location before sending the LCD text.
- Show us a good image of your actual wiring.
i removed it and its still not showing off
- no
- i did and it didnt solved nothing
- wdym your actual wirinfg
-
Open the serial monitor window.
-
In the bottom right of the window, set the baud rate to 9600.
-
Actual wiring means take a good picture of the components with all the wires, then attach that picture to a post here so we can check the real wiring.
-
Show us your new attempt at writing to the LCD.
Then you have other problems as well. Could be the wiring, but the posted wiring diagram is incomprehensible.