Multi function touch sensor

Hello,

Can anyone help me program 1 touch sensor to control multiple servos by the amount of taps to the sensor? Servo1 open one tap, servo 2 open on 2 taps, servo 3 open on 3 taps & all servos close on 4 taps?

By reading this, you can already tell I’m a noob lol

Will servo 2 be required to open before servo 1 or will they open in sequence ?

I ask because the first tap for servo 2 could be interpreted as the tap for servo 1

Each servo serves an individual function, what I 3d printed is an iron man arm from the shoulder to the forearm,

Servo 1 controls 6 servos as the forearm rockets that all open together with a touch sensor tap

Servo 2 controls the shoulder flap to move up & down also by a touch sensor tap

The bicep & the forearm each have a servo for them to open up to free your arm, those servos are separate from the servos used for the forearm rockets & shoulder.

Vey interesting, but you did not answer my question

Can you see the problem of differentiating between the tap for servo 1 and the first tap for servo 2 ?

I apologize, yes I see the interference between taps, what would your best approach be for this? So far I have the 6 forearm servos functioning properly, I’ve thought of using separate touch sensors for the other servos however I also have trouble coding multiple touch sensors, 1 touch sensor controls all servos connected to the arduino pins. My project is on ig if you’d like to take a look, my ig is Idreamof3d. I’m building an entire motorized iron man suit & have little knowledge about arduino :sweat:

Separate touch sensors for each function would make things considerably simpler

What problems do you have coding for them ?

I don’t exactly know how to assign each touch sensor to a specific servo

The clumsy but simple way to code it would be a series of if statements

if sensor 0 has become touched
  do this
else if sensor 1 has become touched
  do this
else if sensor 2 has become touched
  do this
end if

Note that you need to detect that a sensor has become touched rather than it is touched

1 Like

Clumsy is ok if it works correctly :joy:, I appreciate your help & im going to run tests

Hello idreamof3d

Consider this pseudo code:

touchSensor == touched ? servo.write(Open) : servo.write(Closed); 

hth

Have a nice day and enjoy coding in C++.

touchSensor == touched ? servo.write(Open) : servo.write(Closed);

What would go where the ? Is? May I have a bit more clarity with this?

Again I apologize for being such a noob

1 Like

The conditional operator (?: )

if (condition)
    statement1;
else
    statement2;

https://www.learncpp.com/cpp-tutorial/comma-and-conditional-operators/

Thank you! I’ll also look into this

This is for 1 touch sensor with multiple functions?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

int angle3 = -35;
myservo3.write(angle3);

The write() function takes positive integer as it's parameter

My apologies for that

Please edit your post and put < CODE > tags round the code

To do what you initially asked, you need to specify what the min/max interval is to identify adjacent taps.

Use millis() to achieve this, then count and act on those taps as needed.

Hello idreamof3d

Post the datasheet of touch sensor used.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.