BlueSun ESP8266 WiFi 'o' Sonar

Continuing the theme with my ESP8266 WiFi "Wonder" chips.

First experiment in making a sonar scanner for remotely displaying depth/distance mapping.

The MaxSonar EZ0 is mounted via a 3D printed mount directly to a simple stepper motor.

The Stepper motor is controlled directly from the ESP8266 output pins.

The sensor can be rotated for a true 360° scan (something a servo would die for, many have died trying).

The distancing probe measures distance via ultrasonic >>Ping<< waves, the output is an analogue signal that can be fed into the ADC input of the ESP8266 module.

As the output data (below is a 360° scan, blueSun is the central origin of the probe) is presented using HTML5 code a simple Web browser enables easy viewing of data.

(Gareth predicts an end to all forms of LCD displays in lieu of IOT browsers ).

For those following along the STL file for printing the mount can be found here :-

BlueSun WiFi 'o' Sonar

The Web Gui bits to the code
void drawGraph() {
    String out = "";   // Press the string reset button to zero
     char temp[100];
    out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1000\" height=\"800\">\n";
     out += "<g stroke=\"black\">\n";  // set of the SVG graphic plane.
  out += "<circle cx=\"400\" cy=\"400\" r=\"20\"  fill=\"rgb(160,160,250)\" />\n";   /BlueSun Logo

  int y1 = 0; int y2=0;  int x1 = 0; int x2=0;  int z =0;  int ana = 0;    z=0; // lazy setting up of variables

   ana= analogRead(A0);
       y2 =  +ana * sin( float(z)/3142.0 * 2.0 * PI  );        // preseed the XY to make line command below happy
       x2 =  +ana * cos( float(z)/3142.0 * 2.0 * PI  );
 
    for (int z = 0; z < 3142; z+=66) {                              //  number of segments to scan at 66 intervals
       ana= analogRead(A0);
       y1 =  + ana * sin( float(z)/3142.0 * 2.0 * PI  );       // convert to display angular data
       x1 =  + ana * cos( float(z)/3142.0 * 2.0 * PI  );
 
     for (int i=0; i <= 3; i++){     // drive the stepper a couple of degrees
      digitalWrite(12,LOW);   digitalWrite(14,HIGH);  delay(stepper);
      digitalWrite(16,LOW);   digitalWrite(13,HIGH);  delay(stepper);
      digitalWrite(14,LOW);   digitalWrite(12,HIGH);  delay(stepper);
      digitalWrite(13,LOW);   digitalWrite(16,HIGH);  delay(stepper);
  }
      sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"5\" />\n", 272+x1, 528 - y1, 272+x2 , 528 - y2);
         out += temp;
         y2 = y1;
    x2 = x1;
     }
    out += "</g>\n</svg>\n";                                 // output the generated svg graphic to web browser
    server.send ( 200, "image/svg+xml", out);

  for (int i=0; i <= 456; i++){         // take stepper back to start of scan (so wires do not get twisted over 360°)
   digitalWrite(13,LOW);   digitalWrite(16,HIGH);  delay(stepper);
   digitalWrite(14,LOW);   digitalWrite(12,HIGH);  delay(stepper);
   digitalWrite(16,LOW);   digitalWrite(13,HIGH);  delay(stepper);
   digitalWrite(12,LOW);   digitalWrite(14,HIGH);  delay(stepper);
   }
}