October 11, 2013

Build an Arduino-powered "Sieve of Eratosthenes" emulator

As an interesting gift for a trainee maths teacher, a software engineer with the handle "darkmoonsinger" created a "Sieve of Eratosthenes" emulator based around an Arduino-compatible board an a MAX7219 LED matrix display driver IC. For the uninitiated a Sieve of Eratosthenes is a tool to find prime numbers from 1 up to an upper limit. How it works is quite interesting, and in the creator's words:

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.

This proved to be quite fascinating, so we pulled out some hardware and tried it for ourselves. Using the LED matrix, the sketch works through the numbers from 1 to 64. These are represented on the matrix from top-left to bottom-right, and through a process of elimination the LEDs left on are the prime numbers, for example:

You can find out more about the Sieve of Eratosthenes and the device from the project page - and the Arduino sketch can be found here on the creator's github page. And for more, we're on twitter and Google+, so follow us for news and product updates as well. 

If you're new to Arduino and want to join the fun, the first step is a solid board for your projects - our Freetronics Eleven - the Arduino-Uno compatible with low-profile USB socket, onboard prototyping space and easy to view LEDs:   

Leave a comment

Comments have to be approved before showing up.