Servo not moving

Hi all, I made this setup where a Raspberry Pi sends “1” through serial to the Arduino when it detects a face to the right, and “2” if it detects a face to the left. The Arduino moves a servo left or right based on this.

This is the Arduino code:

#include<Servo.h>
int val;

Servo s;
int pos = 90;

void setup(){
  Serial.begin(9600);
  s.attach(9);
  s.write(pos);}
  
 void loop(){
   if(Serial.available()>0){
     val = Serial.read();
     Serial.write(val);
    if (val == 1){
 if (pos < 180 && pos > 0){
 
 pos+=2;
} if (pos == 180){
pos = 178; 
}

if (pos == 0){
pos = 2; 
}
} 

if (val == 2){
if (pos < 180 && pos > 0){
 
 pos-=2;
} 
 if (pos == 180){
pos = 178; 
}

if (pos == 0){
pos = 2; 
}
 
}

s.write(pos);
delay(15);
 
}}

But the servo doesn’t move. Please help, I’m just a beginner in serial related stuff.

Hint you are NOT sending the number 1 but you are sending '1'

Always layout your code before posting, this avoids wasting our time!

Mark

Thanks! I replaced 1 and 2 with '1' and '2' and it works flawlessly!