SlideShare a Scribd company logo
1 of 39
Download to read offline
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);
}
Lecture07 - Technologies in STEM Education

More Related Content

Similar to Lecture07 - Technologies in STEM Education

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 arduinoSagar Srivastav
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixelssdcharle
 
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 CourseElaf A.Saeed
 
ARDUINO AND ITS PIN CONFIGURATION
 ARDUINO AND ITS PIN  CONFIGURATION ARDUINO AND ITS PIN  CONFIGURATION
ARDUINO AND ITS PIN CONFIGURATIONsoma saikiran
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slidesmkarlin14
 
Arduino slides
Arduino slidesArduino slides
Arduino slidessdcharle
 
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
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote controlVilayatAli5
 
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.pdfJayanthi 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/2Satoru 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 Lecture07 - Technologies in STEM Education (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 Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 
Arduino slides
Arduino slidesArduino slides
Arduino 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

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Lecture07 - Technologies in STEM Education

  • 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); }