Category Archives: TUTORIALS

How to build a 5X5 LED matrix

Janet's LED matrix

This tutorial will cover the basic knowledge you need to hack your way at a self-made LED matrix. We will use open source instructions available online from various groups to learn about the components of this kind of project and to acquire code to control the LED matrix. Various sources for each of the components will be given. As will become apparent, there are many ways to solve a circuitry problem. Our main “problem” when making a 5X5 LED matrix is the limited number of Arduino output pins we have to control it. In this tutorial we will be controlling 25 LEDs using Shift registers and NpN transistors to minimize the number of Arduino pins needed to control the lights.
Your needed materials are:
– 1 Arduino Uno
– 2 Shift registers (I use 74HC5950)
– 10 NPN transistors (BC547)
– 5 1kohm resistors (for base of transistors)
– 10 100 ohm resistors (for the emitters of the transistors)
– 25 LEDs ( I use blue)
– Lots of wire
– Solder and soldering iron
We will start by watching a video that covers the basics. [ VIDEO: https://www.youtube.com/watch?v=GPokkuX_jjk ]
The main concepts from the Make video by Collin Cunningham are:
• LED matrix ( powering and controlling LEDs through columns & rows)
• How to bend the anode and cathode legs to create LEDs in parallel to create your own matrix
• Multiplexing using a serial LED display driver
Collin Cunningham gets fancy and uses an already build LED matrix and even makes his own printed circuit board. In order to lower costs we will be using some different methods to multiplex, but this video is by a charismatic character who quickly shows the process.
The initial inspiration for the configuration used in this tutorial comes from instructables.com by user Osgeld. [ HACK: http://www.instructables.com/id/The-74HC164-Shift-Register-and-your-Arduino/?ALLSTEPS ] The user goes through 3 possible projects using Arduino and Shift registers. The third project is the matrix controlled by using a shift register and transistors. He provides code for this configuration, which is always nice. The following two figures show the logic and circuitry behind the hardware.

osgeld circuit

Figure 2 Circuit by Osgeld on the Instructables page

Shift register Daisy chain

Figure 3 It is helpful to have a circuit diagram to help you as you wire

YouTube user Andrew Ong produced a great video that shows his digital model of a similar configuration. [ VIDEO: https://www.youtube.com/watch?v=2m3PbCvcqkY ] He points out the importance of choosing the right components to avoid a dimming effect and explains how the signal moves through the circuit.
If you work well with text this online Arduino workshop has a good explanation of LED matrices. http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html
As you can see there are 5 components to this project: the Arduino, shift registers, transistors, LEDs, and of course resistors. We already know about the Arduino, so we need to give homage to electrical engineers and watch some videos that explain the necessary components needed to multiplex with LEDs. The videos will explain (in varying depth) the uses, coding, and mechanism behind each component. It is helpful to have the data sheets of the components you are using while watching these videos. You should also pay attention to the symbols they use when drawing the circuits, it will help you learn how to interpret circuit diagrams for future projects.

LEDs and resistors:
EEEnthusiast is a user of YouTube, he produces very thorough explanations on electrical topics. His video “Arduino Tutorial #1 – Extended – Limitations I/O pins, Pull-down, Current Resistor Calculations” explains current resistor calculations with Arduino.(https://www.youtube.com/watch?v=gGDq_-WKMfE&list=UU6JpBeS_6JhUwfGF8RgLCIQ)
A great follow up is “Resistance for LEDs Tutorial” by YouTube user Kevin Darrah. He explains the calculations needed to choose a resistor for your LEDs, although you use the same principle to calculate for other components as well. If you need additional help understanding resistors he has several other videos explaining their use and he points out the different symbols used when drawing circuits. When you are ready, he also has instructions on building other fun things like LED cubes. (https://www.youtube.com/watch?v=7PzohqhABj4)
When you are ready to calculate the resistant using Ohms law, there are handy websites (like http://www.ohmslawcalculator.com/led_resistor_calculator.php ) that can help you.
Transistors
Kevin Darrah also has a video explaining multiplexing LEDs with transistors that explains the hardware and software for controlling a matrix. https://www.youtube.com/watch?v=lZyc6ulpkyM There are may other videos that explain transistors, I recommend other by EEEnthusiast and Kevin Darrah such as:
‘How to work with Transistors’ by Kevin Darrah: https://www.youtube.com/watch?v=6RN1hnwBj3Y
‘How to Multiplex/ Part II’ by Kevin Darrah: https://www.youtube.com/watch?v=-1UPPHjR0vk&src_vid=lZyc6ulpkyM&feature=iv&annotation_id=annotation_397974
He explains why you use resistors on transistors, and how to multiplex the transistors to control the cathode and anode columns and rows.
‘Arduino #11 – High Current & Voltage Loads Tutorial – Transistors and Relays’ by EEEnthusiast (IF you are working with components that need higher voltage): https://www.youtube.com/watch?v=JJB_ICWYIqg&list=UU6JpBeS_6JhUwfGF8RgLCIQ
GarageLabe.com posted a tutorial on an 8×8 matrix that gives the best explanation on using transistors to create the persistence of vision effect that allows us to multiplex LEDs. It goes through the logic of coding for LEDs in parallel. The post also contains the basic layout of code to control a matrix using transistors. http://garagelab.com/profiles/blogs/arduino-scrolling-text-marquee-to-give-a-happy-christmas

Shift registers
The shift registers in the 5X5 matrix we want to build will allow us to control all 25 LEDs from 3 pins on Arduino. The 74HC595 is an integrated circuit that has 8 outputs, we need two of them because we have 10 transistors that will need to be connected to it. The transistors themselves are each connected to a row or column controlling 5 LEDs. You can also get some shift registers that have many inputs if what you need for a project are additional ins.
‘Arduino Tutorial #3 – Shift Registers (74HC595)’ by EEEnthusiast has a thorough explanation of coding for shift registers as well as the configuration for the 74HC595 model https://www.youtube.com/watch?v=bqfPZXEuyuc

Need more? Try:
74HC595 Shift Register Control | AVR Tutorial by 000Plasma000 https://www.youtube.com/watch?v=d7Au3I4ZdZc
‘Multiplexing with Arduino and the 74HC595’ by amandaghassaei
http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/step2/How-does-the-74HC595-work/
A very similar circuit and code that is easily adapted
http://tronixstuff.com/2010/06/06/getting-started-with-arduino-chapter-nine/

Soldering
When building your own LED matrix it is important to solder the components appropriately. Watch this quick video by Collin Cunningham to get all the basics on soldering. https://www.youtube.com/watch?v=QKbJxytERvg
It is important when building a matrix that the row and column wires do not touch. This can be accomplished by using electrical tape to protect on of them from the other, as I have done. Alternatively, this can be accomplished by bending them appropriately to create a space between the two, as seen in this image from instructable.com

Separating Cathodes and Anodes

Figure 4 http://www.instructables.com/file/FLQPWTJFHAVXW8W
Now that you have your matrix built and connected test out your grid using test code. You will have to modify the code to match your wiring. I wanted to test the circuit so I adapted code from tronixstuff.com just to make sure the LEDs were getting power. For my matrix, one shift register controls cathodes and another the anodes
//// Modfied from http://tronixstuff.files.wordpress.com/2010/06/example9p1.pdf
int latchpin = 4; // connect to pin 12 on the ‘595
int clockpin = 3; // connect to pin 11 on the ‘595
int datapin = 2; // connect to pin 14 on the ‘595
int matrixrow[5] = {
1,2,4,8,16};
int matrixcolumn[5] = {
1,2,4,8,16};
void pixeldisplay(int row, int column, int holdtime)
// turns on and off a pixel at row, column – with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]); // sets the digit to address
shiftOut(datapin, clockpin, MSBFIRST, matrixrow[row-1]); // clears the digit
digitalWrite(latchpin, HIGH);
delay(holdtime);
}
void rowdisplay(int row, int holdtime)
// turns on and off a row of LEDs with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 255); // we want all the cathodes on, which is 11111111 in binary, 255 decimal
shiftOut(datapin, clockpin, MSBFIRST, matrixrow[row-1]); // clears the digit
digitalWrite(latchpin, HIGH);
delay(holdtime);
}
void columndisplay(int column, int holdtime)
// turns on and off a column of LEDs with delay ‘holdtime’
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]);
shiftOut(datapin, clockpin, MSBFIRST, 255); // we want all the anodes on, which is 11111111 in binary, 255 decimal
digitalWrite(latchpin, HIGH);
delay(holdtime);
}
void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
}
void loop()
{
for ( int a = 1; a < 10; a++) {
for ( int b = 1; b < 10; b++) {
pixeldisplay(a,b,50);

for ( int a = 1; a < 10; a++) {
for ( int b = 1; b < 10; b++) {
pixeldisplay(b,a,50);
} } } } }

