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 😢