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.

Lottery Machine
Lottery Machine
Lottery Machine

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

Lottery Machine

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.

Lottery Machine
Lottokone.ino2 KB

Step 3: Start earning money.

Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Lottery Machine
Show All 9 Items

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.

 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel