tilt sensor and servo motor dilemma

Hello, everyone. I am currently working on a project that involves a tilt sensor and servo motor. My goal is to have the servo motor move 90 degrees only when the tilt sensor senses a tilt. I know this sounds like a rather simple project, but both me and my engineering teacher can not figure out what is wrong. We don’t know whether it is my code or the wiring of the Arduino, because everything seems to be correctly done. There are no errors when I verified the code, and the wiring seems to be correct. This project is overdue, so any immediate help is appreciated! Photos of the wiring are attached. Thank you.

int servoPin = 9;
int switchTilt = 2;
int val;
#include <Servo.h> ;

Servo myservo; 

void setup() 
  // put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(9, OUTPUT);


void loop()
  // put your main code here, to run repeatedly:
if (val == HIGH)
  digitalWrite(13, HIGH);

  digitalWrite(13, LOW);

IMG_2267 (1).jpg

IMG_2266 (1).jpg

Servos go from 0 to 180 with 90 in the middle, there's no -90.

And includes don't get a ; on the end but i'm not sure what the effect of one is.

Forget the sensor. Can you make the servo move 90 degrees?

Forget the servo. Can you make the tilt sensor sense a tilt?

The code says things are connected to pins 2 and 9. The pictures show something different.

And that servo is way too big to be powered from the Arduino 5V pin.

Put a Serial.print() in to see if the tilt sensor is doing anything.


Here are the OP images.
IMG_2267 (1).jpg
IMG_2266 (1).jpg

According to the picture, the + and - rails of the breadboard are not connected to 5 V and ground.


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: