[c] praktikum3

Viewer

copydownloadembedprintName: praktikum3
  1. const int TRIGPIN = 6;
  2.  const int ECHOPIN = 7;
  3.  long timer;
  4.  int jarak;
  5.  
  6.  void setup()
  7.  {
  8.    Serial.begin(9600);
  9.    pinMode(ECHOPIN, INPUT);
  10.    pinMode(TRIGPIN, OUTPUT);
  11. }
  12.  
  13. void loop()
  14. {
  15.    digitalWrite(TRIGPIN, LOW);
  16.    delayMicroseconds(5);
  17.    digitalWrite(TRIGPIN, HIGH);
  18.    delayMicroseconds(5);
  19.    digitalWrite(TRIGPIN, LOW);
  20.    delayMicroseconds(5);
  21.  
  22.    timer = pulseIn(ECHOPIN, HIGH);
  23.    jarak = (timer/2)/29.1;
  24.    delay(1000);
  25.  
  26.    Serial.print("Jarak = ");
  27.    Serial.print(jarak);
  28.    Serial.print(" cm");
  29.    Serial.println();
  30. }

Editor

You can edit this paste and save as new:


File Description
  • praktikum3
  • Paste Code
  • 30 Jun-2022
  • 564 Bytes
You can Share it: