Rangefinder and Tip the Can info from RoboSumo lecture on Wed 19th Feb 2020

Tip the Can date and robot compliance (max size and weight):

Precendence of criteria for ranking Tip the Can results:

Three things you probably need to get working to successfully complete Tip the Can:

Connecting the HC-SR04 rangefinder sensor to the Arduino Nano:

Example HC-SR04 trigger and echo waveforms:

This was the example code I wrote during the lecture (with some modifications):

  1. I made a factor of ten error in calculating the threshold duration of the echo pulse – it should have been 4.7ms rather than 47ms.
  2. I’ve added a longer delay at the end of the loop function so that it leaves time for any ultrasound echoes in the room to dissipate before going back to the start of the loop function and triggering the next ultrasound pulse.
//
// HC-SR04 rangefinder example for Arduino Nano
// Written by Ted Burke - last updated 19-Feb-2020
//
// This example triggers readings from the HC-SR04 rangefinder
// repeatedly and switches an LED on or off depending on whether
// an object is detected withing 80 cm of the sensor.
//

void setup()
{
  pinMode(2, OUTPUT); // LED pin
  pinMode(6, OUTPUT); // trigger pin
  pinMode(7, INPUT);  // echo pin
}

void loop()
{
  // Send 20 us trigger pulse from Arduino to rangefinder
  digitalWrite(6, HIGH);
  delayMicroseconds(20);
  digitalWrite(6, LOW);

  // Wait for the time it take sound to travel 2 x 80cm
  delayMicroseconds(4700); // 4.7 ms

  // Check if echo pulse has ended or not
  if (digitalRead(7) == 1)
  {
    // Pulse is still active -> no objects within the 80cm threshold
    digitalWrite(2, LOW); // LED off
  }
  else
  {
    // Pulse has ended -> an object is within the 80cm threshold
    digitalWrite(2, HIGH); // LED on
  }

  // Leave a delay to allow any ultrasound echoes in the room to
  // dissipate before triggering another pulse
  delay(50);
}
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s