Étape 6: Programmation:-
Outil avec alarme automatique de mesure de distance #By Sourabh Kumar @ www.androroot.com
#include
Innovente lcd (12, 11, 5, 4, 3, 2) ; Broche diclaration pour LCD
int pingPin = 7 ; Broche diclaration pour capteur Trig d’ultrasons
int inPin = 8 ; Diclaration de broche pour l’écho des ultrasons
const int ronfleur = 9 ; La broche diclaration pour buzzer et conduit
longue durée, pouces, cm ;
int indec, cmdec ;
int inchconv = 147 ;
int cmconv = 59 ;
Chaîne s1, s2 ;
void setup()
{
LCD.Begin (8, 2) ; Type LCD modifiez-le selon vôtre lcd
pinMode (pingPin, sortie) ;
pinMode (inPin, entrée) ;
pinMode (vibreur, sortie) ;
}
void loop()
{
digitalWrite (pingPin, basse) ;
delayMicroseconds(2) ;
digitalWrite (pingPin, HIGH) ;
delayMicroseconds(10) ;
digitalWrite (pingPin, basse) ;
durée = pulseIn (inPin, HIGH) ;
po = microsecondsToInches(duration) ;
INDEC = (durée - pouces * inchconv) * 10 / inchconv ;
cm = microsecondsToCentimeters(duration) ;
cmdec = (durée - cm * cmconv) * 10 / cmconv ;
S1 = String(inches) + "." + String(indec) + « in » + "" ;
S2 = String(cm) + "." + String(cmdec) + « cm » + "" ;
lcd.setCursor (0, 0) ;
LCD.Print(S1) ;
lcd.setCursor(0,1) ;
LCD.Print(S2) ;
Delay(600) ;
Si (cm < = 15) //If quelque obstacle vient dans cette gamme (Mine = 15cm) commence à Buzzer. Changer en fonction de votre objectif.
{
digitalWrite (sonnerie, HIGH) ;
Delay(100) ;
digitalWrite (sonnerie, faible) ;
Delay(10) ;
lcd.setCursor(0,0) ;
LCD.Print ("Andro Ro") ;
lcd.setCursor(0,1) ;
LCD.Print("OT-Alarm") ;
Delay(800) ;
}
}
long microsecondsToInches(long microseconds)
{
retourner les microsecondes / inchconv ;
}
long microsecondsToCentimeters(long microseconds)
{
retourner les microsecondes / cmconv ;
}
Télécharger .ino fichier ici : http://www.androroot.com/2016/06/distance-measuri...