Components and supplies
LDR, 5 Mohm
Resistor 10k ohm
3 mm LED: Red
DC Motor, 12 V
Dual H-Bridge motor drivers L293D
Arduino UNO
Ceramic Capacitive Rain Sensor
Tools and machines
Scissor, Electrician
Hot glue gun (generic)
Solder Wire, Lead Free
Drill / Driver, Cordless
Project description
Code
baru_tambah_delay.ino
arduino
1#define OutputDO 8 //nama alias pin 8 yaitu output DO 2int Ldr = A1; //inisialisasi 3int ldr; 4int en1= 6; //inisialisasi en1 masuk pwm yaitu 6 5int en2= 5; //inisialisasi en2 masuk pwm yaitu 5 6int in1= 2; //inisialisasi pin input1/in1 masuk pin 13 7int in2= 12; //inisialisasi pin input2/in2 masuk pin 12 8int in3= 11; //inisialisasi pin input3/in3 masuk pin 11 9int in4= 10; //inisialisasi pin input4/in4 masuk pin 10 10 11int OutputAO=A0; //nama alias pin AO yaitu Output AO 12int Led=13; //nama alias pin 13 yaitu LED 13 14 15int val;//val sebagai buffer data 16float sensor; //sebagai data buffer sensor 17 18void setup() { 19 pinMode(en1, OUTPUT); //pin en1 sebagai OUTPUT 20 pinMode(en2, OUTPUT); //pin en2 sebagai OUTPUT 21 pinMode(in1, OUTPUT); //pin in1 sebagai OUTPUT 22 pinMode(in2, OUTPUT); //pin in2 sebagai OUTPUT 23 pinMode(in3, OUTPUT); //pin in3 sebagai OUTPUT 24 pinMode(in4, OUTPUT); //pin in4 sebagai OUTPUT 25 26pinMode (Led, OUTPUT) ; //Defisini LED sebagai output 27pinMode (OutputDO, INPUT) ; //Defisini OutputDO sebagai input 28pinMode (OutputAO, INPUT) ; //Defisini OutputAO sebagai input 29pinMode (ldr, INPUT); 30 31//inisialisasi komunikasi serial 32Serial.begin(9600); 33 34} 35 36void hujan(){ 37 digitalWrite (Led, HIGH); 38 39 analogWrite(en1,125); 40 digitalWrite(in1,LOW); 41 digitalWrite(in2,HIGH); 42 43 analogWrite(en2,125); 44 digitalWrite(in3,LOW); 45 digitalWrite(in4,HIGH); 46 47 Serial.println("mundur"); 48 49} 50void mendung(){ 51 digitalWrite (Led, HIGH); 52 53 analogWrite(en1,125); 54 digitalWrite(in1,LOW); 55 digitalWrite(in2,HIGH); 56 57 analogWrite(en2,125); 58 digitalWrite(in3,LOW); 59 digitalWrite(in4,HIGH); 60 61 Serial.println("mundur"); 62} 63void terang(){ 64 digitalWrite (Led, LOW); 65 66 analogWrite(en1,125); 67 digitalWrite(in1,HIGH); 68 digitalWrite(in2,LOW); 69 70 analogWrite(en2,125); 71 digitalWrite(in3,HIGH); 72 digitalWrite(in4,LOW); 73 74 Serial.println("maju"); 75} 76void mati(){ 77 analogWrite(en1,0); 78 digitalWrite(in1,LOW); 79 digitalWrite(in2,LOW); 80 81 analogWrite(en2,0); 82 digitalWrite(in3,LOW); 83 digitalWrite(in4,LOW); 84 85 Serial.println("mati"); 86 delay(5000); 87} 88 89void loop() { 90sensor = analogRead(OutputAO);//Pembacaan nilai sensor 91Serial.println(sensor); //hasil akan ditampilkan di serial monitor 92 93ldr = analogRead(A1); 94Serial.print("ldr : "); 95Serial.println(ldr); 96//pembacaan nilai sensor (logika 1 dan 0) 97val = digitalRead (OutputDO); 98 99//Pengondisian 100 if (ldr <= 250 ) 101 { 102 if (sensor <=500) 103 //lampu led akan menyala 104 105 hujan(); delay(500); 106 mati(); delay(5000); 107 108 } 109 110 else if(ldr <= 250 ){ 111 if (sensor > 500){ 112 mendung(); delay(400); 113 mati(); delay(5000); 114 } 115 } 116 117else if(ldr >= 250 ){ 118 if (sensor > 500){ 119 terang(); delay(10 00); 120 mati(); delay(5000); 121 } 122 } 123} 124
baru_tambah_delay.ino
arduino
1#define OutputDO 8 //nama alias pin 8 yaitu output DO 2int Ldr = A1; //inisialisasi 3int ldr; 4int en1= 6; //inisialisasi en1 masuk pwm yaitu 6 5int en2= 5; //inisialisasi en2 masuk pwm yaitu 5 6int in1= 2; //inisialisasi pin input1/in1 masuk pin 13 7int in2= 12; //inisialisasi pin input2/in2 masuk pin 12 8int in3= 11; //inisialisasi pin input3/in3 masuk pin 11 9int in4= 10; //inisialisasi pin input4/in4 masuk pin 10 10 11int OutputAO=A0; //nama alias pin AO yaitu Output AO 12int Led=13; //nama alias pin 13 yaitu LED 13 14 15int val;//val sebagai buffer data 16float sensor; //sebagai data buffer sensor 17 18void setup() { 19 pinMode(en1, OUTPUT); //pin en1 sebagai OUTPUT 20 pinMode(en2, OUTPUT); //pin en2 sebagai OUTPUT 21 pinMode(in1, OUTPUT); //pin in1 sebagai OUTPUT 22 pinMode(in2, OUTPUT); //pin in2 sebagai OUTPUT 23 pinMode(in3, OUTPUT); //pin in3 sebagai OUTPUT 24 pinMode(in4, OUTPUT); //pin in4 sebagai OUTPUT 25 26pinMode (Led, OUTPUT) ; //Defisini LED sebagai output 27pinMode (OutputDO, INPUT) ; //Defisini OutputDO sebagai input 28pinMode (OutputAO, INPUT) ; //Defisini OutputAO sebagai input 29pinMode (ldr, INPUT); 30 31//inisialisasi komunikasi serial 32Serial.begin(9600); 33 34} 35 36void hujan(){ 37 digitalWrite (Led, HIGH); 38 39 analogWrite(en1,125); 40 digitalWrite(in1,LOW); 41 digitalWrite(in2,HIGH); 42 43 analogWrite(en2,125); 44 digitalWrite(in3,LOW); 45 digitalWrite(in4,HIGH); 46 47 Serial.println("mundur"); 48 49} 50void mendung(){ 51 digitalWrite (Led, HIGH); 52 53 analogWrite(en1,125); 54 digitalWrite(in1,LOW); 55 digitalWrite(in2,HIGH); 56 57 analogWrite(en2,125); 58 digitalWrite(in3,LOW); 59 digitalWrite(in4,HIGH); 60 61 Serial.println("mundur"); 62} 63void terang(){ 64 digitalWrite (Led, LOW); 65 66 analogWrite(en1,125); 67 digitalWrite(in1,HIGH); 68 digitalWrite(in2,LOW); 69 70 analogWrite(en2,125); 71 digitalWrite(in3,HIGH); 72 digitalWrite(in4,LOW); 73 74 Serial.println("maju"); 75} 76void mati(){ 77 analogWrite(en1,0); 78 digitalWrite(in1,LOW); 79 digitalWrite(in2,LOW); 80 81 analogWrite(en2,0); 82 digitalWrite(in3,LOW); 83 digitalWrite(in4,LOW); 84 85 Serial.println("mati"); 86 delay(5000); 87} 88 89void loop() { 90sensor = analogRead(OutputAO);//Pembacaan nilai sensor 91Serial.println(sensor); //hasil akan ditampilkan di serial monitor 92 93ldr = analogRead(A1); 94Serial.print("ldr : "); 95Serial.println(ldr); 96//pembacaan nilai sensor (logika 1 dan 0) 97val = digitalRead (OutputDO); 98 99//Pengondisian 100 if (ldr <= 250 ) 101 { 102 if (sensor <=500) 103 //lampu led akan menyala 104 105 hujan(); delay(500); 106 mati(); delay(5000); 107 108 } 109 110 else if(ldr <= 250 ){ 111 if (sensor > 500){ 112 mendung(); delay(400); 113 mati(); delay(5000); 114 } 115 } 116 117else if(ldr >= 250 ){ 118 if (sensor > 500){ 119 terang(); delay(10 00); 120 mati(); delay(5000); 121 } 122 } 123} 124
Downloadable files
fritzing_fix_bb_FRXrApJajz.jpg
fritzing_fix_bb_FRXrApJajz.jpg
Documentation
img-20190512-wa0019_564YTo8FaT.jpg
img-20190512-wa0019_564YTo8FaT.jpg
img-20190512-wa0019_564YTo8FaT.jpg
img-20190512-wa0019_564YTo8FaT.jpg
Comments
Only logged in users can leave comments
Binti_mufarida
0 Followers
•0 Projects
Table of contents
Intro
15
0