My first robot related post – Arduino LCD – HC-SR04

Posted: July 31, 2012 in Arduino

Lets make it a nice and simple one…

So I’ve just picked up the Arduino UNO, and a LCD/Distance sensor kit. I don’t know too much about programming and electronics, but I got this up and running without too much hassle. Vid links below.

Code, which also includes a bit of code that outputs cm to serial as well as LCD and will say out of range when more than 100cm.

#include <Ultrasonic.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Ultrasonic ultrasonic(7,6);

void setup()
{
Serial.begin( 9600 );
lcd.begin(16, 2);
lcd.print(“Testing…”);
}
void loop()
{

if (ultrasonic.Ranging(CM)>= 100) {
Serial.println(“Out Of Range”);

}
else {
Serial.print( ultrasonic.Ranging(CM) );
Serial.println( “cm” );
}
delay(1000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(ultrasonic.Ranging(CM));
lcd.print(“cm”);
delay(100);
}

Leave a comment