Differences

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

Link to this comparison view

pm:prj2022:cstan:5 [2022/05/25 13:55]
carlos_javier.del [Software Design]
pm:prj2022:cstan:5 [2022/05/25 14:32] (current)
carlos_javier.del [Concluzii]
Line 86: Line 86:
  
 Through the ultrasonic sensor we are going to detect the obstacle. We start programming by declaring the variables and constants. Through the ultrasonic sensor we are going to detect the obstacle. We start programming by declaring the variables and constants.
 +
 {{:​pm:​prj2022:​cstan:​psr6.png?​200|}} {{:​pm:​prj2022:​cstan:​psr6.png?​200|}}
 +
 We define the pins for the LEDs, for the ultrasonic sensor and for the Arduino buzzer. Then we declare 4 constants. The first one is the speed of sound converting from metres per second to centimetres per second. We do this by multiplying by 100. The next constants are the decision thresholds we marked earlier. We define the pins for the LEDs, for the ultrasonic sensor and for the Arduino buzzer. Then we declare 4 constants. The first one is the speed of sound converting from metres per second to centimetres per second. We do this by multiplying by 100. The next constants are the decision thresholds we marked earlier.
  
 +  ***__SET UP FUNCTION__**
 +
 +In the setup function we start the serial monitor and set the pins to the corresponding mode. The LEDs, the Trigger of the ultrasonic sensor and the buzzer are in output mode (OUTPUT). The Echo pin of the ultrasonic sensor is in INPUT mode.
 +
 +{{:​pm:​prj2022:​cstan:​psr7.png?​200|}}
 +{{:​pm:​prj2022:​cstan:​psr8.png?​200|}}
 +
 +  ***__LOOP FUNCTION__**
 +
 +The loop() function contains the code that will be repeated over and over again. This is where we are going to put all our algorithm, the one we have detailed above. I have split this function into several functions to make the code more readable.
 +
 +{{:​pm:​prj2022:​cstan:​psr9.png?​200|}}
 +
 +  ***__START ULTRASONIC SENSOR__**
 +
 +The first thing we do is to prepare the ultrasonic sensor. We do this with the function initiateTrigger() which sends a pulse. It starts in the low state for 2 milliseconds,​ then 10 milliseconds in the high state and finally we put it in the low state. This indicates that the signal will then be sent to be picked up by echo.
 +
 +{{:​pm:​prj2022:​cstan:​psr10.png?​200|}}
 +
 +  ***__CALCULATE DISTANCE OF OBJECTS__**
 +
 +Once the sensor is ready, we can use it to calculate the distance. We do this with the function calculateDistance(). It is a particular function as it will return a value. This is done by putting at the end (or wherever you want) the reserved word return followed by the value you want to return. All code below the return is not executed, so be careful. In this case I return the calculated distance inside the function which is a float variable.
 +The pulseIn function detects just that, and returns the elapsed time in microseconds. For this reason, it must be converted to seconds by multiplying by 0.000001, which is the same as dividing by 1,000,000. With this information we can now apply the formula to calculate the distance as a function of time and speed.
 +
 +{{:​pm:​prj2022:​cstan:​psr11.png?​200|}}
 +
 +  ***__TRIGGER ALERTS__**
 +
 +Once we have the distance calculated, we can decide whether we are in the situation to send an alert or not. Whenever the distance is below the first threshold (green LED threshold and the least restrictive),​ we will launch the corresponding visual and audible alert.
 +
 +{{:​pm:​prj2022:​cstan:​psr12.png?​200|}}
 +
 +  ***__FINAL CODE__**
 +
 +{{:​pm:​prj2022:​cstan:​psr13.png?​200|}} {{:​pm:​prj2022:​cstan:​psr14.png?​200|}} {{:​pm:​prj2022:​cstan:​psr15.png?​200|}} {{:​pm:​prj2022:​cstan:​psr16.png?​200|}}
 </​note>​ </​note>​
  
Line 97: Line 134:
 </​note>​ </​note>​
  
-===== Concluzii ​===== +===== Conclusions ​===== 
 +Testing the car sensor sensor car makes it easy for car drivers to park the car.
 ===== Download ===== ===== Download =====
  
pm/prj2022/cstan/5.1653476145.txt.gz · Last modified: 2022/05/25 13:55 by carlos_javier.del
CC Attribution-Share Alike 3.0 Unported
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