GMU:Home Made Bioelectronics/Marah Doleh/Docummentation of progress/Code on arduino

From Medien Wiki
< GMU:Home Made Bioelectronics‎ | Marah Doleh‎ | Docummentation of progress
Revision as of 12:36, 11 May 2022 by Faxi0847 (talk | contribs) (Created page with " // ULTRASONIC SENSOR int TRIG = 3; int ECHO = 2; int DURATION; int DISTANCE; void setup() { // ULTRASONIC SENSOR pinMode(TRIG, OUTPUT); pinMode(ECHO...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


// ULTRASONIC SENSOR
int TRIG = 3;
int ECHO = 2;
int DURATION;
int DISTANCE;



void setup() {  

  // ULTRASONIC SENSOR
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  // SERIAL
  Serial.begin(9600);
  
}
 
 
void loop() {
 
  digitalWrite(TRIG,HIGH);
  delay(1);
  digitalWrite(TRIG,LOW);
  DURATION = pulseIn(ECHO,HIGH);
  DISTANCE = DURATION / 58.2;

  if(DISTANCE > 0 && DISTANCE < 50 ){
    Serial.println(DISTANCE);
    delay(100);
  }
 
}