Playing an Audio File with Processing

In this tutorial, we will demonstrate how to use Processing to play an audio file of your choise. We intend to use this function as part of a larger project involving the use of sensors in public spaces to trigger pre-recorded sounds when people pass through the space. In this larger project, the function we describe here will be linked with the function of using a piezo sensor to detect vibration.

INGREDIENTS:
Arduino UNO
Processing software
IMG_3248 Processing code

While it is possible to use arduino to play individual audio files in mono, Processing allows for the playback of audio files in stereo, and can overlap multiple audio files at once.

To clarify this terminology, “mono” means the audio file has a single audio channel, as opposed to the left and right audio channels of stereo audio files. Virtually all contemporary music is formatted in stereo, and it is the format we are accustomed to listening to.

Processing is capable of performing these magical feats of musical playback by virtue of the Minim library. Minim comes included with Processing software. It can also be used outside of Processing, but we’re not going to get into that here.

The only assembly required to run this function is to connect your arduino to a computer via usb. Do this now.

Next, open a new Processing file. Save it under your file name of choice (I called mine “Minim_1”). When you save, a folder will be generated to contain your Processing file. This folder will have the same title as your processing file.

Next, select an audio file, something short. Place your audio file in the Processing folder that you just generated. We chose a Napalm Death song titled “You Suffer”, which lasts about 3 seconds. It’s amazing, and downloadable here if you want to use my code.

