Coding a Linear Actuator Using Push Buttons

My science fair project, involves a arm elevator.This consist of a device called a linear actuator.This device is setup similar to a servo except it moves up and down.If possible I would like for this device to be push button operated. :frowning: The issue is that I am not necessarily an expert at coding. The teacher involved in the project has created a code that can be used to move the linear actuator. However, there are several complications with this code such as the error messages that have appeared and actually attempting to activate the push buttons (2). If you can please help us to understand the code that is required for thee object to move up and down.I am in urgent need of help any assistance will do. (I have also attached the code used to this post)

CodePushbuttonandLinearActuator.pdf (31.1 KB)

If possible I would like for this device to be push button operated.

I suspect that you don't. I suspect that you want the pushbuttons to be read by an Arduino that then makes some decisions regarding how to manipulate the linear actuator.

The issue is that I am not necessarily an expert at coding.

You don't need to be. There are maybe 6 functions you need to use altogether, and none takes more than two arguments - digitalRead() takes 1, digitalWrite() takes 2, analogWrite() takes 2.

The teacher involved in the project has created a code that can be used to move the linear actuator.

If you had read the stickies at the top of the forum, you'd know that you should have posted that code.

However, there are several complications with this code such as the error messages that have appeared

Close your eyes. They'll go away. That won't really help, but you haven't given us anything to go on.

I have also attached the code used to this post

As a useless ass PDF file. A text file containing the text would have been so much better.

The code copied from PDF with comments removed, with below error.

sketch_oct28b:27: error: expected `;’ before ‘u037e’

#include <Servo.h>
Servo servoActuator;

const int buttonPin = 2; 

int buttonState = 0; 

void setup() {
  servoActuator.attach(7);

  pinMode(servoActuator, OUTPUT);

  pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {

    servoActuator.write(0);
  }
  else {

    servoActuator.write(90);
  }
}
  pinMode(servoActuator, OUTPUT);

The second argument to pinMode() is a pin number, not a Servo instance.

My version of a similar setup that might work for the OP.

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}