Sparki Follows a Line!

Let me start by saying I LOVE Sparki!

The “Line Following” code on the site was not working.

I figured I could figure out how to get Sparki to follow a line. I was completely successful and now Sparki is following the line pretty well. Making it work almost brought tears to my eyes. I can’t wait to share this with my 7th grade students. Please share your thoughts.

Here is a YouTube video: http://youtu.be/7DPyyW0Ss_s

Here is the code that worked…

[code]#include <Sparki.h> // include the sparki library

void setup()
{
}

void loop() {
int threshold = 900;

int lineLeft = sparki.lineLeft(); // measure the left IR sensor
int lineCenter = sparki.lineCenter(); // measure the center IR sensor
int lineRight = sparki.lineRight(); // measure the right IR sensor

if ( lineLeft > threshold ) // if line is below left line sensor
{
sparki.moveRight(); // turn right
}

if ( lineRight > threshold ) // if line is below right line sensor
{
sparki.moveLeft(); // turn left
}

// if the center line sensor is the only one reading a line
if ( (lineCenter < threshold) )
{
sparki.moveForward(); // move forward
}

sparki.clearLCD(); // wipe the screen
sparki.println();

sparki.print("Line Left: "); // show left line sensor on screen
sparki.println(lineLeft);

sparki.print("Line Center: "); // show center line sensor on screen
sparki.println(lineCenter);

sparki.print("Line Right: "); // show right line sensor on screen
sparki.println(lineRight);

sparki.println();
sparki.updateLCD(); // display all of the information written to the screen

delay(100); // wait 0.1 seconds
}[/code]

Hi,

That looks really good! Can you tell me how you printed out your track? it looks really nice and easy to assemble!

Cheers,

Darren

Hi

I am very new to all of this. I am preparing a curriculum to teach Sparki to my 7th and 8th graders. So I uploaded your line follow code. How do I now get Sparki to do this on he “has” the code?

I did it! And like you, I almost cried! Thanks

[quote=“Dazz_pl19”]Hi,

That looks really good! Can you tell me how you printed out your track? it looks really nice and easy to assemble!

Cheers,

Darren[/quote]

Found the customizable line following tracks at http://robotsquare.com/2012/11/28/line-following/.

Brilliant - It and the maze producing site worked perfectly! Thanks!

Bruce

Fantastic! Said Doctor #9, and the teacher

Allons-y! Said Doctor #10, and the student

Geronimo! Said Doctor #11, and Sparki!

Thanks for the code! I had yet to look at those sensors.

Here’s what it looks like for me. No modification to the code (yet)

http://www.youtube.com/watch?v=9zSop1waElk