# Sieve of Eratosthenes

Up until now I’ve done a lot of software-only projects on my own (clearly, given that I write software for a living) and electronics projects in groups, but I hadn’t yet done an entire arduino-based electronics project on my own from start to finish.

My little sister is finishing up her graduate degree in mathematics education this year, aiming to teach high school maths, and I wanted to give her something besides just a grocery store gift card for her birthday. So I decided to make an arduino-based demonstration of the Sieve of Eratosthenes, the prime number derivation sieve, that she can set on her desk and show her students.

Essentially what happens is that you have a square 2D array (in this case, let’s say of booleans), with each value originally set to true. Starting from 2, for every number that’s true, go through and set all multiples of that number to false. When you reach the end of the (outer) loop, all primes are true (and 1, which is not a prime, is true too, but it makes the array look prettier) and all composite numbers are false.

So first I bought myself an LED matrix and an 8-digit LED display driver (MAX7219) and soldered that all together:

And popped the LED matrix on:

I hooked it up to my arduino and ran some simple test code to make it run numbers (the original intention for the driver):

Figured out how to address each LED individually:

Then got my wee arduino nano involved and got it breadboarded:

And wrote up the algorithm and got that going:

Soldered the whole thing to some stripboard:

Which meant I was in business. So it was time to move to making an enclosure for it. I sketched something up in FreeCAD (with 5 major revisions):

And started printing on the Ultimaker. The first print got aborted partway through, which ended up not being a big deal, because I forgot to include space for the power cord.:

The second print:

Didn’t work out because I’d not made the case deep enough to accommodate the LED matrix, which bumps up above the board quite a bit. The next print went wrong and was aborted:

And finally, I got a good print:

A quick lid in Draftsight:

And cut it out on the CNC router (thanks, Pocky!). It was sanded and flame-polished (thanks, Hybrid!):

And then I hot-glued the board to the tabs and screwed the lid on, resulting in the final project:

So the note along with my sister’s birthday present sends her to this URL, so that she can see how her present was made.

Happy birthday, Furball!

-(-*

Great Project ! Thanks for posting. This is an inspiration.

Greetings and Happy Birthday!

Great!

Can you share the code?

Thanks.

For the record, this was written at o’dark thirty and I did a couple of things that, while not super efficient, made my life easier.

Github

Hey I know this is off topic but I was wondering if

you knew of any widgets I could add to my blog that automatically tweet my

newest twitter updates. I’ve been looking for a plug-in like this for quite some time

and was hoping maybe you would have some experience with something like

this. Please let me know if you run into anything.

I truly enjoy reading your blog and I look forward to your new updates.

Happy B-day Furball! Dark moon, would you help set a simple on/off control for a couple electric motors?

Being a math teacher, I would love to get the code for this Sieve of Eratosthenes to share in my classroom and electronics club…. Could you share a link?

Certainly! It’s a little rough (I did it quickly and then left it alone), but here it is:

https://github.com/darkmoonsinger/SieveOfErotosthenes