bangnaga

Arduino Servo, RFID, Potensio

Mar 28th, 2015
329
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LED_PIN 13
  2. #include <SoftwareSerial.h>
  3.  
  4. #include <Servo.h>  // Servo PIN 6 Digital
  5. Servo servo1;
  6.  
  7. int PinTimbangan = A0;    // Pin Sensor Timbangan di A0
  8. int NilaiTimbangan = 0;  // Nilai Awal Timbangan
  9.  
  10. SoftwareSerial RFID(2, 3);
  11. String Teks;
  12. String TeksCek;
  13. char c;
  14. void setup()
  15. {
  16.  
  17. Serial.begin(9600);
  18. RFID.begin(9600);
  19.      Serial.println("Mulai");  
  20.   servo1.attach(6); // Pin Servo di Digital 6
  21.   servo1.writeMicroseconds(1500);
  22.   tutuppalang1();
  23.  
  24. pinMode(LED_PIN, OUTPUT); //Sets LED pin as output
  25. digitalWrite(LED_PIN, LOW); //Turn off LED
  26. }
  27.  
  28.  
  29. void loop()
  30. {
  31.     NilaiTimbangan = analogRead(PinTimbangan);    
  32.     while(RFID.available()>0){
  33.     delay(5);
  34.     digitalWrite(LED_PIN, HIGH); //Turn on LED
  35.     c=RFID.read();
  36.     Teks += c;
  37.   }
  38.   if(Teks.length()>10) Cek();
  39. Teks="";
  40.  
  41. }
  42.  
  43. void Cek()
  44. {
  45. Teks=Teks.substring(1,11);
  46.  if (TeksCek != Teks) {
  47.     NilaiTimbangan = analogRead(PinTimbangan);  
  48.     Serial.print("Tag:");
  49.     Serial.print(Teks);
  50.     Serial.print("Timbangan:");    
  51.     Serial.println(NilaiTimbangan);    
  52.     digitalWrite(LED_PIN, LOW); //Turn off LED
  53.     TeksCek = Teks;
  54.     bukapalang1();
  55.    
  56.   }
  57. }
  58.  
  59.  
  60. void bukapalang1()
  61. {
  62.      servo1.write(90);  // Turn Servo Left to 45 degrees
  63.      delay(3000);  
  64.      tutuppalang1();
  65. }
  66. void tutuppalang1()
  67. {
  68.      servo1.write(180);  // Turn Servo Left to 45 degrees
  69.      delay(1000);  
  70. }
RAW Paste Data