- Pin1 is output pin
- Pin2 is VCC pin
- Pin3 of the sensor connected to the ground
CODE:-
// include the library code:
#include <LiquidCrystal.h>
int sensor1 = A0; //the Analog sensor is connected to analog pin 0
int sensor2 = 9; //the Digital sensor is connected to digital pin 9
int sensorValue = 0; // Variable to store the value read from the Analog sensor
int sensorDigital = 0; //Variable which store the value read from the Digital sensor
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600); // use the serial port
}
void loop() {
sensorValue = analogRead(A0); //read the sensor and store it in the variable sensorValue
sensorDigital = digitalRead(9); //read the sensor and store it in the variable sensorDigital
lcd.setCursor(0,0); // set the cursor at column(0) and row(0)
lcd.print(sensorValue); //Print the sensorValue to LCD
Serial.print(sensorValue); //Print the sensorValue to serial monitor
lcd.setCursor(0,1); //set the cursor at column(0) and row(0)
lcd.print(sensorDigital); //Print the sensorDigital to LCD
Serial.print(sensorDigital); // Print the sensorDigital to serial monitor
delay(1000); //delay to avoid overloading the serial port buffer
}
Comments
Post a Comment