Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pt:examples:sensor:ultrasonic_distance [2015/12/16 16:54] – Criação deste novo documento. articapt:examples:sensor:ultrasonic_distance [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 19: Line 19:
 ===== Prática ===== ===== Prática =====
  
 +O HomeLab está equipado com o sensor de distância ultra-sônico Devantech SRF04/SRF05. O SRF04/SRF05 é apenas sensor e não dá informação directa sobre a distância. Além dos pins de alimentação, o sensor tem também um pino de disparo e um pino de eco. Uma diferença importante entre o SRF05 e o SRF04 é que é possível, no caso de SRF05, usar um único conector físico de pins para o disparador e o sinal de eco. Isto permite ao sensor usar o conector de três fios standard (alimentação, terra e sinal). Quando o pin de disparo está definido como high, o sensor gera ondas ultra-sónicas de 40 kHz com 8 períodos de duração. No momento do disparo, o pino de eco vai a high e assim continua até que o som refletido atinge o sensor de volta. Assim, o sinal de eco reflete, basicamente, o tempo durante o qual o som chega ao objeto e volta a partir do mesmo. Ao medir esse tempo, multiplicando-o depois pela velocidade do som e, por fim, dividindo o resultado por dois, é calculada a distância ao objecto.
  
- +Para usar o SRF04/SRF05 com o AVR, os pins de disparo e eco devem ser ligados alguns dos pins AVR. Para medir o tempoé adequado usar um temporizador de 16 bitspor exemplo o //timer3//De seguida é apresentada uma função que é baseada no controlador Atmega2561 que executa todos os processos de medição - gera o sinal do disparadorcomeça o temporizadormede o comprimento do sinal de eco e converte-o na distância em centímetrosA função  bloqueia o processadorsignificando que o mesmo é ocupado pela função até que o resultado da medição seja recebido mesmo que a medição demore muito tempoQuanto mais rápido o eco chegar mais rápido o resultado é retornadoSe o eco não chegara função espera por ele durante 36 ms e retorna 0. É importante deixar aproximadamente 20 ms de intervalo entre cada mediçãopara o som gerado durante a medição anterior se desvanecer e a nova medição não ser afetada por este. É importante notar que as ondas sonoras não se perturbam entre si quando vários sensores ultra-sônicos são usados ​​simultaneamente.
-HomeLab is equipped with Devantech SRF04/SRF05 ultrasonic distance sensor. SRF04/SRF05 is just a sensor and it does not give direct information about the distance. Besides the power supply pins the sensor has also triggering pin and a echo pin. One important difference between the sensor SRF04 and SRF05 is that it is possible in case of SRF05 use a single physical connector pins for the trigger and the echo signal. This allows the sensor to use the standard three-wire connector (power, ground and signal). When the triggering pin is set high the sensor generates 40 kHz ultrasonic wave which is 8 periods long. At that moment the echo pin becomes high and remains high until the reflected sound is reached back to the sensor. So the echo signal reflects basically the time during which the sound reaches to the object and comes back from the object. By measuring that time and multiplying it by the speed of sound and then divide it by two, is calculated the distance to the object.  +
- +
-To use the SRF04/SRF05 with the AVR, its trigger pin and echo pin should be connected to some of the AVR pins For measuring timeit is suitable to use a 16-bit timerfor example //timer3//Following is a function which is based on the Atmega2561 controller and executes all measuring procedures – it generates the signal of the triggerstarts the timermeasures the length of the echo signal and converts it to the distance in centimetersThe function is blockingmeaning the processor is occupied by it until the result of measuring is received or the measuring takes too long timeThe faster the echo arrives the faster the result is returnedIf the echo does not arrivethe function waits for it for 36 ms and returns to 0. It is important to leave approximately 20 ms break between each measuringto able the sound generated during the previous measuring to die out and the new measuring will not be affectedIt is important to notice that the sound waves don’t disturb each other, when several ultrasonic sensors are used simultaneously+
  
 <code c> <code c>
Line 87: Line 85:
 </code> </code>
  
-Presented function allows the user to choose the echo/trigger pin, so the sensor can be connected where it is more suitable or where is more spaceIn additionthe freedom of choosing the pins allows to use the function also elsewhere than only in the HomeLab. Presented function belongs already to the library of the HomeLab so it is not necessary to write itOne thing must be rememberedthe function in the library of the HomeLab is stiffly connected to the clock rate of the Controller module of the HomeLab. Using the function with other clock-ratesit would give incorrect resultTo use the function with other clock-ratesit should be written in the program manuallyFollowing code of program demonstrates the use of SRF04/SRF05 ultrasonic sensor with the library of the HomeLab. When connecting the sensor it is very important to observe the power polarityIncorrectly connected sensor becomes broken.+A função apresentada permite ao utilizador escolher o pin de eco/disparode modo que o sensor possa ser ligado onde é mais adequado ou onde existe mais espaçoAlém dissoa liberdade de escolher os pins permite utilizar a função também em outros dispositivos que não só no HomeLab. A função apresentada pertence já à biblioteca do HomeLab e não é necessário reescrevê-laUma coisa deve ser lembradaa função na biblioteca do HomeLab está rigidamente ligada à velocidade de relógio do módulo de controlo do HomeLab. Usando a função com outras frequências de relógioesta gerará resultados incorretosPara usar a função com outras frequências de relógioesta deve ser implementada manualmenteO código seguinte demonstra o uso do sensor ultra-sónico SRF04/SRF05 com a biblioteca do HomeLab. Ao ligar o sensor é muito importante observar a polaridade da fonteSensores incorretamente ligados ficam irremediavelmente estragados.
  
 <code c> <code c>
Line 162: Line 160:
 } }
 </code> </code>
-To make sure that the ultrasonic sensor actually start workingyou should check whether the small LED will flash every measurement which is located on the back of the sensor.+ 
 +Para se certificar-se de que o sensor ultra-sónico começou realmente a trabalhardeve verificar-se se o pequeno LED, que está localizado na parte de trás do sensor, pisca a cada medição.
pt/examples/sensor/ultrasonic_distance.1450284856.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0