Go Back
Video cover
0:00 / 0:00
Project Info

Smart Labyrinth

Smart Labyrinth is a precisely controlled labyrinth platform through joystick using servo motors and a microcontroller, it is used to control the movement of the marble in the labyrinth.

Role
Software & Hardware Engineer
Type
solo
Stack
Arduino C
Internal Project
Presentation

Loading Presentation...

arduino
Copy code
#include <Servo.h>

Servo Servik1;
Servo Servik2;

const int pinX = A0;
const int pinY = A1;

float smoothedX = 512.0;
float smoothedY = 512.0;

const float alpha = 0.15;

void setup() {
  Serial.begin(9600);
  Servik1.attach(3, 500, 2500);
  Servik2.attach(5, 500, 2500);
}

void loop() {
  int rawX = analogRead(pinX);
  int rawY = analogRead(pinY);

  smoothedX = (alpha * rawX) + ((1.0 - alpha) * smoothedX);
  smoothedY = (alpha * rawY) + ((1.0 - alpha) * smoothedY);

  int xMicro = map(smoothedX, 0, 1023, 1388, 1611);
  int yMicro = map(smoothedY, 0, 1023, 1388, 1611);

  Servik1.writeMicroseconds(xMicro);
  Servik2.writeMicroseconds(yMicro);

  Serial.print(rawX);
  Serial.print(" ");
  Serial.println(smoothedX);

  delay(5);
}

Gallery