If you do use this file, re-title it “you_suffer.mp3”, place it in your Processing folder, and use the code I provide below.

If you wish to play a different audio file, this link provides you with code to do so, as well as lots of helpful info about Minim.

To play the audio file you have now placed in your Processing folder, simply plug it in to the code provided by the link by deleting the song title they have in quotes (“mysong.wav”), and typing in the file name of your audio file between the quotes (e.g. “you_suffer.mp3”).

Here is the code we used:

That’s it on your end, the code handles all the rest of the work, importing the Minim library and using an audio player function to play your audio file.

When you run the code, a small window will appear to the side, and your audio file will play. It looks like this:Processing2

Happy jamming!

Using Piezo Sensors to Detect Vibration

Using Piezo Sensors to
Detect Vibration

In this tutorial, you will learn how to use a Piezo sensor to detect vibration. We intend to use this function as
part of a larger project involving the use of sensors in public spaces to turn on background music and trigger
pre-recorded sounds when people pass through the space. To keep things simple, however, this tutorial will
stick to the simpler concept of the film sensor perceiving vibration.

IMG_3115

 

INGREDIENTS:
• Arduino UNO
• Solderable breadboard
• (1) LM358 OpAmp
Integrated Circuit
• (1) Piezo sensors
• (1) Potentiometers
• (1) 1 mega-ohm resistor
• (1) Zener 5.1V 1 Watt diode
• (1) 0.1 uF capacitor
• Jumper wires

The first step is to put your circuit together.
The image below shows the completed circuit using a solderable breadboard.
In the bottom left of the image the green and yellow wires are coming from the piezo element. The yellow is
the ground, the green is the positive output. A resistor is used for the component. To prevent voltage spikes,
a diode is added in parallel to protect other parts of the circuit.
The signal is taken into the op amp. The op amp amplifies the signal from the piezo element, and sends
that signal from one side of the op amp to the other. The right side of the op amp receives the signal, and is
used for amplification of the signal. The left side gets the amplified signal from the right side, and is used for
a comparator, determining which values to designate as high or low. The potentiometer adjusts the sensitivity
of the comparator, and thus the sensitivity of the trigger.
The output of the comparator provides the input for the arduino. Using our code, this input determines the
display in the serial monitor, either “EARTHQUAKE” when motion is detected, (a HIGH reading) or “CHILLIN”
when motion is not detected (a LOW reading).Piezo Diagram

