Simple decision maker using Arduino

Simple decision maker using Arduino

475
0
SHARE

Poin2 Lab. is located in the heart of Seoul – Gangnam area, well known for “Gangnam Style”. Do you know psy?There are so many places to eat, just sooooo many, so it’s actually hard to decide what to eat for lunch. To solve this issue, I made a small decision maker using Arduino Nano, 6 LEDs, and a switch, so the device will randomly choose 1 out of 6 choices when the reset button is pressed. I tried to make things a little fancier than previous projects, so there were some soldering involved. However, you can do it simply on a breadboard and probably cover it up somehow to make it look much fancier than mine.

 

Things you need:
Arduino Nano x 1
LED (Whatever colors you want) x 6
Switch Button x 1
Wires

 

Hardware Connection:

hwc

Connect LEDs to Digital GPIO 2-7 through 330ohm resistors, a switch between Reset and Ground, and you are good to go!

a20150727_145331

I had a plastic case laying around the office, so decided to give it a new life as a decision maker.

a20150727_155945

Drilling holes with a hand drill bit.

a20150728_111035

 

Soldering components (a little messy, I know.. )

a20150728_111045-1024x1024

The end product! Now it’s time to program Arduino.

 

Programming Arduino

int menu;

void setup() {
Serial.begin(9600);
// set the digital pin as output:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

randomSeed(((analogRead(A0)+53)*(analogRead(A1)+15)*(analogRead(A2)*29))/64);//make sure random number is actually random everytime Arduino is reset
menu = random (181,241); //random number between 181 & 240
int ledStart=0;
int initDelay = 65;
int choice = menu%6+2; //result is already set here, the rest of code is all about LED behavior

Serial.println((analogRead(A0)+53)*(analogRead(A1)+15)*(analogRead(A2)*29));
Serial.println(menu);
Serial.println(choice);
//Initialize LEDs
circle(20,5); //5 rounds of 20ms LED circle
circle(30,4); //4 rounds of 30ms LED circle
circle(40,2);

//LED circles around until it reaches the random number
while (ledStart+100 <= menu){
int remainder = (menu – ledStart)%6 + 2;
oneway(15,remainder);
ledStart++;
}

//little bit slower
while (ledStart+30 <= menu){
int remainder=(menu-ledStart)%6 + 2;
oneway(55,remainder);
ledStart++;
}

//interval is increased as it reaches the result
while(ledStart<=menu){
int remainder=(menu-ledStart)%6 + 2;
oneway(initDelay,remainder);
ledStart++;
initDelay=initDelay+10;
}

// Dealing with last few numbers to reach preset result
if (ledStart > menu){
int lastRound=7;
while(lastRound>choice){
oneway(initDelay,lastRound);
lastRound–;
initDelay=initDelay+10;
}
delay(100);
digitalWrite(choice,1);
}
}
void loop() //loop is empty so the program will run only once after reset
{}

//Turn on all LEDs in order, then turn them off in order
void circle(int interval, int times)
{
for(int i=0; i<times; i++){
for(int j=2; j<8; j++){
digitalWrite(9-j, 1);
delay(interval);
}
for(int j=2; j<8; j++){
digitalWrite(9-j,0);
delay(interval);
}
}
}

//Turn on one LED, then turn it off
void oneway(int interval, int k)
{
digitalWrite(k,1);
delay(interval);
digitalWrite(k,0);
delay(interval);
}

 

The above code basically creates a random number, then divides it by 6, take the remainder and add 2 because I decided to use digital pins 2-7 for LEDs. The rest of code is just to make the device a little more fun, making the LEDs to turn on sequentially until the result is reached.

Every morning as we come to the office, we’d put down whatever we want to eat on a piece of paper on first-come, first-served base, and have this little decision maker choose our lunch. The first day went by very smoothly, with no one complaining about the menu. let’s wait and see how well it will serve its purpose!

a20150729_104847

 

#포인투랩 오늘의 점심. 감사해요 @fishman_js

YC(@yooncheolc)님이 게시한 동영상님,