Catégorie : Électronique
Affichages : 5448

Sources :

L'idée est de pouvoir déterminer (grossièrement car le matériel utilisé a une précision de l'ordre de 3mm...) à quelle distance du matériau se trouve le laser afin de trouver rapidement la meilleure hauteur sans avoir à refaire la mise au point (la mise au point dépendant directement de la hauteur).

J'avais dans mon stock une carte Arduino Mega 2560, un détecteur à ultrason HC-SR04 ainsi qu'un écran LCD "LCD Keypad Shield", bref tout le matériel nécessaire pour pouvoir obtenir l'information sur la hauteur (attention, il ne s'agit pas de la hauteur absolue) à laquelle la sonde à ultrason se trouve. Il est facile ensuite de déduire la hauteur du laser si on connaît l'écart entre les 2 modules.

Voici le code d'après Richard Shonkwiler :

 

//  Compiled By: Richard Shonkwiler, Greenwood, Indiana

#include <LiquidCrystal.h> //Access the LCD Library
#include <NewPing.h>       //Access the New Ping Library
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Define the Pin Functions for the LCD Pinout
                           
    //Define the pins for the HC-SR04 ultrasonic sensor
                           
#define vcc 41 //Set 5+ volts for the vcc pin on the sensor
#define gnd 35  //Set ground for the sensor
#define TRIGGER_PIN  39 //Set for trigger 
#define ECHO_PIN     37 //Set for Echo
#define MAX_DISTANCE 200 // sets the maximum distance. This really does nothing here but can be used to 
                         // trigger the display or some other device to carry out another function once this
                         // value is reached.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // This is taken from the NewPing library to arrange the 
                                                    // calculations for measurments
 
void setup() {
 Serial.begin(9600); // Set the baud rate for Serial Display
 pinMode (vcc,OUTPUT); //Set pin vcc as an output
 pinMode (gnd,OUTPUT); // Set the gnd pin as an output
 lcd.begin(16,2); // Tell arduino how many charcters and lines your LCD has.
}
void loop() 
{                         // Dont forget me. I have to be here to tell the arduino where this section of code starts.
  digitalWrite(vcc,HIGH); // Set vcc as HIGH. (Turn it on to begin suppliing 5 volts to this pin)
  delay(100);             // Set a delay so things dont get scrambled
  int uS = sonar.ping();  // represent uS as a sonar ping. Thats more of the New Ping library working
  lcd.setCursor(0,0);     //Locate the first character position for the cursor on the LCD display
  Serial.print(uS / US_ROUNDTRIP_CM); //Print on the serial monitor the referanced sonar ping and the round trip 
                                      //calculation performed by the New Ping library
  //lcd.print(uS / US_ROUNDTRIP_CM); //Print on the LCD the referanced sonar ping and the round trip 
                                   //calculation performed by the New Ping library
  lcd.print(uS/6);   // permet d'obtenir une précision de l'ordre du mm                              
  Serial.println("cm"); // Add CM for centimeters to the end of the distance in serial monitior.
  lcd.print(" mm  "); //Add CM for centimeters to the end of the distance on the LCD.
  lcd.setCursor(0,2); // Starting cursor position of next line on LCD
  lcd.print(uS / US_ROUNDTRIP_CM);
  lcd.print(" cm  ");
}   //Dont forget me. I have to be here to tell the arduino where the end of this code section ends

 Conclusion :

Vu le manque de précision des mesures (comme annoncé plus haut), cette méthode est peu convaincante pour déterminer précisément la meilleure hauteur de travail du laser. Pour cela, il vaut mieux passer par un fichier test en Gcode permettant de tracer des lignes à différentes hauteurs (voir l'article sur le réglage de la hauteur du laser).