This diagram illustrates the flow of the signal through the circuit:

 

Tutorial 3_Circuit Diagram

The completed code and serial monitor display look like this:

Code and Serial Monitor

 

 

 

Detecting the absence of light to gradually switch on LED(s).

In this tutorial we will be looking at how to use a photo resistor to turn on an LED light with the absence of light. this is useful for when the sun goes down and you need that extra light for a sense of comfort, or for generating an ambient setting in any space. This applies directly to a project that i am working on with a group in which we will be activating a dead space such as an ally way and providing a sense of safety at night time. With the small application applied to our greater idea we will be able to generate an ambient light to encourage people into a feeling of a safe environment.

To begin we will need all the parts listed below.

PARTS LIST
* 1 X Breadboard $4.95
* 1 X Arduino Uno $29.95
* 1 X LED pack $2.95
* 1 X 330 Resistors $0.95
* 6 X Jumper Wires $4.95
* 1 X Photo Resistor $1.50
* 1 X 10 K Resistors $0.95
Total = $46.20 (tax and shipping not included)

step 1: HARDWARE CONNECTIONS
taking the Photo resistor you’ll need to connect one side of the photo resistor to 5 volts labeled on your arduino as (5V). Next take the other end and connect it to the analog pin 0. You no want to create a voltage divider by connecting a 10K resistor between ANALOG pin 0 and the ground or GND. This is now a voltage divider, with the photo resistor being one of two dividers. What this allows is for the output of the voltage divider to vary in the light level.
LED: now connect the positive side (long leg) of the LED to digital pin 9. (To vary the brightness, this pin must support PWM, which is indicated by “~” or “PWM” on the Arduino itself.)
Connect the negative side of the LED (short leg) to a 330 Ohm resistor.
Connect the other side of the resistor to GND.
this is a simple diagram to help explain its set up construction for piecing together the parts into a functional process.
fritzing diagram

——-
Step 2: Const int
Now that you have all the pieces connected we will designate your constant integers. Start by typing out “const int” it should highlight itself and after adding a space designate which pin the photo resistor will be sensing from in its analog output. After typing that first const int repeat the process with const int ledpin = 9; and don’t forget to end it with a semicolon.
Now we will also set up some global variables for the light level:

“int lightlevel, high = 0, low = 1023;”

This is telling the arduino the voltage boundaries.

——-
Step 3: void setup()
Begin your next line of code by typing “void setup()” press enter and start the next line with a curly bracket
“{”
(Again look ahead below in this tutorial to get a clear idea of how i’m referring to the code.)
next you will press enter again to start the next line and type in “pinMode(ledpin, OUTPUT);”

It is case sensitive so make sure that the variables you are using are the same as the ones you previously defined.
Press enter again and close off the void setup with a closed curly bracket “}”

——-
Step 4: void loop()
Start your next line by typing in “void loop()” and then enter. Your next line should be a curly bracket

