TOUCH BUTTON PROTECTION

Hi
Im in the state with my little program where again i dont know where to go.
Situation is simple.
One analog sensor connected to analogInput1 measures pressure and displaying value on the LCD.
2 touch buttons are connected thru AT42QT1070 goes to analogInput 2,4 and once pressed change state of pin 3 and pin 11 (2->3), (4->11).
Now,as we all know accidental touch is possible with this design.
What i would like to do is:

If no touch is detected (button pressed) within 10sec->inactivate outputs->to reactivate press and hold either button #2 or #4 for minimum 3 sec to enable output(2,11).

/*
  ANALOG PRESSURE SENSORS

 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int buttonPin = A4;  // the number of the pushbutton pin
const int buttonPin1 = A2;
const int outPin =  3;      // the number of the LED pin
const int outPin1 =  11;


int buttonState = 0;// variable for reading the pushbutton status
int buttonState1 = 0;
int sensorValue = 0;
int val = 0;  
int raw;
float voltage;
float pressure;       //pressure in psi


void setup() {
  Serial.begin(9600);

// set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
// Print a message to the LCD.
  lcd.setCursor(5, 0);
  lcd.print("valve");
  lcd.setCursor(3, 1);
  lcd.print("control");
  delay(500);
  lcd.clear();
  lcd.print("FL          ");
  


// initialize the LED pin as an output:
     pinMode(outPin, OUTPUT);  
     pinMode(outPin1, OUTPUT);  
// initialize the pushbutton pin as an input:
     pinMode(buttonPin, INPUT);  
     pinMode(buttonPin1, INPUT);  
}

void loop(){
// read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    buttonState1 = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
    if (buttonState == LOW) {     
// turn LED on:    
    digitalWrite(outPin, HIGH);  
  } 
   else {
// turn LED off:
    digitalWrite(outPin, LOW); 
  }
    if (buttonState1 == LOW) {     
// turn LED on:    
    digitalWrite(outPin1, HIGH);  
  } 
    else {
// turn LED off:
    digitalWrite(outPin1, LOW); 
  }

 
//Sensor #1
   raw = analogRead(A1);
   voltage = (float) raw / 1023.0 * 5.0;
   pressure = (((float)analogRead(A1) /    1023.0 * 5.0) - 0.5) * 37.5; 
      

  if (pressure<-10)
  {
     lcd.setCursor(3,0);
     lcd.print(pressure,0);
  }          
    if (pressure>-10)
  {
          lcd.setCursor(4,0);
          lcd.write(254);
          lcd.setCursor(3,0);
           lcd.print(pressure,0);
  }
    if (pressure>-100)
  {
            lcd.setCursor(5,0);
            lcd.write(254);
            lcd.setCursor(3,0);
            lcd.print(pressure,0);}
  }

Moderator edit: CODE TAGS. Why are they so difficult to add?

Can someone please suggest something or please direct me to the link... searched entire google with lack of results.

If no touch is detected (button pressed) within 10sec

Within 10 seconds of what? The creation of the universe? Starting the Arduino?

  lcd.setCursor(5, 0);
    lcd.print("valve");
      lcd.setCursor(3, 1);
        lcd.print("control");
          delay(500);
            lcd.clear();
               lcd.print("FL          ");

Knock
this
shit
off
now!

Im trying to say that the program is running and with those two buttons you can control vales. As soon as you stop pressing them i want to deactivate outputs,meaning no meater what you press there shouldnt be any reaction unless you press and hold for 3.seconds after that all outputs goes back to operate as normal

mOskit:
Hi
Im in the state with my little program where again i dont know where to go.
Situation is simple.
One analog sensor connected to analogInput1 measures pressure and displaying value on the LCD.
2 touch buttons are connected thru AT42QT1070 goes to analogInput 2,4 and once pressed change state of pin 3 and pin 11 (2->3), (4->11).
Now,as we all know accidental touch is possible with this design.
What i would like to do is:

If no touch is detected (button pressed) within 10sec->inactivate outputs->to reactivate press and hold either button #2 or #4 for minimum 3 sec to enable output(2,11).

/*

ANALOG PRESSURE SENSORS

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int buttonPin = A4;  // the number of the pushbutton pin
const int buttonPin1 = A2;
const int outPin =  3;      // the number of the LED pin
const int outPin1 =  11;

int buttonState = 0;// variable for reading the pushbutton status
int buttonState1 = 0;
int sensorValue = 0;
int val = 0; 
int raw;
float voltage;
float pressure;      //pressure in psi

void setup() {
  Serial.begin(9600);

// set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
// Print a message to the LCD.
  lcd.setCursor(5, 0);
  lcd.print("valve");
  lcd.setCursor(3, 1);
  lcd.print("control");
  delay(500);
  lcd.clear();
  lcd.print("FL          ");

// initialize the LED pin as an output:
    pinMode(outPin, OUTPUT); 
    pinMode(outPin1, OUTPUT); 
// initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT); 
    pinMode(buttonPin1, INPUT); 
}

void loop(){
// read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    buttonState1 = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
    if (buttonState == LOW) {   
// turn LED on:   
    digitalWrite(outPin, HIGH); 
  }
  else {
// turn LED off:
    digitalWrite(outPin, LOW);
  }
    if (buttonState1 == LOW) {   
// turn LED on:   
    digitalWrite(outPin1, HIGH); 
  }
    else {
// turn LED off:
    digitalWrite(outPin1, LOW);
  }

//Sensor #1
  raw = analogRead(A1);
  voltage = (float) raw / 1023.0 * 5.0;
  pressure = (((float)analogRead(A1) /    1023.0 * 5.0) - 0.5) * 37.5;

if (pressure<-10)
  {
    lcd.setCursor(3,0);
    lcd.print(pressure,0);
  }         
    if (pressure>-10)
  {
          lcd.setCursor(4,0);
          lcd.write(254);
          lcd.setCursor(3,0);
          lcd.print(pressure,0);
  }
    if (pressure>-100)
  {
            lcd.setCursor(5,0);
            lcd.write(254);
            lcd.setCursor(3,0);
            lcd.print(pressure,0);}
  }




Moderator edit: CODE TAGS. Why are they so difficult to add?

Please point where or how should i use CODE TAGS.

PaulS:
Within 10 seconds of what? The creation of the universe? Starting the Arduino?

  lcd.setCursor(5, 0);

lcd.print("valve");
      lcd.setCursor(3, 1);
        lcd.print("control");
          delay(500);
            lcd.clear();
              lcd.print("FL          ");



Knock
this
shit
off
now!

can you please check of my code looks right now?

mOskit:
Im trying to say that the program is running and with those two buttons you can control vales. As soon as you stop pressing them i want to deactivate outputs,meaning no meater what you press there shouldnt be any reaction unless you press and hold for 3.seconds after that all outputs goes back to operate as normal

I suggest you write a short program that just focuses on this requirement until you get it figured out. Then you can apply your new knowledge to the main project.

What do you mean by "stop pressing them"? Stop for how long?

Why do you want to deactivate the outputs? Surely you should be deactivating the inputs?

Are you even sure that this problem you are trying to guard against is a real problem? What would be the worst that would happen if you did nothing?

At the very least you need to write down a clear step-by-step description of what is needed - for your own benefit as well as ours.

...R

Thats what i am asking for. Where to start with, what commands should be used etc.
simple description:
2 touch buttons. One open water valve to fill tank second drains water from the tank. You choose either to set water level once is set you not pressing them to either add or drain but you still working around and accidently you still can touch with your shoulder either overfilling the rank or flooding the floor.
I dont know how to make any simpler.
its a tuff shitt for begginer without having explained each command like to proper idiot. Im a mechanical engineer and writing codes is just tuff to start for me as dont understand most what is in command description

mOskit:
writing codes is just tuff to start for me as dont understand most what is in command description

I had assumed that you had written the code in your opening Post and are not a complete beginner.
If you are a complete beginner then the best place to start is with the many examples that come with the Arduino IDE.

simple description:
2 touch buttons. One open water valve to fill tank second drains water from the tank. You choose either to set water level once is set you not pressing them to either add or drain but you still working around and accidently you still can touch with your shoulder either overfilling the rank or flooding the floor.

There is a huge amount of un-stated information in this paragraph - information you have, and we don't.
For example ...
What sort of button switches?
How are they connected to the Arduino?
How does the Arduino know which is a legitimate button push, and which is not?
Why not put a physical guard around the buttons so that big things like shoulders can't reach them?
Why not use a water level detector to prevent flooding?

...R

ok.
im using adafruit industries [u]Standalone 5-Pad Capacitive Touch Sensor Breakout - AT42QT1070[/u] im using only 2 input pins on this breakout board.
AT42QT1070 Output pin number 2 goes to analog input number 2, and AT42QT1070 output pin number 4 goes to analog input 4 in arduino.
Arduino output pins are digital output number 3 and number 11.
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(outPin, HIGH);
}
else {
// turn LED off:
digitalWrite(outPin, LOW);
}
if (buttonState1 == LOW) {
// turn LED on:
digitalWrite(outPin1, HIGH);
}
else {
// turn LED off:
digitalWrite(outPin1, LOW);
}

Now, its all about learning programing this is the reason I dont want to use any physical guard, flood detector is actually a good idea.
But firs i need to figure out how to lock the keypad.....
looking for similar solution like is in every smartphone with touchscreen. you just have to swipe or insert a code to have your screen active. if you not using your phone for about 30 seconds the screen goes dark and inactive.

mOskit:
Now, its all about learning programing this is the reason I dont want to use any physical guard, flood detector is actually a good idea.
But firs i need to figure out how to lock the keypad.....
looking for similar solution like is in every smartphone with touchscreen. you just have to swipe or insert a code to have your screen active. if you not using your phone for about 30 seconds the screen goes dark and inactive.

Use that short program to figure out how to lock the touch screen.

I think what you need is to keep track of how long it has been since a key was pressed and if it is too long (you have to decide what that is) then further key presses are ignored until some special event happens.

There are two ways to do that. You could make it so that, for example, a particular button needs to be pressed and held down for a preset time. Or you could ignore all input unless it is a preset sequence (i.e. a keycode).

The first of the two is probably the easiest.

You can use millis() to manage the timing as in the demo several things at a time and the Thread planning and implementing a program.

The trick with checking how long since a key was pressed is to reset the value of keyPressedMillis() (i.e. restart the count) every time a key is pressed.

...R

this is exactly what i`m trying to figure.
meaning as soon as the input goes LOW counter starts to count 10 second if in between those 10 seconds you press any button counter start counting from zero.
if counter hits 11 seconds than input is locked and nothing will be executed until any button will be pressed and held for minimum 3 seconds.

does this make sense what i`m saying??

Except that you can't really lock input and look for it at the same time can you?

What you can do is separate the input code and have it run regularly but make how the input code treats button activity change according to what has been done. Sometimes this is called modal or state behavior.

So you have mode for waiting for input that requires 3 seconds press to change to mode for input that also watches for 10 seconds with none that changes mode to waiting for input. 2 modes always running round and round.

The input code in input mode only passes key pressed info to the rest of the sketch through variables. Never do you put turn on/turn off code into the input code unless you want to grow a mess of spaghetti code.

Your input code puts values into one or more variables that if it's real simple, a turn on/off code segment watches for and acts upon (don't forget to clear the trigger variable) or if it's not real simple then make a decision code section and have that set the trigger variable(s).

ok but in this case you need human action is needed to change the button/program state (change 3sec to 10sec)
maybe setting outputs state HIGH/LOW within 10sec count and after that outputs goes to LOW only unless press and held 3 sec

mOskit:
ok but in this case you need human action is needed to change the button/program state (change 3sec to 10sec)
maybe setting outputs state HIGH/LOW within 10sec count and after that outputs goes to LOW only unless press and held 3 sec

The input code looks for human action and interprets button presses by what mode it is in. 2 modes:

In Wait For Input Mode it takes a 3 second press to pass along that a button is pressed and Change The Mode to Input Mode.
In input mode, every press is passed along and no press for 10 seconds makes Change The Mode back to Wait For Input Mode.

Run the sketch, first button press should take 3 seconds and then others can be quicker.

The input code should not set the outputs directly. That is the path to future spaghetti code. But maybe you need to spend a few years finding out why you should avoid that. I'd rather spare you the headaches.

sounds like a plan.
now i need a month to find some sample codes and get this working :smiley: as i still don`t get much.
Karma for you guys.
thnaks

What do you already know? How many Arduino Tutorial Examples have you worked through?

Have you seen (and bookmarked into one section or bookmarks) the references and various get started and more learning pages on the Arduino site itself? Really there's a beginner to intermediate course and manual worth right on site. Before you're done that, you will be able to get help from other sites but beware the internet that not everything is authority and some is idiots.

You need to know these right from the start.

See what you can learn from sections 1, 2, 3, and 5. Skip part 4, it teaches BAD habits.
All of the Examples are in your IDE. Open them from your FILE menu under Examples.

And here is the Reference page with links to the Libraries page and the base AVR C libraries.

In a month you will have better questions, for sure!

the code you see on the beginning of the post is mostly made by my self with a help from another page where guys helped me get the sensor reading right.
i have a book (arduino for dummies) than im reading right now. ive done all those sketches for beginners.
i have a big language barrier, especially to new technical things. im originally from Poland and it takes time until i understand what im reading especially when translator tell you totally something else than you expecting:).
So what cause me the most headache is to understand the reference page. this is why i asked to on the beginning to which references i have to use and explain those references like you would have to speak to a total idiot (e.g this is spoon-> its silver and you can eat soup with it) :smiley:

I just checked the International part of the forum and no Polish section.
No sections for many places, I am sorry to say.

So many people just use English and yours is not bad, I have seen worse right here in the USA!

Where are you now?

In this part of the forum are many Euro members. Perhaps a Polish speaker will contact you.
Maybe you could post in Polish at The Bar section and be easier to find?

I'm in UK at the moment and i think i will stay here for a while.
I'll crack on with it soon to see if i can produce something.
thanks for trying any way.