Description of Sketch
Sparki will navigate between the lines of a maze trying to complete the path from a start point to the exit. The code is designed to navigate by trial-and-error so you may see different results each time you run the program. It is a work in progress. 
Sparki Components Utilized
IR Sensors; Wheels; LCD
Sparki.h and Sparki.cpp Version Dependencies
None
Notes
This is a simple maze following sketch that navigates between the lines of a printed maze pattern. It does not ride on the lines nor have the logic to actually learn the best maze path to follow. Hopefully, others will improve on what I started.
Be sure to press the reset button on Sparki if you lift him off the maze grid, or if he doesn’t start moving when powered on, so that the program restarts when you put him down.
You can download a PDF file for the printed maze I created to test this program from here: dropbox.com/s/gy5m2pju3a26l … t-Maze.pdf . There are 9 pages that can be printed on standard U.S. letterhead or A4 sheets; trimmed so the lines align; and then taped together. [edited 2014-02-25]
Lastly, please note that the format of this forum post follows a standard for user contributed software that I proposed here: Sparki Code Sharing Post
[code]
//
// Maze_Walk1 - Navigate through a black line matrix on floor
// by 8-Bits ~ Update: 20140222
//
#include <Sparki.h> // include the sparki library
void setup() {
sparki.servo(SERVO_CENTER); // center the servo just to look good
}
int do180 = false; // toggle double 90 turn
void loop() {
int lineLeft = sparki.lineLeft(); // save left IR sensor reading
int lineCenter = sparki.lineCenter(); // save center IR sensor reading
int lineRight = sparki.lineRight(); // save right IR sensor reading
int threshold = 700;
if ( lineLeft < threshold && lineRight < threshold ) { // if line detected by left & right sensors
sparki.moveBackward(2); // take a step back
sparki.moveRight(90); // try turning very sharp to the right
if (do180 == true) { // don’t get boxed in
do180 = false;
sparki.moveBackward(2) ; // take another step back
sparki.moveRight(90);
} else {
do180 = true;}
} else {
if ( lineCenter < threshold && lineLeft < threshold ) { // if line detected by center & left sensors
sparki.moveBackward(2); // take a step back
sparki.moveLeft(30); // try turning sharp to the left
} else {
if ( lineCenter < threshold && lineRight < threshold ) { // if line detected by center & right sensors
sparki.moveBackward(2); // take a step back
sparki.moveRight(30); // try turning sharp to the right
} else {
if ( lineLeft < threshold ) { // if line detected by left sensor
sparki.moveRight(15); // turn away to the right
} else {
if ( lineRight < threshold ) { // if line detected by right sensor
sparki.moveLeft(15); // turn away to the left
}
}
}
}
}
sparki.moveForward(); // else move forward
sparki.clearLCD(); // clear the screen
sparki.println();
sparki.print("Line Left: ");
sparki.println(lineLeft);
sparki.print("Line Center: ");
sparki.println(lineCenter);
sparki.print("Line Right: ");
sparki.println(lineRight);
sparki.println();
sparki.updateLCD(); // display last sensor data used
delay(100); // wait 0.1 seconds
}[/code]
Have Fun!