“{“.

Next comes something possibly new. It’s called “analogread”. It measures the voltage coming from the photo resistor and resistor pair. This number can range between 0 (0 volts) and 1023 (5 volts), but this circuit will have a smaller range between dark and light.
So after that curly bracket has been placed as mentioned previously you want to then start your next line and type in

“lightLevel = analogRead(sensorPin);”

Remember to pay close attention to what is capitalized and what is not based on what you have designated in your global integers and constants.

So now we want to use this number to control the LED. But we have a problem: the analogRead() function returns values between 0 and 1023, and the analogWrite() function wants values from 0 to 255.

We can solve this by using two handy functions called map() and constrain(). Map will change one range of values into another range. If we tell map() our “from” range is 0-1023, and our “to” range is 0-255, map() will squeeze the larger range into the smaller. (It can do this for any two ranges.)

i.e. lightLevel = map(lightLevel, 0, 1023, 0, 255);

Because map() could still return numbers outside the “to” range, (if they’re outside the “from” range), we’ll also use a function called constrain() that will “clip” numbers into a given range. If the number is above the range, it will reset
it to be the highest number in the range. If the number is below the range, it will reset it to the lowest number. If the number is within the range, it will stay the same.

i.e. lightLevel = constrain(lightLevel, 0, 255);

Here’s one last thing to think about. The circuit we made won’t have a range all the way from 0 to 5 Volts. It will be a smaller range, such as 300 (dark) to 800 (light). If we just pass this number directly to map(), the LED will change brightness, but it will never be completely off or completely on.

so your next line of code should read as follows

“manualTune();”

This allows you to manually change the range from light to dark. now press enter to prepare for your next line of code.

The above functions will alter lightLevel to cover the range from full-on to full-off. Now we can adjust the brightness of the LED by typing in your next line of code

“analogWrite(ledPin, 255-lightLevel);”

By having lightLevel in this analog write segment being changed to 255-lightLevel it is now able to brighten the LED with the absence of light.
next you’ll press enter and end this void loop() with a closed curly bracket

“}”

step 5: Manual tune
you are now defining the variable manual tune and describing in code to the arduino what it means to have manual tune.

Begin a new line of code with:

“void manualTune()” press enter for a new line and type:

“{”

to signify the beginning of its definition.

next type:

“lightLevel = map(lightLevel, 0, 1023, 0, 255);”
“lightLevel = constrain(lightLevel, 0, 255);”

You can change the 0 and the 1023 for a different range of output in light intensity.
Now you want to return the main loop (), and send lightLevel to the LED. close this definition off with a curly bracket and your code is complete

“}”

compare to the code below for reference in how it is layed out.

———

CIRCUIT DIAGRAM

circuit diagram of a Photo resistor.

In this diagram, it is showing how you’ll be using a photo resistor. A photo resistor changes resistance based on how much light the sensor receives. Since our Arduino’s cannot interpret resistance directly, rather it reads voltage, we use a voltage divider to use our photo resistor. This voltage divider will output a high voltage when it is not getting any light or it will output a dim light when light begins to fade. in opposition, its output is a low voltage when it is receiving light. if tweaked right its low voltage will not be read and will be perceived as “off”.

Here is an example of what your code should look like.

——-
this would be a physical construction of the arduino board set up to sense an absence of light.

photo

here are some photos of it in action in which a the photo resistor detects light and is not active or has a low output.
light detected no led 1

now with my finger barely covering the photo resistor the led starts to grow in its output of energy.
no light detection 2

i am now covering the photo resistor in an attempt to mimic full darkness in which now the LED is at a full glow.
no light full glow 3

again i remove my finger barely to allow the photo resistor to receive a pinch of light which in turn lowers the output of energy. the bulb is at a low glow now, and then placing it back over the photo resistor once more allows the arduino to register a high low voltage and its output then becomes higher through the LED.
low light detection  low output 4no light detected full glow 5

Buzzer Reacts to a Specific RGB LED Color

BUZZER REACT TO A SPECIFIC RGB LED COLOR:

Introduction:
In this tutorial it will be explained that how buzzer reacts to a specific RGB color. For example, it could be an alarm for specific situation, which is defined by colors. That is, as the color of RGB changes, the alarm sound changes and has a specific meaning.
Note: This tutorial only focuses on one color and one sound. Based on, different voltage and different RGB colors, buzzer could be applied for more kinds of notes and sounds.
Parts list:
• Arduino UNO (1)
• Breadboard (1)
• RGB LED (1)
• Jumper wire (11)
• 330 Ohm resistor (3)
• Piezo element (1)
• Potentiometer (1)

How to set up:
The first thing should be done is assembling all parts on the breadboard. Then, start coding.
Note1: Be sure that RGB led legs are connected correctly (in terms of colors and Common leg which is connected to GND without resistor).
Note2: Most LEDs are designed to work with a voltage between 1.5v and 3v. As most microcontrollers (including the Arduino) operate on 5 volts a current limiting resistor is required.
The following diagram shows how to assemble the parts on the breadboard:
instruction

