daily pastebin goal
32%
SHARE
TWEET

TELOO

rabanialfarisi Sep 13th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Sharp IR GP2Y0A41SK0F Distance Test
  2. // http://tinkcore.com/sharp-ir-gp2y0a41-skf/
  3.  
  4. #define sensor A0 // Sharp IR GP2Y0A41SK0F (4-30cm, analog)
  5.  
  6. void setup() {
  7.   Serial.begin(9600); // start the serial port
  8.   pinMode(2, INPUT_PULLUP);
  9. }
  10.  
  11. void loop() {
  12.   int tombol = digitalRead(2); // baca pushbutton value
  13.   if (tombol == LOW) {
  14.     int rata2, persen, var;
  15.     float fo, fc, volts,distancefo, distance;
  16.     fc= 4;
  17.     rata2 = 0;
  18.    
  19.  
  20.       for (int i=0; i<200; i++) {
  21.       Serial.println("Mendeteksi Full Open");
  22.       volts = analogRead(sensor)*0.0048828125;  // value from sensor * (5/1024)
  23.       distancefo = 13*pow(volts, -1)-1; // worked out from datasheet graph
  24.       rata2 = rata2 + distancefo;
  25.       delay (25); // tunggu 25 ms each read
  26.       distancefo = rata2/200;
  27.       fo= distancefo;      
  28.       }
  29.    while (1){
  30.               volts = analogRead(sensor)*0.0048828125;  // value from sensor * (5/1024)
  31.               distance = 13*pow(volts, -1)-1; // worked out from datasheet graph
  32.               persen = (distance-fc)/(fo-fc)*100;
  33.               delay (500);
  34.               Serial.println (persen);
  35.              }// WHILE SEK IKI KOK MUK PISAN METU OUTPUT PERSEN E SHIEEEET FAAQ
  36.  
  37.   }
  38.   else {
  39.     Serial.println ("Posisikan valve pada Full Open");
  40.   }
  41. }
RAW Paste Data
Top