Mirko Pavleski
Published © GPL3+

DIY Android+Arduino Controlled Labyrinth (Maze) Game

The device presented is marble maze game that is controlled using a smartphone via Bluetooth connection.

IntermediateFull instructions provided4,947
DIY Android+Arduino Controlled Labyrinth (Maze) Game

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

Code

C/C++
#include <Servo.h>
#define START_CMD_CHAR '>'
#define END_CMD_CHAR '\n'
#define DIV_CMD_CHAR ','
#define MIN 55
#define MAX 125
// Create servo objects
Servo panServo;
Servo tiltServo;
// Center servos
float tiltVal = 0;
float panVal = 0;
// Sensoduino
String inText;
float value0, value1, value2;
void setup() {
  // Attach servo objects to Arduino pins
  panServo.attach(10);
  tiltServo.attach(9);
  Serial.begin(9600); // The default speed of the HC-05  Bluetooth serial module
  Serial.flush();
}
void loop()
{
  Serial.flush();
  int inCommand = 90;
  int sensorType = 90;
  unsigned long logCount = 0L;
  char getChar = ' ';  //read serial
  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().
  // parse incoming command start flag
  getChar = Serial.read();
  if (getChar != START_CMD_CHAR) return; // if no command start flag, return to loop().
  // parse incoming pin# and value
  sensorType = Serial.parseInt(); // read sensor typr
  logCount = Serial.parseInt();  // read total logged sensor readings
  value0 = Serial.parseFloat();  // 1st sensor value
  value1 = Serial.parseFloat();  // 2rd sensor value if exists
  value2 = Serial.parseFloat();  // 3rd sensor value if exists
  if (sensorType !=1) return;   // Check sensor type. SensorType 1 is the Accelerometer sensor
  panVal = value0; // value0 = X sensor reading
  tiltVal = value1;  // value1 = Y sensor reading
 
  tiltVal = -7*tiltVal+90; // Map Y sensor reading to servo PWM values
  // Clip too large or too small Y values
  if (tiltVal>=MAX) tiltVal=MAX;
  if (tiltVal<=MIN) tiltVal=MIN;
   
  tiltServo.write(tiltVal); // Write tiltServo
   
  panVal = -7*panVal+90; // Map X sensor reading to servo PWM values
  // Clip too large or too small X values
  if (panVal>=MAX) panVal=MAX;
  if (panVal<=MIN) panVal=MIN;
   
  panServo.write(panVal); // Write panServo
}

Sensoduino

C/C++
No preview (download only).

Credits

Mirko Pavleski

Mirko Pavleski

149 projects • 1283 followers

Comments