Your final assembly should be something like this:

photo(3)

Code:
Please note that your Arduino must not be connected to the computer. Otherwise, the power might damage or burn out the parts. The code is as follows and next to each part it is explained what each part does.

Now to see the result, plug in your Arduino, upload your code and tern the potentiometer. The result should be like this video:
Video

Many thanks.

Lighting Multiple LED’s with Multiple Photo Resistors

This tutorial describes how to control two sets of multiple LEDs using two photo resistor sensors. This is a lab responsive to different light conditions in one setting so as for lights to react appropriately to its particular conditions. This procedure will define how to set up an array of lights and how to adjust them into two groups for each to respond to its particular light resistor reading. In essence, the overall goal will be to achieve responsive lighting as an effect of multiple data collections.

The parts list:

1. Arduino UNO

2. 6 LED lights

3. 6 330 Ohm Resistors

4. 2 Photo Resistors

5. 2 10k Ohm resistors

6. Jumper Wires

Step 1 Setting LED’s

We will first place a wire connecting 5V to a positive strip of the breadboard and a wire connecting ground (GND) to a negative strip of the breadboard.

We will now begin placing the 6 LED’s onto the breadboard. Each LED is placed round side up (positive) and flat side down (negative). The LED wires should be aligned on the y-axis. Give adequate space from LED to LED, in this sample they are spaced by one block apart. The next step is to apply the 330 Ohm resistors. Each LED should contain one 330 Ohm resistor connected to its negative or flat side of the LED and grounded onto the negative strip of the breadboard.

IMG_2550

The next step is to apply a pin number to each of the LED’s. In this sample we have avoided the use of TX, RX and PWM pins (0, 1, 3, 5, 6, 9, 10, 11) due to malfunction in the reception of instruction for each LED. We have applied a pin to the positive side of each LED. We utilized pin 13, 12, 8, 7, 4, and 2 and applied it in such order from top to bottom.

IMG_2552

Step 2 Setting Photo Resistors

For the second step we must apply the photo resistors. We apply one of them aligned to the y-axis. We then apply a 10k resistor also aligned to the y-axis. The bottom of the 10k resistor should be on the same line as the top of the photo resistor. Also, the top of the 10k resistor must be connected to the 5V using a wire connected to the positive strip of the breadboard. (Refer to drawing). The bottom of the photo resistor must also be grounded. Last but not least, the photo resistor must be given a pin for it to register data. For this we will use an analog pin A0. Repeat the same process using different squares on the breadboard for the second photo resistor. The only difference for the second photo resistor will be the assigned analog pin, analog pin A1.

IMG_2556

 

ArduinoCircuitSample

ArduinoCircuitSample

Step 3 Coding

We start the code by stating all the pins in use. First we indicate both analog pins A0 and A1. Second we create two arrays each storing a separate group of pins. We grouped pins 13, 12 and 8 into one and 7, 4, and 2 on the pin A1. We also require a pincount for each of the arrays. Each has a specific name and the number of pins per group, in this case 3 per array.

Void Setup

The next step is setting the void set up. Here we will setup an index to organize the pin order. We will also use a “for” statement to repeat a block statement or set of instruction. In this case we
declare a variable (index = 0), a test (index < pincount), and
an increment (x++). Thirdly we must declare the sensorpin as an OUTPUT, pinMode(ledPins[index], OUTPUT);. These three steps must be repeated for the second array of LED’s as shown on the image below.

Void Loop

For the void loop we must indicate a light level. This will be determined by the read on the photo resistors. Therefore, we indicate lightLevel = analogRead(sensorPin). Keep in mind this is the read for the first sensor. The next step is important in manufacturing an applicable number range of light for Arduino. Because the range is primarily (0-1023) we must manually adjust it to smaller range suitable for, (0-255). This is input as manualTune(), but is further developed as its on void after the void loop instructions.

Our next step is to identify our data received from the photo resistor and construct an instruction for the LED’s based on the data received. For this we create a “for” statement to create a set of instruction for each of the LED’s for (index = 0; index < pincount; indext++). This shows the variable, the test variable and an instruction.

