Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:sensor:ultrasonic_distance [2015/11/10 12:24] heikopikneren:examples:sensor:ultrasonic_distance [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Ultrasonic distance sensor ====== ====== Ultrasonic distance sensor ======
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:controller]], [HW] [[en:hardware:homelab:digi]], [AVR] [[en:avr:timers]], [LIB] [[en:software:homelab:library:timer]], [LIB] [[en:software:homelab:library:module:lcd_graphic]], [LIB] [[en:software:homelab:library:module:sensor]]//+//Necessary knowledge:  
 +[HW] [[en:hardware:homelab:digi]],  
 +[AVR] [[en:avr:timers]],  
 +[LIB] [[en:software:homelab:library:timer]], \\ 
 +[LIB] [[en:software:homelab:library:module:lcd_graphic]], [LIB] [[en:software:homelab:library:module:sensor]] //
  
 ===== Theory ===== ===== Theory =====
Line 21: Line 25:
 <code c> <code c>
 #define ULTRASONIC_SPEED_OF_SOUND 33000 // cm/s #define ULTRASONIC_SPEED_OF_SOUND 33000 // cm/s
- 
  
 // Ultrasonic distance measuring // Ultrasonic distance measuring
Line 82: 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 space. In addition, the 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 it. One thing must be remembered: the 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-rates, it would give incorrect result. To use the function with other clock-rates, it should be written in the program manually. Following code of program demonstrates the use of SRF04/SRF05 ultrasonic sensor with the library of the HomeLab.    +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 space. In addition, the 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 it. One thing must be remembered: the 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-rates, it would give incorrect result. To use the function with other clock-rates, it should be written in the program manually. Following 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 polarity. Incorrectly connected sensor becomes broken.
  
 <code c> <code c>
-// 
 // The example program of the ultrasonic distance sensor of the HomeLab // The example program of the ultrasonic distance sensor of the HomeLab
 // Measuring the distance is blocking. // Measuring the distance is blocking.
-// 
 #include <stdio.h> #include <stdio.h>
 #include <homelab/pin.h> #include <homelab/pin.h>
Line 95: Line 96:
 #include <homelab/module/lcd_gfx.h> #include <homelab/module/lcd_gfx.h>
  
-// 
 // Pins of ultrasonic sensor // Pins of ultrasonic sensor
 // Robotic HomeLab II // Robotic HomeLab II
-pin pin_pin_trigger_echo = PIN(F, 2);+//pin pin_pin_trigger_echo = PIN(F, 2);
  
 // Robotic HomeLab III // Robotic HomeLab III
Line 124: Line 124:
  
  // Line selection  // Line selection
- lcd_gfx_goto_char_xy(1,2);+ lcd_gfx_goto_char_xy(1,1);
    
  // Name of the program  // Name of the program
Line 133: Line 133:
  
   // Endless loop.   // Endless loop.
- while (true)+ while (1)
  {  {
  // Measuring  // Measuring
Line 142: Line 142:
  {   {
  // converting the distance to text.  // converting the distance to text.
- sprintf(text, "%cm   ", distance);+ sprintf(text, "%3d cm   ", distance);
  }  }
  // Were there errors during the measuring ?  // Were there errors during the measuring ?
Line 160: Line 160:
 } }
 </code> </code>
-If older type sensor (SRF04) is used, then see page: \\ http://home.roboticlab.eu/en/examples/sensor/ultrasonic_distance_srf04+To make sure that the ultrasonic sensor actually start working, you should check whether the small LED will flash every measurement which is located on the back of the sensor.
en/examples/sensor/ultrasonic_distance.1447158276.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