[c] wkw
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- #define b 8
- const int TRIGPIN = 6;
- const int ECHOPIN = 7;
- long timer;
- int jarak;
- void setup(){
- Serial.begin(9600);
- pinMode(ECHOPIN,INPUT);
- pinMode(TRIGPIN,OUTPUT);
- pinMode(b,OUTPUT);}
- void loop(){
- digitalWrite(TRIGPIN,LOW);
- delayMicroseconds(5);
- digitalWrite(TRIGPIN,HIGH);
- delayMicroseconds(5);
- digitalWrite(TRIGPIN,LOW);
- delayMicroseconds(5);
- timer = pulseIn(ECHOPIN, HIGH);
- jarak = (timer/2)/29.1;
- Serial.print("Jarak = ");
- Serial.print(jarak);
- Serial.print(" cm");
- Serial.println();
- if(jarak <= 10) {
- Serial.print("Bahaya ");
- tone(8,1000);
- delay(100);
- noTone(b);
- delay(100);}
- else if (jarak <= 20 && jarak <=29 ){
- Serial.print("Awas ");
- tone(8,1000);
- delay(250);
- noTone(b);
- delay(250);}
- else {
- Serial.print("Aman ");
- tone(8,500);
- delay(1000);
- noTone(b);
- delay(1000);}
- }
- const int TRIGPIN = 6;
- const int ECHOPIN = 7;
- long timer;
- int jarak;
- int mobil = 0;
- void setup(){
- Serial.begin(9600);
- pinMode(ECHOPIN,INPUT);
- pinMode(TRIGPIN,OUTPUT);}
- void loop(){
- digitalWrite(TRIGPIN,LOW);
- delayMicroseconds(5);
- digitalWrite(TRIGPIN,HIGH);
- delayMicroseconds(5);
- digitalWrite(TRIGPIN,LOW);
- delayMicroseconds(5);
- timer = pulseIn(ECHOPIN, HIGH);
- jarak = (timer/2)/29.1;
- Serial.print(" Jarak = ");
- Serial.print(jarak);
- Serial.print(" cm");
- Serial.println();
- if(jarak <= 5) {
- mobil = mobil + 1;
- Serial.print("Jumlah Mobil yang masuk : ");
- Serial.print(mobil);
- delay(10000);}
- else{
- Serial.print("Jumlah Mobil yang masuk : ");
- Serial.print(mobil);}
- }
Editor
You can edit this paste and save as new:
File Description
- wkw
- Paste Code
- 30 Jun-2022
- 1.67 Kb
You can Share it:
Latest Code Pastes