coding for to and fro motion of piezo actuator

The motion of the Piezo actuator displaces with the increase in control voltage, and again displaces back with the decrease in control voltage.

this to and fro motion of the actuator will be controlled by arduino.

For advancing the actuator, I am using this code,

int led_pin = 11;
int led_pin1 = 10; //Initializing LED Pin

void setup()
{
Serial.begin(9600);
pinMode(led_pin, OUTPUT); //Declaring LED pin as output
}

void loop()
{

for(int i=0; i<255; i++) //Fading the LED
{
analogWrite(led_pin, i);
analogWrite(led_pin1, i);
int j=i*2;
Serial.println(j);
delay(1000);

}

}

to retrace back to the original position. I request your help.

please can you share me a coding on to and fro motion of an actuator controlled by voltage.

Your mystery piezo requires an AC voltage. A piezo will move one direction on a + voltage and back to center on 0 voltage.

Paul

If this code successfully walks the actuator from one end of travel to the other

 for(int i=0; i<255; i++)    //Fading the LED
  {
    analogWrite(led_pin, i);
    analogWrite(led_pin1, i);
    int j=i*2;
    Serial.println(j);
    delay(1000);
  }

The I assume that this snippet would walk it back

 for(int i=255; i>0; i--)
  {
    analogWrite(led_pin, i);
    analogWrite(led_pin1, i);
    int j=i*2;
    Serial.println(j);
    delay(1000);
  }

The delay(1000) seams long to me. That is a full second, making the sweep in one direction take 4 minutes 15 seconds. If that is your intent, then you are good. If you want it quicker, try smaller values than the 1000 that you have.

Thank you so much, my piezo is working

@arjita

Other post/duplicate DELETED Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here. It will help you get the best out of the forum in the future.