why this code might not work. help me

#include <Servo.h>
Servo servo1;
long num1 ;

const byte potpin = A3;
int deger;

void kurulum()
{
servo1.attach(10);

pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);

Serial.begin(9600);
}

void döngü()

{
if (Serial.available() > 0)
{
num1= Serial.parseInt();

servo1.write(num1);

while (Serial.available())
Serial.read();
}

deger = analogRead(potpin);
Serial.println(deger);
gecikme(2500);

if (digitalRead(3) == LOW)

{
if(deger = 214)
{

servo1.write(90);

}

else if(213<=deger )
{

servo1.write(45);

}
else if(215>=deger )
{

servo1.write(135);

}

}

if (digitalRead(4) == LOW)

{
if(deger = 300)
{

servo1.write(90);

}

else if(299<=deger)
{

servo1.write(45);

}
else if(deger>=301)
{

servo1.write(135);

}
}

if (digitalRead(5) == LOW )

{
if(deger = 400)
{

servo1.write(90);

}

else if(399<=deger)
{

servo1.write(45);

}
else if(deger>=401)
{

servo1.write(135);

}

}
if (digitalRead(3) != LOW && digitalRead(4)!= LOW && digitalRead(5) != LOW )
{
servo1.write(90);

}

if(deger = 400)Oops

Please remember to use code tags when posting code

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags
[code]Paste your sketch here[/code]

Always comment your sketch.

#include <Servo.h>
Servo servo1;
long num1 ;

const byte potpin = A3;
int deger;


void setup()
{
  servo1.attach(10);
 
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  

  Serial.begin(9600);
}


void loop()

{
  if (Serial.available() > 0)
  {
    num1 = Serial.parseInt();

    servo1.write(num1);


    while (Serial.available())
      Serial.read();
  }

  deger = analogRead(potpin);
  Serial.println(deger);
  delay(2500);

  if (digitalRead(3) == LOW)

  {
    if (deger == 214)
    {

      servo1.write(90);

    }

    else if (213 <= deger )
    {

      servo1.write(45);

    }
    else if (215 >= deger )
    {

      servo1.write(135);

    }

  }

  if (digitalRead(4) == LOW)

  {
    if (deger == 300)
    {

      servo1.write(90);

    }

    else if (299 <= deger)
    {

      servo1.write(45);

    }
    else if (deger >= 301)
    {

      servo1.write(135);

    }
  }


  if (digitalRead(5) == LOW )

  {
    if (deger == 400)
    {

      servo1.write(90);

    }

    else if (399 <= deger)
    {

      servo1.write(45);

    }
    else if (deger >= 401)
    {

      servo1.write(135);

    }

  }
  if (digitalRead(3) != LOW  && digitalRead(4) != LOW && digitalRead(5) != LOW )
  {
    servo1.write(90);


  }

I have a pressure sensor, I want the servo motor to change the angle according to the values ​​coming from there. But when you press the button, there is no change in the servo motor

If you want to debug your code, scatter some prints around, and get it to tell you what it is doing, and why.

It's a good thing pin 3 defaults to INPUT, isn't it?

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components. Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Using if (deger == 214) may not be wise as the chances of sitting at exactly 214 is unlikely.


This can be confusing,

else if (213 <= deger )

consider:

else if (deger >= 213 )

Hi,
What are connected to pins 3 and 4?
What are they supposed to do?

Thanks.. Tom... :slight_smile:

Please don't post code with mismatched parentheses... Only post code that actually compiles without
error (unless you are asking about compiler errors!).

If you want to do things when a button is pressed, rather than while a button remains
pressed, use the approach of StateChangeDetection example.

Why do you have a 2.5 second delay after reading the analogs? I suspect this causes issues with button detection because you could press and release the button during that time and never see it. Also, you need to check if the button has been pressed not the state of the button. Check out the following tutorial:

StateChangeDetection

Hi,

  • Have you got code that JUST makes the servo sweep and works?
  • Have you got code that JUST reads the pressure sensor AND works?
  • Have you got code that JUST reads the button AND works?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a Fritzy picture, prefer a hand drawn circuit if you do not have a CAD program.

Thanks.. Tom.. :slight_smile: