Подрубил его к тестовой программе в Arduino. Работает, честно выдает расстояние в сантиметрах в Serial Monitor.
// variables to take x number of readings and then average them
// to remove the jitter/noise from the DYP-ME007 sonar readings
const int numOfReadings = 10; // number of readings to take/ items in the array
int readings[numOfReadings]; // stores the distance readings in an array
int arrayIndex = 0; // arrayIndex of the current item in the array
int total = 0; // stores the cumlative total
int averageDistance = 0; // stores the average value
// setup pins and variables for DYP-ME007 sonar device
int echoPin = 2; // DYP-ME007 echo pin (digital 2)
int initPin = 3; // DYP-ME007 trigger pin (digital 3)
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds
unsigned long distance = 0; // variable for storing the distance (cm)
//setup
void setup() {
pinMode(initPin, OUTPUT); // set init pin 3 as output
pinMode(echoPin, INPUT); // set echo pin 2 as input
// create array loop to iterate over every item in the array
for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {
readings[thisReading] = 0;
}
// initialize the serial port, lets you view the
// distances being pinged if connected to computer
Serial.begin(9600);
}
// execute
void loop() {
digitalWrite(initPin, HIGH); // send 10 microsecond pulse
delayMicroseconds(10); // wait 10 microseconds before turning off
digitalWrite(initPin, LOW); // stop sending the pulse
pulseTime = pulseIn(echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low
distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm.
total= total - readings[arrayIndex]; // subtract the last distance
readings[arrayIndex] = distance; // add distance reading to array
total= total + readings[arrayIndex]; // add the reading to the total
arrayIndex = arrayIndex + 1; // go to the next item in the array
// At the end of the array (10 items) then start again
if (arrayIndex >= numOfReadings) {
arrayIndex = 0;
}
averageDistance = total / numOfReadings; // calculate the average distance
Serial.println(averageDistance, DEC); // print out the average distance to the debugger
delay(100); // wait 100 milli seconds before looping again
}
И что дальше? Полёт с огибанием голов? Ну Вы батенька зажрались 😃. Скоро квадрик как я кота в форточку погулять будете выпускать 😃
Ну это конечно для квадрика тоже. Но в целом план такой:
Поддержка высоты на коптере;
Избегание препятствий для роботка-игрушки для детей;
Автоматический гудок для велосипеда;
Я зажрался?!
Автоматический гудок для велосипеда;
Я зажрался?!
Обленился 😉
{"assets_hash":"a8b26fa7f6e768b07a72c8c9aadb9422","page_data":{"users":{"41b8a4ac3df9550077792e83":{"_id":"41b8a4ac3df9550077792e83","hid":5271,"name":"Prikupets","nick":"Prikupets","avatar_id":null,"css":""},"42c29f6a3df9550077790423":{"_id":"42c29f6a3df9550077790423","hid":7960,"name":"Cherkashin","nick":"Cherkashin","avatar_id":null,"css":""},"4dbfd8303df9550077753075":{"_id":"4dbfd8303df9550077753075","hid":87385,"name":"Лисяра","nick":"Лисяра","avatar_id":null,"css":""}},"settings":{"blogs_can_create":false,"blogs_mod_can_delete":false,"blogs_mod_can_hard_delete":false,"blogs_mod_can_add_infractions":false,"can_report_abuse":false,"can_vote":false,"can_see_ip":false,"blogs_edit_comments_max_time":30,"blogs_show_ignored":false,"blogs_reply_old_comment_threshold":30,"votes_add_max_time":168},"entry":{"_id":"4e09f1219970730077103440","hid":12083,"title":"Ультразвуковой модуль (DYP-ME007)","html":"<p>Пришел такой известный звуковой модуль: <a href=\"http://www.goodluckbuy.com/ultrasonic-wave-detector-ranging-module-distance-sensor.html\" class=\"link link-ext link-auto\" data-nd-link-type=\"autolink\" data-nd-link-orig=\"http://www.goodluckbuy.com/ultrasonic-wave-detector-ranging-module-distance-sensor.html\" target=\"_blank\" rel=\"nofollow noopener\">goodluckbuy.com/ultrasonic-wave-detector-ranging-m…</a></p>\n<p><img class=\"image\" data-nd-image-orig=\"http://www.goodluckbuy.com/images/detailed_images/sku_63979_0.jpg\" src=\"http://www.goodluckbuy.com/images/detailed_images/sku_63979_0.jpg\" alt referrerpolicy=\"no-referrer\"><br>\nПодрубил его к тестовой программе в Arduino. Работает, честно выдает расстояние в сантиметрах в Serial Monitor.</p>\n<!--cut-->\n<pre class=\"hljs\"><code>// variables to take x number of readings and then average them\n// to remove the jitter/noise from the DYP-ME007 sonar readings\nconst int numOfReadings = 10; // number of readings to take/ items in the array\nint readings[numOfReadings]; // stores the distance readings in an array\nint arrayIndex = 0; // arrayIndex of the current item in the array\nint total = 0; // stores the cumlative total\nint averageDistance = 0; // stores the average value\n\n// setup pins and variables for DYP-ME007 sonar device\nint echoPin = 2; // DYP-ME007 echo pin (digital 2)\nint initPin = 3; // DYP-ME007 trigger pin (digital 3)\n\nunsigned long pulseTime = 0; // stores the pulse in Micro Seconds\nunsigned long distance = 0; // variable for storing the distance (cm)\n\n//setup\nvoid setup() {\n pinMode(initPin, OUTPUT); // set init pin 3 as output\n pinMode(echoPin, INPUT); // set echo pin 2 as input\n // create array loop to iterate over every item in the array\n for (int thisReading = 0; thisReading < numOfReadings; thisReading++) {\n readings[thisReading] = 0;\n }\n // initialize the serial port, lets you view the\n // distances being pinged if connected to computer\n Serial.begin(9600);\n}\n\n// execute\nvoid loop() {\n digitalWrite(initPin, HIGH); // send 10 microsecond pulse\n delayMicroseconds(10); // wait 10 microseconds before turning off\n digitalWrite(initPin, LOW); // stop sending the pulse\n pulseTime = pulseIn(echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low\n distance = pulseTime/58; // Distance = pulse time / 58 to convert to cm.\n total= total - readings[arrayIndex]; // subtract the last distance\n readings[arrayIndex] = distance; // add distance reading to array\n total= total + readings[arrayIndex]; // add the reading to the total\n arrayIndex = arrayIndex + 1; // go to the next item in the array\n // At the end of the array (10 items) then start again\n if (arrayIndex >= numOfReadings) {\n arrayIndex = 0;\n }\n averageDistance = total / numOfReadings; // calculate the average distance\n Serial.println(averageDistance, DEC); // print out the average distance to the debugger\n delay(100); // wait 100 milli seconds before looping again\n}\n</code></pre>\n<p>Программу брал отсюда: <a href=\"http://www.elechouse.com/elechouse/images/product/Arduino%20Ultrasonic%20Range%20Detection%20Sensor/Arduino%20Ultrasonic%20Range%20Detection%20Sensor.pdf\" class=\"link link-ext link-auto\" data-nd-link-type=\"autolink\" data-nd-link-orig=\"http://www.elechouse.com/elechouse/images/product/Arduino%20Ultrasonic%20Range%20Detection%20Sensor/Arduino%20Ultrasonic%20Range%20Detection%20Sensor.pdf\" target=\"_blank\" rel=\"nofollow noopener\">elechouse.com/…/Arduino Ultrasonic Range Detection…</a><br>\nВ статье перепутаны выводы D2 и D3 - надо подключать, как в программе а не в статье.</p>\n","user":"41b8a4ac3df9550077792e83","ts":"2011-06-28T15:20:01.000Z","st":1,"cache":{"comment_count":3,"last_comment":"4e0ac95e9970730077162a51","last_comment_hid":3,"last_ts":"2011-06-29T06:42:38.000Z","last_user":"4dbfd8303df9550077753075"},"views":3489,"bookmarks":0,"votes":0},"subscription":null},"locale":"en-US","user_id":"000000000000000000000000","user_hid":0,"user_name":"","user_nick":"","user_avatar":null,"is_member":false,"settings":{"can_access_acp":false,"can_use_dialogs":false,"hide_heavy_content":false},"unread_dialogs":false,"footer":{"rules":{"to":"common.rules"},"contacts":{"to":"rco-nodeca.contacts"}},"navbar":{"tracker":{"to":"users.tracker","autoselect":false,"priority":10},"forum":{"to":"forum.index"},"blogs":{"to":"blogs.index"},"clubs":{"to":"clubs.index"},"market":{"to":"market.index.buy"}},"recaptcha":{"public_key":"6LcyTs0dAAAAADW_1wxPfl0IHuXxBG7vMSSX26Z4"},"layout":"common.layout"}