counter with a switch for a DC motor

Hello,

We are currently programming an Arduino UNO in order to control a DC motor. The counter is in fact a switch in order to count the about-turn. Unfortunately, we don't successed with the code, is it possible to look at it please ? I believe it's more simple for someone who is familiar wirth the Arduino. Don't hesitate if you have any questions.

Thanks a lot ! Aurore

The code for openning :

void lecturecode(int code) { if ((code == codeouv) && (etatserrure == 0)) { // if the code is right and the lock is closed you can open it BTLEserial.println("Ouverture"); etatcompteur = compteur; // we register the state of the counter at the begining while (compteur != etatcompteur + 5) { // as the number of tour is not okay, the DC motor goes on digitalWrite(CIFORW_PIN,HIGH); } digitalWrite(CIFORW_PIN, LOW);// then, it stops BTLEserial.println("Serrure Ouverte"); etatserrure = 1; // the lock is openned

Le code du capteur :

void capteur() { etatcapteur = digitalRead(CAPT_PIN); // we register the state of the captor (the switch) if (etatserrure == 0){ // if the lock is closed if ((etatcapteur != lastetatcapteur) && (digitalRead(CAPT_PIN)==HIGH)){ // if there is a change in the state of the captor compteur = compteur + 1; // lastetatcapteur = etatcapteur; // } }

You will need to post all of your code. And PLEASE read the How to use the forum and put your code inside code tags to make it easy to read.

Am I correct to think that what you refer to as a switch is something to produce a pulse once for every revolution of the motor?

...R

Same thing as reading a key or button.