Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

JOB SHEET P4 : ANTARMUKA SENSOR

1 Tujuan Praktek :
a. Mengetahui cara menghubungkan (antarmuka) sensor ke board mikrokontroler Arduino Uno
b. Membuat aplikasi pengontrolan yang menggunakan komponen I/O : sensor dan LED

2 Alat/Komp onen :

No Perangkat/Komp onen Jumlah No Perangkat/Komp onen Jumlah


1 Board Arduino Uno 1 6 PIR 1
2 Kabel USB A-B 1 7 Distance Sensor GP2Y0A02 1
3 Protoboard 1 8 LED 1
4 LDR 1 9 Resistor 220 1
5 LM35 1 10 Kabel jumper Secukupnya

3 Kegiatan Praktek :
a. Rangkai dan ujilah sampai berhasil, aplikasi antarmuka sensor P4.1 sampai P4.4.
b. Rancang, rangkai, dan ujilah satu aplikasi antarmuka yang menggunakan sensor dan LED (DIY P4.5).
c. Buat dan kumpulkan Laporannya.

Page 1 of 7 | P4 - Antarmuka Sensor


 

Light Dependent Resistor (LDR) → Light Sensor LM35 → Temperature Sensor

Passive Infra Red (PIR) → Motion Sensor SHARP GP2Y0A02 IR → Distance Sensor

Page 2 of 7 | P4 - Antarmuka Sensor


P4.1 - LDR LIGHT SENSOR P4.2 - LM35 TEMPERATURE SENSOR

A. BLINKING RATE A. TEMPERATURE MONITOR

/* /*
LDR blinking rate sketch LM35 sketch
Blink a LED with a rate based on light intensity upon an LDR Prints the temperature to the Serial Monitor
*/ */

const int ledPin = 2; // LED connected to digital pin 2 const int lm35Pin = 0; // LM35 connected to analog input pin 0
const int ldrPin = 0; // connect LDR to analog input 0
void setup()
void setup() {
{ Serial.begin(9600);
pinMode(ledPin, OUTPUT); // enable output on the led pin }

Page 3 of 7 | P4 - Antarmuka Sensor


Serial.begin(9600);
} void loop()
{
void loop() int tempVal = analogRead(lm35Pin);
{ Serial.print(tempVal); Serial.print(" > ");
int rate = analogRead(ldrPin); // read the analog input float millivolts = (tempVal / 1024.0) * 5000;
Serial.println(rate); float celsius = millivolts / 10; // sensor output is 10mV / Celsius
digitalWrite(ledPin, HIGH); // set the LED on Serial.print(celsius);
delay(rate); // wait duration dependent on light level Serial.print(" degrees Celsius, ");
digitalWrite(ledPin, LOW); // set the LED off Serial.print( (celsius * 9)/ 5 + 32 ); // converts to fahrenheit
delay(rate); Serial.println(" degrees Fahrenheit");
} delay(1000); // wait for one second
}

B. DIMMER B. TEMPERATURE INDICATOR

Page 4 of 7 | P4 - Antarmuka Sensor


/* /*
LDR dimmer sketch LM35 sketch
Dim a LED based on light intensity upon an LDR Turn on a LED if temperature is greater than a threshold
*/ */

const int ledPin = 2; // LED connected to digital pin 2 const int lm35Pin = 0; // sensor connected to this analog pin
const int ldrPin = 0; // connect LDR to analog input 0 const int ledPin = 2; // digital output pin for LED
const int threshold = 25; // the degree that will turn on the LED
void setup()
{ void setup()
pinMode(ledPin, OUTPUT); {
Serial.begin(9600); Serial.begin(9600);
} pinMode(ledPin, OUTPUT);
}
void loop()
{ void loop()
int ldrVal = analogRead(ldrPin); {
Serial.println(ldrVal); int tempVal = analogRead(lm35Pin);
delay(200); long celsius = (tempVal * 500L) /1024; // 10 mV per degree celcius
ldrVal = constrain(ldrVal, 20,150); Serial.print(celsius);
int ledLevel = map(ldrVal,20,150, 255,0); Serial.print(" degrees Celsius: ");
analogWrite (ledPin, ledLevel); if(celsius > threshold)
} {
digitalWrite(ledPin, HIGH); // LED on
Serial.println("LED is ON");
}
else
{
digitalWrite(ledPin, LOW);
Serial.println("LED is OFF"); // LED off
}
delay(1000); // wait for one second
}

Page 5 of 7 | P4 - Antarmuka Sensor


P4.3 - PIR MOTION DETECTOR P4.4 - IR DISTANCE SENSOR

/*
PIR sketch
Turn on a LED if motion is detected /*
*/ IR-distance sketch
Display distance of object from Sharp Distance Sensor 2Y0A02
const int ledPin = 9; // choose the pin for the LED (on Serial Monitor)
const int pirPin = 2; // choose the input pin for the PIR sensor */

void setup() { const int irPin = 0; // choose the pin for the IR distance sensor
pinMode(ledPin, OUTPUT); // declare LED as output float irVal, cm; //Must be of type float for pow()
pinMode(pirPin, INPUT); // declare PIR as input
} void setup() {
Serial.begin(9600);
void loop() { }
int pirVal = digitalRead(pirPin); // read input value

Page 6 of 7 | P4 - Antarmuka Sensor


if (pirVal == HIGH) // check if the input is HIGH void loop() {
{ irVal = analogRead(irPin);
digitalWrite(ledPin, HIGH); // turn LED on if motion is detected //inches = 4192.936 * pow(sensorValue,-0.935) - 3.937;
delay(500); cm = 10650.08 * pow(irVal,-0.935) - 10;
digitalWrite(ledPin, LOW); // turn LED off delay(100);
} Serial.print("Distance (cm) : ");
} Serial.println(cm);
}

DIY 4.5

… .

Page 7 of 7 | P4 - Antarmuka Sensor


Page 8 of 7 | P4 - Antarmuka Sensor

You might also like