Introduction: Lottery Machine

A simple and effective lottery machine.

Be a lottery host for fun with friends

OR

Play those numbers in the real lottery.

7 numbers between 1-39 are generated randomly for every 250ms.

The generated numbers can be changed to anything.

These numbers are from my own country national lottery.

For mobile users: Watch the video from here!

Step 1: Build.

Build is simple.

You will need an Arduino board, LCD screen and a button.

I used a shield to connect the button and LCD.

Button used is a touch plate that senses your touch and the LCD screen is in RGB colors.

Button is connected to D7 witch means Pin 7 on Arduino and the LCD is connected to I2C.

Step 2: Coding

Connect the board to the PC and start coding.

The code uses EEPROM to store the generated numbers so there will be no same numbers in the drawn numbers on the screen.

Start with including components and global variables.

#include

#include #include "rgb_lcd.h"

const int numNumbers = 7; const int buttonPin = 7;

rgb_lcd lcd;

const int colorR = 255; const int colorG = 0; const int colorB = 0;

int numbers[numNumbers];

boolean isInit = false; boolean lcdNeedsRefreshed = false; boolean isFirstButtonPush = true;

Then move to setup. I included a small intro to the setup that tells you what to do.

void setup() {
pinMode(buttonPin, INPUT_PULLUP);

int eeprom=EEPROM.read(0); eeprom+=1; EEPROM.write(0, eeprom); randomSeed(eeprom);

lcd.begin(16, 2); lcd.home(); lcd.clear(); lcd.setRGB(colorR, colorG, colorB); lcd.setRGB(255,255,255); lcd.setCursor(0,0); lcd.print("HOLD FINGER ON"); lcd.setCursor(0,1); lcd.print("THE BUTTON"); delay(3000); lcd.clear(); }

Then to the loop. The loop uses few subroutines that are done bellow.

void loop(){

if(isFirstButtonPush){ readButtonPush(); if(!isInit){

isInit = true; } }else{ readButtonPush();

if(lcdNeedsRefreshed){ lcd.home(); lcd.clear(); printNumbersToLCD(); lcdNeedsRefreshed = false; delay(50); }

lcd.setRGB(50,255,11);

}

delay(200); }

void readButtonPush(){

int reading = digitalRead(buttonPin); lcd.scrollDisplayLeft(); lcd.setCursor(0,1); lcd.print(" Winning numbers! Or not.");

if(reading == LOW){ generateRandomNumbers(); isFirstButtonPush = false; lcdNeedsRefreshed = true; } }

Lastly the subroutines that i mentioned before.

void generateRandomNumbers(){
for(int i = 0; i < numNumbers; i++){ numbers[i] = nextRandomNumber(); } }

int nextRandomNumber(){ int nextRandom = random(1,39); boolean isDuplicate = false; for(int i = 0; i < numNumbers; i++){ if(nextRandom == numbers[i]) isDuplicate = true; } if(isDuplicate) return nextRandomNumber(); return nextRandom; }

void printNumbersToLCD(){

lcd.setCursor(0,0); for(int i = 0; i < numNumbers; i++){ if(numbers){ lcd.print(numbers[i]); } if(i != 6) lcd.print("-");

} }

If you have any questions just ask. I will try to answer them.

Step 3: Start Earning Money.

Like i said. Winning numbers....Or not!

Hard to say what wins. Hopefully it is you (10% cut for me if you hit the jackpot ;).

There is about 15 million number possibilities that it can generate with these numbers.

I hope you liked my project, in case you did remember to follow me to get the latest projects first.

Thank you for reading.

Comments

author
ewalsh4 (author)2017-01-12

Ah awesome! Would it be hard to change this code around so it displays on TFT-LCD?

author
mrw122015 (author)2016-01-13

I really like this! Unforunetly I do not have an arduino yet, but I hope to get one soon. In the meantime, I have a Raspberry Pi. Is there any way to use a python program version of this on the raspbery pi? Or maybe just a general python program to print the numbers? Thanks!

Nice Job again!

author
mkarvonen (author)mrw1220152016-01-17

Look for similiar projects done with raspberry. It sure can be done.

author
mrw122015 (author)mkarvonen2016-01-17

Ok thank You! Nice Job again on your project

author
vsahu4 (author)2016-01-16

i liked ur project
but where can i get the arduino ? could u plz send me the link

author
mkarvonen (author)vsahu42016-01-17

Look for a ebay.com . Type Arduino to the search field. There should be plenty from you to chose from.

author
gogoguy (author)2015-11-01

I love this 'ible!

author
mkarvonen (author)gogoguy2015-11-01

Thanks! :)

About This Instructable

4,823views

86favorites

License:

Bio: I am 26 years old engineering student from Oulu in Finland. Currently living in Joensuu. I make these projects as a hobby, and it would ... More »
More by mkarvonen:PipBoy 3000 (working)DIY Piranha PlantPhoto(s) to 3D model
Add instructable to: