Hello everyone and thanks for the welcome to the community
I follow the forum a lot because I'm working on some projects myself and I ran into a problem myself.
I am working on a project on my old tractor. I work on electronics for tractor hydraulics and I encountered an intractable problem. I have 3 servomotors and 4 potentiometers, a gyroscope and a button. Potentiometer 1 and 2 are on the joystick, as well as the button, and they are used to control the front crane of the tractor, as well as the gyroscope, which is turned on on demand for the balance of the front part of the crane if necessary. Servo 3 works exclusively for the rear hydraulics on the tractor - plow depth control or EHC. Now pot 3 regulates the position of the servo and pot 4 simulates a load sensor which, if the plow is moved, moves the servo a little, and when the load disappears, returns servo 3 to the default position of potentiometer 3. So far everything is working fine BUT ....
When I press the button for the gyroscope, everything turns off except motor 2, which works with the gyroscope, and only it remains working with the gyroscope..
Does anyone have an idea where I went wrong?? more experience in code than me..
I would be very grateful for your help..
You got that thing on the right connected to the thing on the left and it should be the other way around. Without posting your code, an annotated schematic (show all connections also notate any leads over 10" / 25 cm) and links to technical information on your hardware items it is highly unlikely somebody will be able to guess what your problem is.
#include <GY6050.h>
#include <Servo.h>
#include <Wire.h>
#define LED_PIN 8
#define BUTTON_PIN 24
Servo myservo1;
Servo myservo2;
Servo myservo3;
int potPin1 = A0;
int potPin2 = A1;
int potPin3 = A2; // Potenciometar za pomicanje serva
int potPin4 = A3; // Potenciometar za simulaciju optereÄenja
int targetPos3 = 90; // PremjeŔteno iznad petlje
int X = 0;
int Y = 0;
GY6050 gyro(0x68);
byte lastButtonState;
byte ledState = LOW;
unsigned long lastTimeButtonStateChanged = millis();
unsigned long debounceDuration = 50;
bool gyroControl = false;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
lastButtonState = digitalRead(BUTTON_PIN);
myservo1.attach(2);
myservo2.attach(3);
myservo3.attach(4); // PrikljuÄak za servo motor
Wire.begin();
gyro.initialisation();
delay(100);
Serial.begin(9600);
}
void loop() {
int potValue1 = analogRead(potPin1);
int potValue2 = analogRead(potPin2);
int potValue3 = analogRead(potPin3);
int potValue4 = analogRead(potPin4);
int servoPos1 = map(potValue1, 0, 1023, 0, 180);
int servoPos2 = map(potValue2, 0, 1023, 0, 180);
int servoPos3 = map(potValue3, 0, 1023, 0, 180);
// Dodatni kod za senzor optereÄenja
int loadSensor = map(potValue4, 0, 1023, -30, 30);
Serial.println(potValue4);
// PoveÄavamo ili smanjujemo ciljnu poziciju myservo3 ovisno o potenciometru 4
targetPos3 = constrain(targetPos3 + loadSensor, 0, 180);
// Glatko mijenjamo trenutnu poziciju prema ciljnoj poziciji
servoPos3 = servoPos3 + (targetPos3 - servoPos3) * 0.15;
delay(10);
if (!gyroControl) {
myservo1.write(servoPos1);
myservo2.write(servoPos2);
myservo3.write(servoPos3);
}
delay(50); // PoveÄano kaÅ”njenje
X = map(gyro.refresh('A', 'X'), -90, 90, 0, 180);
Y = map(gyro.refresh('A', 'Y'), -90, 90, 0, 180);
if (gyroControl) {
myservo2.write(X);
}
if (millis() - lastTimeButtonStateChanged >= debounceDuration) {
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) {
if (ledState == HIGH) {
ledState = LOW;
gyroControl = false;
} else {
ledState = HIGH;
gyroControl = true;
}
digitalWrite(LED_PIN, ledState);
}
}
}
}
Hi, yes, I know, I didn't manage to copy right away.
here is pasted the entire code I made. everything works only when the gyroscope with servo2 motor is turned on on the button, then nothing else works.. Do you have an idea, more experience than me..?
Thank you in advance
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.