## Introduction: LinkIt ONE Prime Number SMSer

A colleague has recently been going on and on about primes and somehow transferred his enthusiasm on me - a guy who happens to know how to code, has a linkIt ONE board and no time to work with it. Every time I study and see it just lying in a corner of my desk, I think to myself: "what a waste of this piece of hardware to just sit there idly" and one day it hit me: make it seek primes and since LinkIt ONE has a built in GSM module make it send me new primes so I will see it wherever I am! This was an easy task which I could finish in half an hour.

That is the story behind this instructable. Keep on reading if you want to make your own using only Mediatek LinkIt ONE kit.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?

Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: The Algorythm

For each number check if it is prime and if it is, notify user via SMS. To decide whether or not a number *n* is prime, we must try to divide it with every number from 2 to *n-1* and see if remainder at division is always not 0. If that is true, n isn't divisible with any number except 1 and itself, which is the definition of a prime number.

This algorithm could be optimised by checking only odd numbers (all even numbers are divisible by 2 and thus not primes) and checking to only sqrt(n) instead of all the way to n-1 (there is no divisor of n that is greater than sqrt(n)) and most importantly, we could only divide with primes. Why didn't I do that? LinkIt ONE is so powerful it finds primes faster than they could be SMSed.

Now the question is how to make those SMS' interesting if they would be coming all the time? as it turns out there is no way of telling how far apart two primes will be. It will always be at least one not prime between (with exception of 2 and 3) so why not use that? When a prime is found, program will halt for time determined by how far apart last two primes, multiplied by delay amount.and only after that SMS will be sent and next number will be tested.

If you take a look at attached code you will see that I also added a "limbo" - part of code with no escape - where program gets stuck if it exceeds 32 bit long int limit and goes back to counting from 1 upwards (we don't want this).

## Step 2: Tweaking the Code

#define STARTNUMBER 10 #define DELAYFACTOR 100 #include #include unsigned long candidate = STARTNUMBER; unsigned long divisor = 2; bool isPrime = true; unsigned long time = millis(); unsigned long counter = 0; void loop() { start: if(Serial.available()){candidate=(Serial.parseInt());} isPrime = true; divisor=2; for(divisor;divisorYou now know the basic algorithm, time to tweak it a little... or not... One thing you might want to change is STARTNUMBER parameter - set ti to something high but number must not exceed 2**32 as this is technical limitation to what LinkIt ONE can perform operations on. The other thing is that you might want to increase delay time from 10 minutes to something more - 5 hours for example. That will make SMS' come up to four times a day on peaks and there will be periods of time when you won't get any SMS' for days.

### Attachments

## Step 3: Assembling LinkIt ONE and Running the Code

Done tweaking? Upload the code, power off the board, insert a sim card (without PIN), attach GSM antenna, power the board and go on with your life, do whatever you were doing. Forget about all of that and be surprised when you get an SMS!

The foam case is from my other instructable which you can find here.

Hope you liked this 'Ible and have fun!

## Discussions