Skip to main content

How to read analog and digital data both at same time using Arduino

 


From the above circuit, we can read both analog and digital data both at the same time and display the reading over a 16X2 LCD display. We have used PIR(passive infrared sensor) motion sensor for analog values and push button for digital values. The PID motion sensor is connected to analog pin 0 and push button is connected to digital pin 9 of the Arduino . 
PIR motion sensor are used to detects infrared radiation from the environment. It does not emit any energy but passively receives infrared radiation from the environment.

There's a amazing fact human body also emit electromagnetic radiation. The radiation emitted by human body depends on the temperature of the body. Radiation emitted by human body is in the infrared region.


  • 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

Popular posts from this blog

Interfacing RELAY with Arduino UNO

  Interfacing RELAY with Arduino UNO What is Relay? Relay is an automatic switch that detects conditions in circuits and causes the contacts to change their positions to close or open the circuit as required. Relays are used in many applications. When the coil of the relay is energized or de-energized, its contacts are ON or Off.          In a relay, we have to consider two important parameters i.e. once is the Trigger Voltage, this is the voltage required to turn on the relay that is to change the contact from Common->NC to Common->NO. Our relay here has a 5V trigger voltage.   Let’s understand the interfacing of relay with Arduino I amusing online simulation software (Tinker cad). Tinker cad helps to interface, code, and simulate online. All the components I have used are present in the software. You can also build your own circuit. All the components have been labeled in the above Figure. The push-button is connected  to pin2 whic...