Percobaan I
ADC - Sensor LDR dengan Motor DC
1. Prosedur [Kembali]
- Rangkailah seperti rangkaian berikut
- Buka Arduino IDE dan masukan listing program
- Upload program ke arduino
- Variasikan nilai ADC dan amati keluarannya pada LCD
Gambar 1. Rangkaian Hardware
1. Arduino Uno
2. Sensor LDR
4. LCD
6. Baterai
7. Resistor
8. Motor Driver L293D
9. Kabel jumper
11. Potensiometer
Diagram Blok:
Gambar 1. Rangkaian Simulasi. Prinsip Kerja: Pada rangkaian percobaan 1 ini menggunakan sensor LDR dan Dip Switch yang berfungsi sebagai input, LCD dan Kipas berfungsi sebagai output.
|
4. Flowchart dan Listing Program [Kembali]
Flowchart:
Listing Program:
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int sw1 = 2;
int sws[]={3,4,7};
int numsw = 3;
int front = 6;
int back = 5;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
pinMode(sw1,INPUT);
for(int thesw = 0; thesw < numsw; thesw++){
pinMode(sws[thesw],INPUT);
}
pinMode(front,OUTPUT);
pinMode(back,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int s1 = digitalRead(sw1);
int ldr = analogRead(A0);
if(s1 == HIGH){
int activesw = 0;
for(int thesw = 0; thesw < numsw; thesw++){
if(digitalRead(sws[thesw]) == HIGH){
activesw++;
}
}
Serial.print("Number of Switch : ");
Serial.println(activesw);
delay(200);
switch(activesw){
case 0 :
lcd.clear();
lcd.setCursor(0,0);
lcd.print(ldr);
lcd.setCursor(0,1);
lcd.print("The LDR Value");
delay(200);
break;
case 1 :
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Running The");
lcd.setCursor(2,1);
lcd.print("Motor");
digitalWrite(front,HIGH);
digitalWrite(back,LOW);
delay(200);
break;
case 2 :
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LDR Value : ");
lcd.setCursor(13,0);
lcd.print(ldr);
if(ldr < 550){
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("turn Motor right");
digitalWrite(front,HIGH);
digitalWrite(back,LOW);
}else{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("turn Motor left");
digitalWrite(front,LOW);
digitalWrite(back,HIGH);
}
break;
case 3 :
int pwm = map(ldr,0,1023,0,255);
digitalWrite(back,LOW);
analogWrite(front,pwm);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PWM = ");lcd.print(pwm);
lcd.setCursor(0,1);
lcd.print(" Control ???");
delay(200);
break;
}
delay(10);
}else{
lcd.clear();
lcd.setCursor(4,0);
lcd.print("ELECTRONIC");
lcd.setCursor(0,1);
lcd.print("&INSTRUMENTATION");
delay(100);
}
}
Kondisi percobaan 1 sesuai modul 2
᭒ HTML↠ klik disini
᭒ Gambar Rangkaian ↠ klik disini
᭒ Video Demo ↠ klik disini
᭒ Listing Program ↠ klik disini
᭒ Video Demo ↠ klik disini
᭒ Listing Program ↠ klik disini
᭒ Download Datasheet ARDUINO UNO ↠ klik disini
᭒ Download Datasheet LCD 2X16 ↠ klik disini
᭒ Donwload Datasheet motor listirk ↠ Klik disini
᭒ Download Datasheet L293D ↠ Klik disini
Tidak ada komentar:
Posting Komentar