Étape 2: Programmation Arduino
Branchez votre Arduino sur ordinateur et regarder vers le haut pour le port (port COM windows) sur lequel l’Arduino est connecté à. M’en souviens. Vous en aurez besoin plus tard. Ensuite il suffit de télécharger ce code pour Arduino. Il suffit de remplir dans la longueur de l’objet , vous pouvez jouer avec d’autres variables trop si vous voulez.
int ldr = 0; int if_val = 1; int ldr_value = 0; unsigned long time; unsigned long time2; float time3; float sped = 0; int val; int start_val = 0; //analog pin to which LDR is connected float object_length = 5.5; //object length in cm int sensitivity = 40;//Less more sensitive, more less sensitive void setup() { Serial.begin(9600); //start serial monitor object_length = object_length * 1000; val = analogRead(ldr); start_val = val + sensitivity; }void loop() { ldr_value = analogRead(ldr); if (ldr_value > start_val){ if (if_val == 1){ if_val = 0; time = millis(); } else { } }else{ if(if_val == 0){ if_val = 1; time2 = millis(); time3 = (time2 - time); sped = (object_length / time3) / 100; Serial.println(sped); } } }