Introduction: Lottery Machine

About: 31 years old tinker and diy hobbyist. From Oulu, Finland. IG @mkarvonen_instructables

A simple and effective lottery machine.

Be a lottery host for fun with friends


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 "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+=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); }



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.