Hello all. I am new to arduino but not programming. I have accomplished some projects now. I am working on with a HC-SR04 a standard lcd and an elegoo but will get an arduino soon. I am using this following tutorials.
and
The first one is how I hooked up my lcd it is working fine. The second url has added stuff like the ultra sound sensor.
The following code is what I have compiled and run on my elegoo.
[code]
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
#define trigger_pin 15 // HC-SR04 trigger pin is connected to Arduino A1
#define echo_pin 14 // HC-SR04 echo pin is connected to Arduino A0
int ledPin = 13; // choose the pin for the LED
int inputPin = 9; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(trigger_pin, OUTPUT);
pinMode(echo_pin, INPUT);
digitalWrite(trigger_pin, LOW);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
lcd.print("Distance"); // Prints "Arduino" on the LCD
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
unsigned long duration;
unsigned int distance;
void loop(){
// Send 10us pulse to HC-SR04 Trigger pin
digitalWrite(trigger_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trigger_pin, LOW);
// Read pulse comes from HC-SR04 Echo pin
duration = pulseIn(echo_pin, HIGH); // Read echo pulse width
if(duration == 0) { // Previous function returns 0 if timeout
lcd.setCursor(2, 1);
lcd.print(" Time Out ");
}
else {
distance = duration / 58; // Calculate the distance in cm
if(distance > 400) { // HC-SR04 module can measure up to 400cm
lcd.setCursor(2, 1);
lcd.print("Out of Range");
}
else {
lcd.setCursor(2, 1);
lcd.print(" cm ");
lcd.setCursor(5, 1);
lcd.print(distance);
}
}
delay(100);
}
[/code]
The output result is a few machine letters that move around the lcd screen to many different locations I uploaded an image of what the letters say. I cannot understand them I was hoping that someone would understand what it means so maybe I can figure out what is wrong.