Becky Marshall

about - work - instagram

Experiment 1: Arduino depth sensing with immediate visual feedback

Sensor: HC-SR04


Hypotheses


What if I could send out a moving depth sensor and receive immediate visual feedback on terrain?

What if I used a "hotter/colder" approach to the visual feedback by using the colors red and blue?

Hardware build-out

I've used a mini breadboard here to prioritize lightweight portability and ease of attaching to something moving, like a floating inflatable.


SHOPPING LIST


Depth sensor HC-SR04 (Amazon)

Arduino Uno starter kit with RGB LED (Amazon)

RGB LED diodes, 100 (Amazon)

Mini breadboards, 6 (Amazon)

Software (Arduino)

// Define pins
int trigPin = 11;
int echoPin = 10;
int REDPin = 6;
int GREENPin = 3;
int BLUEPin = 5;
long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets trigPin as an Output
  pinMode(echoPin, INPUT); // Sets echoPin as an Input
  pinMode(REDPin, OUTPUT);
  pinMode(GREENPin, OUTPUT);
  pinMode(BLUEPin, OUTPUT);
  Serial.begin(9600); //Prepares serial monitor
}

void loop() {
  digitalWrite(trigPin, LOW); // Turns trigPin off
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // Turns trigPin on
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // Reads echoPin, sets duration in microseconds
  distance = duration*0.034/2; // Calculates distance based on speed of sound in air

  Serial.print("Distance: "); // Sends distance to Serial Monitor
  Serial.println(distance);
  delay(50); // Choose frequency of readings

  int BLUEbrightness = map(distance, 4, 50, 0, 20); //Remaps distance numbers to brightness
  int REDbrightness = map(distance, 4, 50, 20, 0); // Remaps the inverse for another color
  analogWrite(REDPin, REDbrightness);
  analogWrite(BLUEPin, BLUEbrightness);
  analogWrite(GREENPin, 0);
  delay (50);
}

Learnings




  • The biggest leverage point here is the mapping parameters. The shift from red to purple to blue can be as subtle or stark as you wish, based on chosen numbers. Play around with yours.

  • The red/blue communication scheme was effective, although the RGB appeared pink and fuchsia rather than purple in between. This could be tweaked using the parameters mentioned above.
  • Noise in the system = ouchy bright flashes. Programmatically kill the noise with an if/else loop:

     if (distance > 3000) {
        analogWrite(REDPin, 0);
        analogWrite(GREENPin, 0);
        analogWrite(BLUEPin, 0);
      }

      else {...

Experiment 2: Underwater depth sensing with haptic feedback

Sensor: JSN-SR04T-2.0


Hypotheses


Can I collect depth measurements to map underwater terrain by floating a waterproof ultrasonic transducer on a body of water?

How might we get immediate feedback for the experiment? Using haptics? We must not rely on good light or noise conditions.

Hardware build-out

I taught the vibration motor to report readings with a simple code of short buzzes to represent 10 centimeters and long buzzes to represent 1 meter (see code below). The vibration motor reports a reading, then begins again once finished reporting. The mini breadboard is better portable in the field. After flashing the code over, draw power from a power bank so you don't have to carry your laptop into the lake like I did.


SHOPPING LIST


Waterproof Ultrasonic Transducer JSN-SR04T-2.0 (Amazon)

Small vibration motors (Amazon)

Small power bank (Amazon)

Mini breadboards, 6 (Amazon)

Arduino Uno starter kit (Amazon)

Software (Arduino)

// Define pins
int trigPin = 11;
int echoPin = 10;
int motorPin = 13;
long duration;
int distance;

//Program the length of pause between buzzes
int pause = 75;

//declare functions for one 10 cm buzz, one meter buzz, and a full stop
void decimeter() {
  analogWrite(motorPin,0);
  delay(pause);
  analogWrite(motorPin,150);
  delay(150); //make the decimeter buzz last 150 milliseconds
  }

void meter() {
  analogWrite(motorPin,0);
  delay(pause);
  analogWrite(motorPin,150);
  delay(550); //make the meter buzz last 550 milliseconds
  }

void fullstop() {
  analogWrite(motorPin,0);
  delay(1000); //make a full stop last 1000 milliseconds aka one second
  }

//declare a function named hapticFeedback that takes an input of "n"
void hapticFeedback(int n) {

  if (n < 100 && n >=80) { //if distance measured is less than 1 meter (within range)
  int x = n/10; //divide distance into decimeters
  for (int i = 0; i < x; i++) {// Loop to do something x times, starting at zero
    decimeter(); //call the 10 cm buzz function
    }
  fullstop(); //full stop when done
  }

  else if (n >= 100 && n <= 1600) { //if distance is at least 1 meter
    int x = n/100; //divide distance into meters
    for (int i = 0; i < x; i++) {// Loop to do something x times, starting at zero
    meter(); //call the meter buzz function
    }
  fullstop(); //full stop when done
  }

  else {
    analogWrite(motorPin,0); //noise readings (out of range) give no feedback
    }
  }

void setup() {
  pinMode(trigPin, OUTPUT); // Sets trigPin as an Output
  pinMode(echoPin, INPUT); // Sets echoPin as an Input
  pinMode(motorPin, OUTPUT); // Sets motorPin as an Output
  Serial.begin(9600);
 }

void loop() {
  digitalWrite(trigPin, LOW); // Turns trigPin off
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // Turns trigPin on
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // Reads echoPin, sets duration in microseconds
  distance = duration*0.148/2; // Calculates distance based on speed of sound in water

  Serial.print("Distance: "); // Sends distance to Serial Monitor
  Serial.println(distance);
  delay(50); // Choose frequency of readings

  hapticFeedback(distance); //calls hapticFeedback function
 }

Learnings




  • Well, after all that, the JSN-SR04T-2.0 simply does not work underwater. A waterproof sensor is not the same thing as an underwater sensor. Underwater sonar costs a lot more money. If you want to hear a success story of someone rigging a $100 sensor to measure a 50 ft tank, read this forum thread.

  • For another successful example, here's a video of someone hacking a fish finder for its underwater transducer.

  • The haptic feedback loop worked well for on-the-fly readings in a variety of settings: low light and bright light, and in noisy, busy public places.
about - work - instagram