Вы находитесь на странице: 1из 4

 PIN1 or VSS to ground.

 PIN2 or VDD or VCC to +5v power.

 PIN3 or VEE to ground (gives maximum contrast best for a beginner).

 PIN4 or RS (Register Selection) to PIN12 of ARDUINO UNO.

 PIN5 or RW (Read/Write) to ground (puts LCD in read mode eases the


communication for user).

 PIN6 or E (Enable) to PIN10 of ARDUINO UNO.

 PIN11 or D4 to PIN5 of ARDUINO UNO.

 PIN12 or D5 to PIN4 of ARDUINO UNO.

 PIN13 or D6 to PIN3 of ARDUINO UNO.

 PIN14 or D7 to PIN2 of ARDUINO UNO.

 PIN15 to +5V with 221 ohm resistor in series.

 And the last PIN16 to ground.


 #include <LiquidCrystal.h>
 lcd.begin(16, 2);
 LiquidCrystal lcd(
 lcd.print("hello, world!");

 /*LCD circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)*/

 #include<LiquidCrystal.h>

 LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Interface pins of the LCD


 const int trig_pin=8;
 const int echo_pin=9;
 long distance,duration;

 void setup() {
 lcd.begin(16,2);
 lcd.setCursor(0,0); //set the cursor to column 0 and line 0
 pinMode(8,OUTPUT);
 pinMode(9,INPUT);
 }

 void loop() {
 digitalWrite(8,HIGH);
 delayMicroseconds(20);
 digitalWrite(8,LOW);
 delayMicroseconds(20);
 duration = pulseIn(echo_pin, HIGH); //To receive the reflected signal.
 distance= duration*0.034/2;
 lcd.setCursor(0,1); //set the cursor to column 0 and line 1
 lcd.print(distance);
 lcd.print("cm");
 delay(100);
 }

 Less

Serial.begin(9600);

int sensorValue = analogRead(A0);

float voltage= sensorValue * (5.0 / 1023.0);

Serial.println(voltage)

/*
ReadAnalogVoltage

Reads an analog input on pin 0, converts it to voltage, and prints the


result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools >
Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins
to +5V and ground.

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
*/

// the setup routine runs once when you press reset:


void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:


void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0
- 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}

Вам также может понравиться