Roulette Screamer
So what this project does, as seen above, is randomly light up the LED's a number of times, then if the last one is green or red, then it sends a signal so that the screamer part of the circuit makes a loud and annoying noise. It is able to make this random choice using an arduino uno.
Downloads
Supplies
-Arduino Uno
-9 Leds
-220 Resistor
-3 1k Resistor
-555 timer
-10 mF Capacitor
-100 nF Capacitor
-8 ohm Speaker
-Button
-NPN transistor
How Does It Work?
Using this code
void setup() {
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,INPUT_PULLUP);
pinMode(2,OUTPUT); }
void loop() { if (digitalRead(4)==LOW){ for (int thisPin = 5; thisPin < 14; thisPin++) { digitalWrite(thisPin,LOW); } int randNumber = random(18,45); int n=0; int d=50;
for (int i=0; i < randNumber; i++) { for (int thisPin = 5; thisPin < 14; thisPin++) {
digitalWrite(thisPin, HIGH); delay(d); n++; d+=5; if (n==randNumber) {break; } digitalWrite(thisPin, LOW); } if (n==randNumber) {break; } } if (randNumber%9==2){ digitalWrite(2, HIGH); delay(2000); digitalWrite(2, LOW); } if (randNumber%9==4){ digitalWrite(2, HIGH); delay(2000); digitalWrite(2, LOW); } if (randNumber%9==8){ digitalWrite(2, HIGH); delay(2000); digitalWrite(2, LOW); } } }
This code works by choosing a random number 18-45 where it will slow down the longer it goes it gets to the randomly determined number. It can do this by using the modulo command to make sure that the you end up with a remainder on dividing the random number by 9. If the final number is one of the ones I deemed to be bad, then it sets a pin to high and back to low as to make the speaker go off.
Why This Circuit?
So initially I wanted to make this shock you when you get the final result, but that was probably not the safest to test and I was not able to get the transformer needed to make that happen. This circuit is just fun to mess around with as you never know when you will get a fun jarring noise
Building the Circuit: Lights
Get your leds, wires, 220 resistor, button
For each of the LEDs put one end of the led connected to a pin on the arduino and an end to the ground, at the end of the ground put the 220 resistor before connecting everything to ground.
With the button connect one end to a different ground on the arduino and to a pin on the arduino that is set up to detect when it is pressed. This button is what initiates the randomization sequence.
Building the Circuit: Arduino
For this connect pins 5-13 to an LED, Pin 4 is for the button, Connect pin 2 to the middle prong of the transistor. Take the 5v of the arduino and connect it to where the the screamer is as that is what is going to power that
Building the Circuit: Screamer
Take the 5v source, connect it to 8 and 4 on the 555 timer. 3 on the 555 timer will split to the right it will be 10uF capacitor into the speaker then to ground. To the left it goes into the 3 resistors where 6 and 2 join in on that point where it reaches 100nF capacitor and connected to the other side of the speaker and 1 on the timer and the is ultimately connected to ground.
Scematic
This is the schematic for the circuit