capacitive sensor TP224 - locking code

Hello
I have had some nice advices here from members, thank you.

i'm trying to find a sketch to program a "locking 4 digit code" with a TP224 capacitive sensor.
Do you have one please ?
Regards
Philippe

What does "locking 4 digit code" mean ?

What does the program actually do ?
What have you tried ?

Hi Bob

I don't have any code ...

I mean : I would try to enter a 4 digit sequence to run/unlock a device.
Hope that helps
Kind regards

How about doing a search of the forum and/or using Google ?

How do you envisage entering digits using a touch sensor ?
Is there going to be a display showing the entered digits ?

What experience of the Arduino do you have ?

Think of it, and search accordingly, as two separate tasks -

  1. read a keypress from the sensor array
  2. implement a keypad unlock sequence

It is like saying, "I can't find a recipe for crushed kumquat cake". Of course, because nobody has made one before. But you can find cake recipes, and find out how to crush kumquats. Then you can make your own recipe.

Sorry as I'm not english native speaking...
I mean : I have a capacitive sensor with 4 pads (1 to 4 )
I would like to press them according to a sequence that will be recognized by the code and then it will activate something (let's say a simple LED to start..)
I've not found a code right now and I've tried to modify one without success ...
I can have the sensor working, (simply showing the pressed pads in the Arduino monitor)

Can you read the sensor and determine when it is activated regardless of the sequence ?

I've not found a code right now and I've tried to modify one without success ...

That is your code. Please post it. Don't forget to read the forum instructions on how to format and post code first.

You might also do a site search on 'pushbutton combination lock'.

thanks, the code below works right …

Then I would like the servo to run only one time when the right code is pressed … (everything else works)
Kind regards

#include <rgb_lcd.h>
#include <Servo.h>

Servo myservo;  
int pos = 0; 
rgb_lcd lcd;
const int b1 = 2;   //touch pad branché sur les entrées 2,3,4,5
const int b2 = 3;  
const int b3 = 4;  
const int b4 = 5;    
const int green =  13; // LED OK sur 13
const int orange =  12; // LED FAUX sur 12

int b1State = 0;
int b2State = 0;
int b3State = 0;
int b4State = 0;

int d1=0,d2=0,d3=0,d4=0;
boolean ouverturePorte;

void setup() {
  myservo.attach(7);
  lcd.begin(16, 2);
  pinMode(green, OUTPUT);
  pinMode(orange, OUTPUT);
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(b3, INPUT);
  pinMode(b4, INPUT);
}

void loop() {
  b1State = digitalRead(b1);
  b2State = digitalRead(b2);
  b3State = digitalRead(b3);
  b4State = digitalRead(b4);

  if(d4==1){
    digitalWrite(green, HIGH);
    lcd.clear();
    lcd.setRGB(0, 255, 0);
  // définit la couleur : R=rouge G=vert B=bleu
  // on choisit une valeur entre 0 et 255
    lcd.setCursor(0, 0);
    lcd.print("    code bon");
    {   
     for (int pos = 0; pos <= 90; pos++) {
    myservo.write(pos);
    delay(15);
  }
  delay(5000);
    for (int pos = 90; pos >= 0; pos--) {
    myservo.write(pos);
    delay(15);
    } 
    }
  }
   else
        {
    digitalWrite(green, LOW);
    lcd.setRGB(100, 100, 100);
    lcd.setCursor(0, 0);
    lcd.print("    composez");
    lcd.setCursor(0, 1);
    lcd.print("    le code");

         }
         
   if(b4State == HIGH){
    if(d1==0 && d2==0 && d3==0 && d4==0){d1=1;delay(300);}else{d1=0;d2=0;d3=0;d4=0;digitalWrite(orange, HIGH);delay(1000);digitalWrite(orange, LOW);} // premier chiffre du code
    }
  if(b3State == HIGH){
    if(d1==1 && d2==0 && d3==0 && d4==0){d2=1;delay(300);}else{d1=0;d2=0;d3=0;d4=0;digitalWrite(orange, HIGH);delay(1000);digitalWrite(orange, LOW);} // premier chiffre du code
    }
  if(b2State == HIGH){
    if(d1==1 && d2==1 && d3==0 && d4==0){d3=1;delay(300);}else{d1=0;d2=0;d3=0;d4=0;digitalWrite(orange, HIGH);delay(1000);digitalWrite(orange, LOW);} // premier chiffre du code
    }
  if(b1State == HIGH){
    if(d1==1 && d2==1 && d3==1 && d4==0){d4=1;delay(300);}else{d1=0;d2=0;d3=0;d4=0;digitalWrite(orange, HIGH);delay(1000);digitalWrite(orange, LOW);} // premier chiffre du code
    }
  }
    if(d1==1 && d2==1 && d3==1 && d4==0){d4=1;delay(300);}else{d1=0;d2=0;d3=0;d4=0;digitalWrite(orange, HIGH);delay(1000);digitalWrite(orange, LOW);} // premier chiffre du code

I'm sorry, but this code is very badly formed. Did you write it? The variable names give no clue about what they are used for, and you should never put so many statements on one line.

The way to have something run only once, is to create a variable that reflects the state. Like

bool servoHasRun = false;
...
void loop {
  if (servoHasRun == false)
  {
  ... do the one time things
  servoHasRun = true;
  }
  ... always do all the other things
}

for example

to make the servo run at any time, you

servoHasRun = false;

Thank you aarg

I did not write this code ... but it works.

Did you succeed in modifying the servo code?