[vc_row][vc_column][vc_column_text]
[/vc_column_text][vc_tour][vc_tab title=”Part list” tab_id=”1394617120-1-0″][vc_column_text]1 x [bigcommerce link=”/cityduino-arduino-uno-compatible-device/” target=”_blank”] arduino UNO [/bigcommerce]
1 x [bigcommerce link=”/ultrasonic-sensor-breakout-srf04/” target=”_blank”]Ultrasonic Module HCSR04[/bigcommerce]
1 x [bigcommerce link=”/2-8-touch-lcd-shield-for-arduino-pcduino/” target=”_blank”]Serial 16×2 LCD shield R04[/bigcommerce]
6 x DuPont line
1 x 5v 2A[bigcommerce link=”/ac-100-240v-0-3a-dc-5v-2a-us-plug-usb-power-supply-adapter/” target=”_blank”] power[/bigcommerce][/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1394617120-2-89″][vc_column_text]HCSR04 Vcc – > arduino Vin
HCSR04 GND – >arduino GND
HCSR04 Trig – > arduino D2
HCSR04 Echo – > arduino D3
Serial 16×2 LCD shield +5v – > arduino +5v
Serial 16×2 LCD shield GND – > arduino GND
Serial 16×2 LCD shield Rx – >arduino Tx
After the wiring is finished, plug in 5v 2A power to the power supply port for arduino. Then connect the computer with USB.[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1394617359621-2-6″][vc_column_text]
#include <stdio.h>
const int LCDdelay=10;
const int TriPin = 2;
const int EchoPin = 3;
float cm;
void lcdPosition(int row, int col) {
Serial.write(0xFE); //command flag
Serial.write((col + row*64 + 128)); //position
delay(LCDdelay);
}
void clearLCD(){
Serial.write(0xFE); //command flag
Serial.write(0x01); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
Serial.write(0x7C); //command flag for backlight stuff
Serial.write(157); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
Serial.write(0x7C); //command flag for backlight stuff
Serial.write(128); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
Serial.write(0xFE);
}
void setup()
{
Serial.begin(9600);
pinMode (TriPin, OUTPUT);
pinMode (EchoPin, INPUT);
}
void loop()
{
digitalWrite (TriPin, LOW);
delayMicroseconds (2);
digitalWrite (TriPin, HIGH);
delayMicroseconds (10);
digitalWrite (TriPin, LOW);
cm = pulseIn (EchoPin, HIGH, 100000) / 58.0;
cm = (int (cm * 100.0)) / 100.0;
backlightOn ();
clearLCD ();
lcdPosition (0, 0);
Serial.print ("Arduino: ");
Serial.print (cm);
Serial.print (" cm - LinkSprite");
delay (1000);
}
[/vc_column_text][/vc_tab][vc_tab title=”Test result” tab_id=”1394617360718-3-4″][vc_column_text]The picture is the same as the beginning, 16 × 2 screen will display “Arduino: xxx (measured out the distance) cm – LinkSprite”
Use a piece of paper or other obstructions to block before the emission head, the 16*2 screen will show the distance between the obstruction and emission head.[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Leave a Reply
You must be logged in to post a comment.