DIT112-V19 / group-09

Arduino smartcar which maps its route across traveled walls
MIT License
6 stars 0 forks source link

Use Smartcar library's ultrasonic sensor instead of pulseIn #37

Closed platisd closed 5 years ago

platisd commented 5 years ago

In your smartcar.ino sketch you are using pulseIn directly which can be avoided if you just use an SR04 sensor and its getDistance() or getMedianDistance() method.

  digitalWrite(trigPinSide, LOW);
  delayMicroseconds(2); //delays are required for a successful sensor operation
  digitalWrite(trigPinSide, HIGH);

  delayMicroseconds(10); //this delay is required as well!
  digitalWrite(trigPinSide, LOW);
  duration = pulseIn(echoPinSide, HIGH);
  sideDistance = (duration / 2) / 29.1; //convert the distance to centimeters