We now want to tell the LED Pins where to start and what to do when receiving data. We start with an off light, analogWrite(ledPins[index], 0 or LOW);. When the photo resistor receives no evidence of light we want the LED to turn on, so we write analogWrite(ledPins[index], (lightLevel));. Add delay after this whole process to ensure that data readings are not being read simultaneously but one after the other.  Repeat this process for the second array of LEDs withing the void loop.

Manual Tune

Our final step is defining the manualTune called out in the void loop. This simply re-maps the large range light values to a range more manageable for the LED. So we describe a void manualTune(). We indicate the range we want to replace (0-1023) and place the new range (0-255), lightLevel = map(lightLevel, 0, 1023, 0, 255). Are last step is determining the new constraint of the range, lightLevel = constrain(lightLevel, 0, 255);.

 

Each photo resistor should be accommodated to 3 pins and respond to its condition within its environment.

IMG_2543

IMG_2544

Reference 

http://arduino.cc/en/Reference/HomePage

http://www.hackerscapes.com/2014/09/lab-4-communicating/

Communication Between Processing and a Servo

In this tutorial , you’ll explore the communication by talking with Processing and allow the processing to control the servo.

Parts Required

1. Arduino Kit

2. Servo

3. Jumper Wires

Circuits

3

 

(This circuit is from Vilros Ultimate Starter Kit Guide)

In the end, it should look like this:

2

You see, it’s really very simple to connect the servo to the arduino board.

Now, let’s build the communication!

1. Download Processing.

2. Here is a tutorial from Sparkfun to learn how to build the connection between Arduino and Processing .

3. So far we’ve shown that Arduino and Processing can communicate via serial that allows data to flow both ways. Coming after: making our servo rotate.

Power

Connect the red from servo to +5V on arduino.

Ground

Connect black/brown from servo to Gnd on arduino.

Signal

Connect white/orange from servo to pin~9 on arduino.

ARDUINO CODE

 

This is what your code should look like when you’re done:

5

PROCESSING CODE

This is what your code should look like when you’re done:

6

 

Reference
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing

http://www.hackerscapes.com/2014/09/lab-4-communicating/

 

Wave Simulation in Processing

Wave movement in processing We want to simulate a wave movement based on the up-and-down of a grid of balls. I have imagined of two kinds of ways that we can interact with our wave grid: -Point based control: The wave is simulated starting from a point, and moves towards all directions from that very point. We will gonna control the position of the point that affects the grid, by mouse position, or Leap Motion gesture position. -Line based control: The wave grid is affected by a line, and moves in the vertical direction of the line. The line is adjusted by our mouse position or Leap Motion gesture position.

  • The grid of balls

We will write a class for the grid. They are the basic class that we will simulate the movement of grid. I have used  IGeo  Vector library here.

 

  •  Control the grid by point

Here I will write a class that functions as a point field that can affect the position of the grid.

For this point field, it is capable of calculating the distance to each ball in the grid, and thus change the position based on the distance, through the calculation of the cos value based on the distance, the wave distance, the phase, and the circulation.

  •  Control the grid by Line

Here I will write a class that functions as a line field that can affect the position of the grid. It is based on a line2d class that can help me do some geometry calculation.

Based on the line class above, I wrote a line wave class which will utilize the functions to affect grid nodes according to the distance to the certain line described in the way of line2d class.

  •  The Main function of the point control simulation software

We need this main function that will utilize the class of grid and pointwave that we wrote, thus to finalize the simulate of the behavior of the wave movement based on our control of that point. We will start with the mouse control, which is a function built in processing, and later on we will use the Leap Motion control to replace the mouse Position here.   In order to show 3D perspective in a more controled way, I have used a 3D camera library called peasy camera here.

 

How to use Leap Motion create vectors

Introduction

In this tutorial, you will be able to use  Leap Motion sensor to create vectors. This tutorial shows capability to our “Wind [Motion] Chime” setup which is use Leap Motion to control the Wind Chime move up and down and make sounds.

Tutorial Parts List:

  • Arduino UNO (1)
  • Leap Motion (1)

Step 1

Go to website: https://www.leapmotion.com/setup?lang=en

