Include - Servo.-Wps Office
Include - Servo.-Wps Office
h>
int angleUpDown = 90; // Initial servo position for Up/Down (center position)
int angleLeftRight = 90; // Initial servo position for Left/Right (center position)
void setup() {
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(buttonLeft, INPUT_PULLUP);
pinMode(buttonRight, INPUT_PULLUP);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
servoUpDown.write(angleUpDown);
servoLeftRight.write(angleLeftRight);
void loop() {
// Move crane up
if (upState == LOW) {
servoUpDown.write(angleUpDown);
if (downState == LOW) {
servoUpDown.write(angleUpDown);
if (leftState == LOW) {
servoLeftRight.write(angleLeftRight);
digitalWrite(motorPin1, HIGH); // Rotate motor left (clockwise)
digitalWrite(motorPin2, LOW);
if (rightState == LOW) {
servoLeftRight.write(angleLeftRight);
digitalWrite(motorPin4, LOW);
temperature = analogRead(thermistorPin);
float tempCelsius = (voltage - 0.5) * 100.0; // Convert to Celsius (based on thermistor calibration)
Serial.begin(9600);
Serial.print("Temperature: ");
Serial.print(tempCelsius);
Serial.println(" C");
delay(100); // Small delay for stability