SlideShare a Scribd company logo
Lecture07
INT4073
Technologies in STEM Education
design process
Analog Input Pins
A/D converter
The Arduino Uno contain an onboard 6 channel
analog-to-digital (A/D) converter.
The converter has 10 bit resolution, returning integers
from 0 to 1023.
While the main function of the analog pins for most
Arduino users is to read analog sensors, the analog
pins also have all the functionality of general purpose
input/output (GPIO) pins
Read Analog Data from Potentiometer
Code
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1000);
}
PWM (“Analog Output”)
Pulse Width Modulation, or PWM, is a technique for getting
analog results with digital means. Digital control is used to
create a square wave, a signal switched between on and
off. This on-off pattern can simulate voltages in between
the full Vcc of the board (e.g., 5 V on Uno) and off (0 Volts)
by changing the portion of the time the signal spends on
versus the time that the signal spends off. The duration of
“on time” is called the pulse width. To get varying analog
values, you change, or modulate, that pulse width. If you
repeat this on-off pattern fast enough with an LED for
example, the result is as if the signal is a steady voltage
between 0 and Vcc controlling the brightness of the LED.
Using Potentiometer to Control LED Light
analogRead (pin): Read the value of the specified
analog pin.
Return value: an integer between 0 to 1023
analogRead( ) function to read the analog input value,
and the input value range is between 0 to 1023.
Then use the analogWrite( ) function (PWM) to change
the LED light duty cycle, and the duty cycle range is 0
to 255.
Need to remap the range by using the map( ) function.
map(value, fromLow, fromHigh, toLow, toHigh): Map
data from one range to another
value: The data to be mapped.
fromLow: The lower limit of the current range.
formHigh: The upper limit of the current range.
toLow: The lower limit of the target range.
toHigh: The upper limit of the target range.
Return value: Remapped data
int ledPin = 3;
int sensorValue = 0;
int ledValue = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop() {
sensorValue = analogRead(A0);
ledValue = map(sensorValue,0,1023,0,255);
analogWrite(ledPin,ledValue);
Serial.println(sensorValue);
Serial.println(ledValue);
delay(1000);
}
Sensors (Inputs)
Photoresistor
Temperature Sensor (LM35)
Temperature and Humidity Sensor (DHT11)
Photoresistor
Uses a resistor divider to allow the high impedence
Analog input to measure the voltage.
Use analogRead() to convert the input voltage range,
0 to 5 volts, to a digital value between 0 and 1023 (10
bit resolution).
Code
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
delay(100);
}
Ex1:Measuring Temperature
by using Temperature Sensor
int val;
int tempPin = A0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = (val/1024.0)*5000;
float cel = mv/10;
Serial.print(“TEMPRATURE = ”);
Serial.print(cel);
Serial.print(“*C”);
Serial.println();
delay(1000);
}
DHT11 Sensor
The DHT11 is a basic, ultra low-cost digital
temperature and humidity sensor. It uses a capacitive
humidity sensor and a thermistor to measure the
surrounding air and spits out a digital signal on the
data pin (no analog input pins needed).
Its fairly simple to use, but requires careful timing to
grab data. The only real downside of this sensor is you
can only get new data from it once every 2 seconds,
the sensor readings can be up to 2 seconds old.
DHT11 Sensor
Technical Details
Low cost
3 to 5V power and I/O
2.5mA max current use during conversion (while
requesting data)
Good for 20-80% humidity readings with 5%
accuracy
Good for 0-50°C temperature readings ±2°C accuracy
No more than 1 Hz sampling rate (once every second)
Body size 15.5mm x 12mm x 5.5mm
How DHT11 Works
The DHT11 detects water vapor by measuring the
electrical resistance between two electrodes. The
humidity sensing component is a moisture holding
substrate with electrodes applied to the surface. When
water vapor is absorbed by the substrate, ions are
released by the substrate which increases the
conductivity between the electrodes. The change in
resistance between the two electrodes is proportional to
the relative humidity. Higher relative humidity decreases
the resistance between the electrodes, while lower
relative humidity increases the resistance between the
electrodes.
Ex2: Measure with DHT11 Sensor
Libraries
The Arduino environment can be extended through
the use of libraries, just like most programming
platforms.
Libraries provide extra functionality for use in
sketches, e.g. working with hardware or manipulating
data.
To use a library in a sketch, select it from Sketch >
Import Library.
A number of libraries come installed with the IDE, but
you can also download or create your own.
Standard Libraries
EEPROM - reading and writing to "permanent" storage
Ethernet - for connecting to the internet using the Arduino
Ethernet Shield, Arduino Ethernet Shield 2 and Arduino
Leonardo ETH
Firmata - for communicating with applications on the
computer using a standard serial protocol.
GSM - for connecting to a GSM/GRPS network with the
GSM shield.
LiquidCrystal - for controlling liquid crystal displays (LCDs)
SD - for reading and writing SD cards
Servo - for controlling servo motors
SPI - for communicating with devices using the Serial Peripheral
Interface (SPI) Bus
SoftwareSerial - for serial communication on any digital pins.
Version 1.0 and later of Arduino incorporate Mikal Hart's
NewSoftSerial library as SoftwareSerial.
Stepper - for controlling stepper motors
TFT - for drawing text , images, and shapes on the Arduino TFT
screen
WiFi - for connecting to the internet using the Arduino WiFi
shield
Wire - Two Wire Interface (TWI/I2C) for sending and receiving
data over a net of devices or sensors.
More Libraries
www.arduino.cc/reference/en/libraries/
For our DHT example, we use “DHTlib” which can be
found on the Library Manager
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
void setup(){
Serial.begin(9600);
}
void loop(){
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
Actuators(Outputs)
Motor:
DC
Servo
Stepper
Servo Motor
A servo motor (or servo) is a motor that allows for
precise control of angular position. Unlike DC motors
where we can only control the rotational speed and
the direction of rotation, a servo motor allows us to
control the angle of rotation. Tower Pro SG90 Micro
Servo is a tiny and lightweight servo commonly used
in small robots. SG90 servo can rotate approximately
180 degrees. The operating speed is about 0.1s for a
60-degree rotation.
0 degree 90 degrees 180 degrees
Control a Servo Motor
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(9);
}
void loop() {
myservo.write(180);
delay(100);
myservo.write(0);
delay(100);
myservo.write(90);
delay(100);
}
Use a potentiometer to control SG90
#include <Servo.h>
Servo myservo;
int sensorPin = A0;
int val;
void setup() {
myservo.attach(9);
}
void loop() {
val = analogRead(sensorPin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(10);
}
INT4073 L07(Sensors and AcutTORS).pdf

More Related Content

Similar to INT4073 L07(Sensors and AcutTORS).pdf

ARDUINO (1).pdf
ARDUINO (1).pdfARDUINO (1).pdf
ARDUINO (1).pdf
SoumikBanerjee43
 
Analog data transmission on rf module using arduino
Analog data transmission on rf module using arduinoAnalog data transmission on rf module using arduino
Analog data transmission on rf module using arduino
Sagar Srivastav
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
sdcharle
 
To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.
Ankita Tiwari
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
Elaf A.Saeed
 
Iot Workshop NITT 2015
Iot Workshop NITT 2015Iot Workshop NITT 2015
Iot Workshop NITT 2015
Srivignessh Pss
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
soma saikiran
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
SANTIAGO PABLO ALBERTO
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
sdcharle
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
mkarlin14
 
Development of a Low Cost, Reliable & Scalable Home Automation System.
Development of a Low Cost, Reliable & Scalable Home Automation System.Development of a Low Cost, Reliable & Scalable Home Automation System.
Development of a Low Cost, Reliable & Scalable Home Automation System.
imtiyazEEE
 
Animatronic hand controller
Animatronic hand controllerAnimatronic hand controller
Animatronic hand controller
Sabrina Chowdhury
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote control
VilayatAli5
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Jayanthi Kannan MK
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
salih mahmod
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
Satoru Tokuhisa
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.
Ankita Tiwari
 

Similar to INT4073 L07(Sensors and AcutTORS).pdf (20)

ARDUINO (1).pdf
ARDUINO (1).pdfARDUINO (1).pdf
ARDUINO (1).pdf
 
Analog data transmission on rf module using arduino
Analog data transmission on rf module using arduinoAnalog data transmission on rf module using arduino
Analog data transmission on rf module using arduino
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.To study the relay operation from digital control signal using LabVIEW.
To study the relay operation from digital control signal using LabVIEW.
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
 
Iot Workshop NITT 2015
Iot Workshop NITT 2015Iot Workshop NITT 2015
Iot Workshop NITT 2015
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATION
 
Arduino: Arduino starter kit
Arduino: Arduino starter kitArduino: Arduino starter kit
Arduino: Arduino starter kit
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 
Development of a Low Cost, Reliable & Scalable Home Automation System.
Development of a Low Cost, Reliable & Scalable Home Automation System.Development of a Low Cost, Reliable & Scalable Home Automation System.
Development of a Low Cost, Reliable & Scalable Home Automation System.
 
Animatronic hand controller
Animatronic hand controllerAnimatronic hand controller
Animatronic hand controller
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote control
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
Arduino اردوينو
Arduino اردوينوArduino اردوينو
Arduino اردوينو
 
Day1
Day1Day1
Day1
 
Anup2
Anup2Anup2
Anup2
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.
 

Recently uploaded

Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

INT4073 L07(Sensors and AcutTORS).pdf

  • 3. Analog Input Pins A/D converter The Arduino Uno contain an onboard 6 channel analog-to-digital (A/D) converter. The converter has 10 bit resolution, returning integers from 0 to 1023. While the main function of the analog pins for most Arduino users is to read analog sensors, the analog pins also have all the functionality of general purpose input/output (GPIO) pins
  • 4. Read Analog Data from Potentiometer
  • 5.
  • 6. Code void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue); delay(1000); }
  • 7. PWM (“Analog Output”) Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on Uno) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of “on time” is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and Vcc controlling the brightness of the LED.
  • 8.
  • 9.
  • 10. Using Potentiometer to Control LED Light analogRead (pin): Read the value of the specified analog pin. Return value: an integer between 0 to 1023 analogRead( ) function to read the analog input value, and the input value range is between 0 to 1023. Then use the analogWrite( ) function (PWM) to change the LED light duty cycle, and the duty cycle range is 0 to 255. Need to remap the range by using the map( ) function.
  • 11. map(value, fromLow, fromHigh, toLow, toHigh): Map data from one range to another value: The data to be mapped. fromLow: The lower limit of the current range. formHigh: The upper limit of the current range. toLow: The lower limit of the target range. toHigh: The upper limit of the target range. Return value: Remapped data
  • 12. int ledPin = 3; int sensorValue = 0; int ledValue = 0; void setup() { Serial.begin(9600); pinMode(ledPin,OUTPUT); } void loop() { sensorValue = analogRead(A0); ledValue = map(sensorValue,0,1023,0,255); analogWrite(ledPin,ledValue); Serial.println(sensorValue); Serial.println(ledValue); delay(1000); }
  • 13. Sensors (Inputs) Photoresistor Temperature Sensor (LM35) Temperature and Humidity Sensor (DHT11)
  • 15.
  • 16. Uses a resistor divider to allow the high impedence Analog input to measure the voltage. Use analogRead() to convert the input voltage range, 0 to 5 volts, to a digital value between 0 and 1023 (10 bit resolution).
  • 17. Code void setup() { Serial.begin(9600); } void loop() { int value = analogRead(A0); Serial.println(value); delay(100); }
  • 19. int val; int tempPin = A0; void setup() { Serial.begin(9600); } void loop() { val = analogRead(tempPin); float mv = (val/1024.0)*5000; float cel = mv/10; Serial.print(“TEMPRATURE = ”); Serial.print(cel); Serial.print(“*C”); Serial.println(); delay(1000); }
  • 20. DHT11 Sensor The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, the sensor readings can be up to 2 seconds old.
  • 21. DHT11 Sensor Technical Details Low cost 3 to 5V power and I/O 2.5mA max current use during conversion (while requesting data) Good for 20-80% humidity readings with 5% accuracy Good for 0-50°C temperature readings ±2°C accuracy No more than 1 Hz sampling rate (once every second) Body size 15.5mm x 12mm x 5.5mm
  • 22. How DHT11 Works The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.
  • 23.
  • 24.
  • 25. Ex2: Measure with DHT11 Sensor
  • 26. Libraries The Arduino environment can be extended through the use of libraries, just like most programming platforms. Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. To use a library in a sketch, select it from Sketch > Import Library. A number of libraries come installed with the IDE, but you can also download or create your own.
  • 27. Standard Libraries EEPROM - reading and writing to "permanent" storage Ethernet - for connecting to the internet using the Arduino Ethernet Shield, Arduino Ethernet Shield 2 and Arduino Leonardo ETH Firmata - for communicating with applications on the computer using a standard serial protocol. GSM - for connecting to a GSM/GRPS network with the GSM shield. LiquidCrystal - for controlling liquid crystal displays (LCDs) SD - for reading and writing SD cards Servo - for controlling servo motors
  • 28. SPI - for communicating with devices using the Serial Peripheral Interface (SPI) Bus SoftwareSerial - for serial communication on any digital pins. Version 1.0 and later of Arduino incorporate Mikal Hart's NewSoftSerial library as SoftwareSerial. Stepper - for controlling stepper motors TFT - for drawing text , images, and shapes on the Arduino TFT screen WiFi - for connecting to the internet using the Arduino WiFi shield Wire - Two Wire Interface (TWI/I2C) for sending and receiving data over a net of devices or sensors.
  • 29. More Libraries www.arduino.cc/reference/en/libraries/ For our DHT example, we use “DHTlib” which can be found on the Library Manager
  • 30. #include <dht.h> dht DHT; #define DHT11_PIN 7 void setup(){ Serial.begin(9600); } void loop(){ int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature = "); Serial.println(DHT.temperature); Serial.print("Humidity = "); Serial.println(DHT.humidity); delay(1000); }
  • 32. Servo Motor A servo motor (or servo) is a motor that allows for precise control of angular position. Unlike DC motors where we can only control the rotational speed and the direction of rotation, a servo motor allows us to control the angle of rotation. Tower Pro SG90 Micro Servo is a tiny and lightweight servo commonly used in small robots. SG90 servo can rotate approximately 180 degrees. The operating speed is about 0.1s for a 60-degree rotation.
  • 33. 0 degree 90 degrees 180 degrees
  • 34.
  • 36. #include <Servo.h> Servo myservo; void setup() { myservo.attach(9); } void loop() { myservo.write(180); delay(100); myservo.write(0); delay(100); myservo.write(90); delay(100); }
  • 37. Use a potentiometer to control SG90
  • 38. #include <Servo.h> Servo myservo; int sensorPin = A0; int val; void setup() { myservo.attach(9); } void loop() { val = analogRead(sensorPin); val = map(val, 0, 1023, 0, 180); myservo.write(val); delay(10); }