3.0

Download “the Leap Motion Controller

Install Leap Motion Controller

 

Step 2

Go to website: http://www.onformative.com/lab/leapmotionp5/

1.0

Download library “LeapMotionP5 archive v0.5

Install the library

4.0

 

Step 3

Processing Code

Go to the “File” menu –> Examples drop down, you should be able to see the names of the new library that you’ve just installed. Find out “active_fingers”, and open up.

6.0

 

Copy the code

import com.onformative.leap.LeapMotionP5;

import com.leapmotion.leap.Finger;

to the very front of the new sketch

5.0.

In the “active_fingers” example, Leap Motion could sense 5 fingers’ movement and draw ellipse.

In the new processing code, we use Leap Motion to create vectors.

7.0

 

Here’s the Sketch for the example: active_finger:

 

Here’s the Sketch for the “Leap Motion Wave”:

 

 

 

 

 

Getting wind speed from an anemometer

Anemometer - Whole setup

Getting Started

This tutorial shows how to use an Ardunio and an Adafruit anemometer to measure wind speed.

Parts List

  • Arduino board (we use an Arduino Uno in this tutorial)
  • Breadboard
  • Wires and alligator clips
  • Anemometer Wind Speed Sensor – Adafruit (product ID: 1733)
  • Wall adaptor power supply 9 volts (or other power source that can provide between 7 and 24 volts)

Hooking it up

The anemometer connects to the rest of the circuits through a single waterproof cable that bundles three wires. These three wires stick out of the end of the cable, each a different color: brown, black, and blue. The brown wire should be connected to the positive power source. The black should be connected to ground, and the blue is the output for the anemometer.

To more easily connect to the Arduino, wrap each wire from the anemometer around the male terminal of a jumper wire. Secure with an alligator clip (Figure 1).

Anemometer - Anemo wiring
Figure 1: Connecting the anemometer wires

Using the jumper wire, connect the brown wire to the Vin pin (called 9V on some boards). Connect the black wire to one of the ground pins. Connect the blue output wire to one of the analog pins. For this tutorial we used pin A0. Figure 2 shows the circuit diagram for the entire assembly. Figure 3 shows the connections on an actual Arduino Uno.

Anemometer - Wiring Diagram
Figure 2: Arduino attachments for anemometer

 

Anemometer - Arduino wiring
Figure 3: Arduino wiring

The anemometer requires a power source between 7V and 24V to produce a measurement. Arduinos use a lower voltage, between 3V and 5V, so the power coming to an Arduino through a USB connection isn’t enough to power the anemometer.

Instead, we’ll use another the external power supply on the board, sometimes labeled X1. This port accepts a female coaxial cable and is appropriate for ranges between 9V and 12V. To use this power source without damaging itself, the Arduino board uses a linear voltage reducer to bring it into the 3V-5V range. However, out anemometer can still access the full voltage if we connect it to the Vin pin (this is why this pin is labeled 9V on some boards).

You can use several sources for the external power supply. One option is to use a standard rectangular 9V battery. However, these batteries are designed for very low current uses for long periods of time (in smoke detectors, for example). The Arduino and anemometer will quickly use up the charge in the battery, leading to fluctuating voltages and bad readings from the sensor. The better option is to buy a wall adapter that produces 9V of steady, higher current power.

Once the wiring is complete and the external power source is connected, the hardware is ready to go. Lets get the software side up and running and measure some wind!

Software

The code for this tutorial takes the voltage output from the anemometer and uses the technical specs from Adafruit to convert the voltage into a wind speed. The anemometer is designed to output voltage between 0.4V and 2V. A value of 0.4V represents no wind and 2V represents a wind speed of 32.4 m/s. The relationship between voltage and wind speed is linear, meaning that each increase of 0.1V represents an increase of 2.025 m/s in wind speed. The following code maps the output values from the anemometer to wind speed using these values.

The Script

Thanks!

Thanks to the rest of the Particle Wave team for their review of the wiring and code for this tutorial. Special thanks to Adafruit forum users shirad and adafruit_support_mike for help in trouble shooting code and hardward, including provided code of their own for comparison and inspiration.