r/ArduinoProjects • u/Regular_Use_5842 • 19d ago
Project Design/Guidance How do I switch this tilt sensor to another?
For context, I'm a beginner in making stuff like these, this is kind of my first time, this is for a school project, so sorry for the messy placements
But I tried to use tinkercad for the simulation
And I ended up with this ( the circuit )
So I just need the servos to spin when the tilt sensor senses a tilt, but I have a different tilt sensor, the circuit uses an SW-200D, while I have an SW-520D, so there's already a difference in number of output pins ( I'm not sure if that's what it's called ), and I'm just not sure about everything else after that ðŸ˜ðŸ˜
The code is quite confusing too, I don't know a single bit of coding, so I tried what I could with the limited knowledge I know
->
#include <Servo.h>
int oozmakappa = 0;
Servo servo_12;
Servo servo_11;
Servo servo_10;
Servo servo_9;
Servo servo_8;
unsigned long spinStartTime = 0;
unsigned long totalSpinDuration = 0;
bool isSpinningForward = false;
bool needsToReturn = false;
void setup() {
pinMode(13, INPUT);
servo_12.attach(12, 500, 2500);
servo_11.attach(11, 500, 2500);
servo_10.attach(10, 500, 2500);
servo_9.attach(9, 500, 2500);
servo_8.attach(8, 500, 2500);
servo_12.write(90);
servo_11.write(90);
servo_10.write(90);
servo_9.write(90);
servo_8.write(90);
}
void loop() {
oozmakappa = digitalRead(13);
if (oozmakappa == HIGH) {
if (!isSpinningForward) {
spinStartTime = millis();
isSpinningForward = true;
needsToReturn = true;
servo_12.write(180);
servo_11.write(180);
servo_10.write(180);
servo_9.write(180);
servo_8.write(180);
}
} else {
if (isSpinningForward) {
totalSpinDuration = millis() - spinStartTime;
isSpinningForward = false;
servo_12.write(0);
servo_11.write(0);
servo_10.write(0);
servo_9.write(0);
servo_8.write(0);
spinStartTime = millis();
}
if (needsToReturn) {
if (millis() - spinStartTime >= totalSpinDuration) {
servo_12.write(90);
servo_11.write(90);
servo_10.write(90);
servo_9.write(90);
servo_8.write(90);
needsToReturn = false;
}
}
}
delay(10);
}
On tinkercad, it stops after 1/2 a spin, and just doesn't move anymore?? ðŸ˜ðŸ˜
I'm very confused, someone please help me and guide me on what to do
If anyone could be of guidance to me, please do so, I'm struggling on how this is supposed to work 💔 I tried looking through YouTube but strangely I just couldn't find anything 😢
2
1
u/hardwareshares 3d ago
the SW-520D and SW-200D are both simple ball tilt switches, so swapping them is easy. the SW-520D has 2 legs and no polarity, just move it off pin 13 since the onboard LED on a Nano/Uno can make INPUT_PULLUP read unreliably. wire one leg to pin 2 and the other to GND with pinMode(2, INPUT_PULLUP). it reads LOW when closed, so flip your HIGH check and test orientation with Serial.println.
the half-spin in Tinkercad is expected because it only has positional micro servos, so continuous-rotation code can't really be tested there. on a real FS90R, the stop point may sit near 90 rather than right on it, so start with writeMicroseconds(1500) and trim it.
also, don't power five servos off the Arduino 5V pin. use a separate 5V supply with the grounds connected.
2
u/Anonymity6584 19d ago
Datasheets at hand and read whats different between those two sensors. You learn electronics side of things only by doing electronics things. Reading datasheets is one of those things.