0% found this document useful (0 votes)
3 views18 pages

Lecture 3 Lab

The document provides an overview of sensor instrumentation, focusing on analog to digital conversion and the use of Arduino for reading and writing digital and analog values. It includes code examples for setting pin modes, reading button states, and using an LCD display. Additionally, it discusses the principles of voltage measurement and Ohm's law in the context of an Ohm meter.

Uploaded by

phandongnghi1810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

Lecture 3 Lab

The document provides an overview of sensor instrumentation, focusing on analog to digital conversion and the use of Arduino for reading and writing digital and analog values. It includes code examples for setting pin modes, reading button states, and using an LCD display. Additionally, it discusses the principles of voltage measurement and Ohm's law in the context of an Ohm meter.

Uploaded by

phandongnghi1810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

SENSORs &

instrumentation

Analog to Digital Coversion

Voltage & Ohm Meter

LECTURER: Quoc T. Huynh, PH.D


Bare minimum code
void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run
repeatedly:

}
PinMode

• A pin on arduino can be set as input or output by using


pinMode function.

• pinMode(13, OUTPUT); // sets pin 13 as output pin

• pinMode(13, INPUT); // sets pin 13 as input pin


Reading/writing
digital values
• digitalWrite(13, LOW); // Makes the output voltage
on pin 13 , 0V

• digitalWrite(13, HIGH); // Makes the output voltage


on pin 13 , 5V

• int buttonState = digitalRead(2); // reads the value of


pin 2 in buttonState
Analog to Digital
Coversion
• What is analog ?

• It is continuous range of voltage values (not just 0 or


5V)

• Why convert to digital ?

• Because our microcontroller only understands digital.


ADC in Arduino Uno
Converting Analog
Value to Digital
Quantanization the
signal
ADC in Arduino

• The Arduino Uno board contains 6 pins for ADC

• 10-bit analog to digital converter

• This means that it will map input voltages between 0


and 5 volts into integer values between 0 and 1023
Reading/Writing
Analog Values
• analogRead(A0); // used to read the analog value
from the pin A0

• analogWrite(2,128);
ADC Example
voltage MetER
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int VoltageValue = 0; // value read from the pot

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
s VoltageValue = analogRead(analogInPin);

// print the results to the serial monitor:


Serial.print(”Voltage = " );
Serial.print(VoltageValue);

// wait 2 milliseconds before the next loop


delay(2);
}
Voltage divider
voltage MetER
I2C
LCD
LCD
Install Library
LCD

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
// set the LCD address to 0x3F for a 16 chars and 2 line
display
void setup() {
lcd.init();
lcd.clear();
lcd.backlight();
// Make sure backlight is on // Print a message on both lines
of the LCD.
lcd.setCursor(2,0);
//Set cursor to character 2 on line 0
lcd.print("Hello world!");
lcd.setCursor(2,1); //Move cursor to character 2 on line 1
lcd.print("LCD Tutorial"); } void loop() { }
Ohm Meter
R2 = Vout * R1 / (Vin – Vout)
Ohm Meter
Auto range

You might also like