Hi All Can someone help with flap issue on a machine i have installed a MZ999 servo due to a failed arm that was controlled by a latching solenoid but to get it going i needed a work around but think a servo will work much better
But having issues with the code I'm great on the automation of the machine but need a fix to get it going any one available to help
Servo is a MZ999 controlled by a Nano v3 due to space at the front of the machine once the plc gives the signal the flap will close and wait until the second sensor is made then return back to zero with the flap open below is my code please be gentle my coding is in scl and tia portal but not in C but need a quick fix Can anyone help ........
// the sensor is no longer true the flap should close 180 degrees until sensor 2 becomes true then waits 2 seconds then will return
// back to zero until sensor 1 is made true again to start the cycle again between 0-180 wait 2 seconds then return to zero
#include <Servo.h>
Servo myservoNose; //servo1
//----------------------------------------Setting of the inputs and output to the servo------------------------------------------------
const int buttonPin1 = 7; // pin 7 for sensor 1
const int buttonPin2 = 2; // pin 2 for Sensor 2
const int ServoPin = 3;
void setup()
{
Serial.begin(115200); //activating Serial Monitor
myservoNose.attach(ServoPin); //activating pin 9 for servo
pinMode(buttonPin1 , INPUT); //To set the signal from the first sensor
pinMode(buttonPin2 , INPUT); //To set the signal from the second sensor
}
void loop()
{
int buttonState1 = digitalRead(buttonPin1); //reading buttonPin and storing it as buttonState.
Serial.println(buttonState1); //telling computer to print buttonState.
if (buttonState1 == HIGH) //if The sensor is high move the servo form 0-180 degrees...
{
delay (1000);
myservoNose.write(0); // the servo from 0 degrees
delay(2000); //wait
myservoNose.write(180);
delay(500); //wait as the door is closed
}
int buttonState2 = digitalRead(buttonPin2); //reading buttonPin and storing it as buttonState.
Serial.println(buttonState2); //telling computer to print buttonState.
if (buttonState2 == HIGH) //if sensor 2 is high move the servo back to zero ...
{
myservoNose.write(180); // Sensor 2 is met and the servo will now return from 180-0
delay(500); //
myservoNose.write(0); //
}
}
type or paste code here