 Arduino – Components

Led dice variations

The task demanded to connect more than two components to the Arduino processor in order to have a quick view the possibilities that this prototyping device can offer.

Process:

In this experiment I used a instructables tutorial that I searched in Instructables and I started to explore from there other potential uses.

To have a better uderstanding of arduino and explore different ideas I recommend this links:
https://create.arduino.cc/projecthub

Components:

• Arduino UNO processor
• 16 Jumper wires
• 1 220 ohm resistor
• 10k resistor
• Button
• Photoresistor
• USB cable
• 6 Led’s

First approach, the regular dice:

1. Connect the button to the middle of the “breadboard”
2. Connect a red cable from the “5v” pin in the arduino UNO device to one of the sides of the breadboard who will the become the “positive lane”of the board.
3. Connect a cable from the positive lane to the “positive” side of the button
4. Connect in the same lane a 10 k resistor leg and connect the second one to the negative lane of the board
5. Connect with a cable the negative lane of the board with the pin 13 of the arduino UNO device.

Every time we click the button, arduino will transmit a signal to light a random number of Led’s

7. Then we must place the Led’s on the board

8. And then we connect all the negative ports together making “bridges” from one cathode to the other and we connect the positive  parts from the LED’s to the the pin ports 2,4,6,8,9,10, and 12 since the arduino processor will transmit the energy from there to the leds in every click. I decided to take the resistors out of the circuit in this part since the energy from was so low that the Led’s where not lighting but it is recommended to use them.

``````<code>
// Arduino LED Dice
// Using button debouncing logic from the Internet!
// Available on Instructables, just search it :)
const int pins = {2, 4, 6, 8, 10, 12};
int buttonPin = 13, buttonStatus, randNum, lastNum, i, lastDebounceTime, debounceDelay = 150;
void draw(int randN);
void setup() {
for (i = 0; i <= 5; i++) {
pinMode(pins[i], OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop() {
if (buttonStatus == HIGH && (millis() - lastDebounceTime) >
debounceDelay) {
do {
randNum = random(1, 6);
} while (lastNum == randNum);
draw(randNum);
lastDebounceTime = millis();
lastNum = randNum;
}
delay(100);
}
void draw(int randN) {
for (i = 0; i <= 5; i++) {
digitalWrite(pins[i], LOW);
}
for (i = 0; i <= randN; i++) {
digitalWrite(pins[i], HIGH);
}
}``````

Second approach: Replacing the button with a photo resistor:

In order to create a “random” pattern of LED’s define by the light ambience that the photoresistor is receiving, so I replaced the button by a photoresistor in the breadboard and merged the code from a photoresistor exercise from Instructables web site, this second exploration was made with Mikhail Pikman:

``````<!-- wp:code -->
<pre class="wp-block-code"><code>// Arduino LED Dice
// Using button debouncing logic from the Internet!
// Available on Instructables, just search it 🙂

const int pins = {2, 4, 6, 8, 10, 12};
int pResistor = 13, buttonStatus, randNum, lastNum, i, lastDebounceTime, debounceDelay = 150;
int value;
void draw(int randN);

void setup() {
for (i = 0; i <= 5; i++) {
pinMode(pins[i], OUTPUT);
}
pinMode(pResistor, INPUT);// Set pResistor – A0 pin as an input (optional)
Serial.begin(9600);
}

void loop() {

//You can change value “25”
if (value < 30){
digitalWrite(pins[i], HIGH);  //Turn led on{
randNum = random(1, 6);
} else{
digitalWrite(pins[i], LOW); //Turn led on;

draw(randNum);
lastDebounceTime = millis();
lastNum = randNum;
}
delay(100);
Serial.println(value);
}

void draw(int randN) {
for (i = 0; i <= 5; i++) {
digitalWrite(pins[i], LOW);
}
for (i = 0; i <= randN; i++) {
digitalWrite(pins[i], HIGH);
}
}</code></pre>
<!-- /wp:code -->``````

Tags: , , ,

• Kamilia Iusupova

|   