Buzzer Reacts to a Specific RGB LED Color


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:

Your final assembly should be something like this:


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:

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.


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.


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.





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.




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




(This circuit is from Vilros Ultimate Starter Kit Guide)

In the end, it should look like this:


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.


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


Connect black/brown from servo to Gnd on arduino.


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



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



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





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


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:


Download “the Leap Motion Controller

Install Leap Motion Controller


Step 2

Go to website:


Download library “LeapMotionP5 archive v0.5

Install the library



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.



Copy the code

import com.onformative.leap.LeapMotionP5;

import com.leapmotion.leap.Finger;

to the very front of the new sketch


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.



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!


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 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.

How to Control a Servo’s Angle of Rotation in Relation to a Coordinate

This tutorial explains how to control a Servo’s angle of rotation in relation to a coordinate that can be found in a typical grid of points.  You will need a(n):

  1. Arduino Uno
  2. Breadboard
  3. Servo (that can rotate 360 degrees)
  4. 6 Wires

Set Up 0

Setting It Up

Before we begin to put the parts together, make sure your Arduino board is not connected to your computer!

Set Up 2

First and foremost, the Servo needs to be connected to a proper source of power for it to work.  Make sure to plug in a red wire from the 5V pin to the positive end of the breadboard and to ground it by plugging a black wire from the GND pin to the negative end of the breadboard.

Then, connect your Servo to your breadboard with 3 jumper wires: orange wire (signal) to F8 (breadboard), red wire (+5V) to positive end of breadboard, and brown wire (ground) to negative end of breadboard.

On the same row as the Servo’s orange wire, connect a yellow wire from J8 (breadboard) to pin 9 (Arduino board).

In the end, it should look like this:

Set Up 1

Now, let’s make that Servo rotate!

Arduino Code

You will need to open up the Arduino interface before we can start writing some code.  Remember, your Arduino board is not connected to the computer, so uploading anything is completely impossible.  For your Arduino board’s safety, let’s keep it unplugged for now.

Firstly, you must include two different sets of libraries: (1) Servo.h and (2) math.h.  These two libraries provide you with the ability to use your Servo and to use the inverse tangent function.  Unfortunately, “pi” is not defined in either libraries, including “math.h”, so you must define it yourself.

We will now to declare a function that’s argument relies on the use of coordinates rather than separate x and y variables (see Diagram 1).

C:UsersTessaDocumentsArduinoprojecttutorialDiagram Model
Diagram 1: Coordinate System

Within the loop function, we will state the position of the motor in relation to the grid (see Diagram 1).  Now, we want the motor to angle towards the points located around it (which are diagrammed as circles).  In the code below, we will focus on 4 points (see Diagram 2).

C:UsersTessaDocumentsArduinoprojecttutorialDiagram Model
Diagram 2: Angle of Rotation in relation to Person on Grid

Now plug in your Arduino, upload the code and watch your Servo’s arm rotate!  You can also check out the angle of the arm in relation to the coordinate in your serial monitor!

If you like, you can expand on this tutorial by including sensors into the equation!  Instead of manually giving a set of coordinates, you can collect coordinates through a series of sensors within a built grid.  The motor’s arm will rotate to the individual’s position within that grid, thanks to the sensor!

Detecting occupied space using gridded motion sensors

This tutorial will show how to identify the coordinates of the space encompassed by objects within a grid. By using two axes with evenly spaced PIR motion detectors, multiple moving objects can be identified. In addition, when multiple objects are close together in the space, the coordinates will include any area covered on two sides by the objects themselves.

Note: Although this tutorial will use 3 total PIR detectors, the number of sensors can be expanded for larger grids with minimal changes to the code.


Figure A: Gridded PIR Sensor System



The gridded PIR sensors should be set up as shown in Figure A. In the next few diagrams, the circles represent objects in the grid, and the X’s represent the squares whose coordinates will be returned by Arduino via the serial cable. The red lines show which PIR sensors are set off by the objects.

Figure B: One Object Detected


If one object is present in the grid, it will set off  PIR sensors attached to the closest column and the closest row.

Figure C: Two objects detected in a line


If two objects in a straight horizontal/vertical line are detected, each object will be detected and the coordinates returned will only be those where the objects are located.

Figure D: Three objects detected (not in a line)


If the objects encompass a certain area on two sides (e.g. if a group of people is walking through a gridded area), the space that they enclose will also be returned as a coordinate value.

This will allow for the response to change when a group enters the space. If the group is neatly ordered in a straight line, the returned coordinates will similarly reflect a straight line. However, if the group is disorderly and spread out in the space, the returned coordinates will reflect the total area encompassed by the group.

Figure E: Objects Along a Diagonal Line


If the objects are placed along the entire diagonal, then all possible coordinates will be returned. According to the initial behavior, each returned value should be encompassed on two sides. In the diagonal case with all coordinate pairs returned, this is technically true, but some of the squares will be two squares or more removed from the actual object, which may encompass more space than desired. In order to fix this problem, additional sensors, such as force sensors on squares outside the diagonal, will provide enough input to double check the presence of objects in those areas.

This is an optional addition, but for our purposes, we will be focusing only on the PIR motion sensors in this tutorial.

Continue reading Detecting occupied space using gridded motion sensors

Using an air quality sensor


In this tutorial we will be connecting a basic air quality sensor to collect data for other applications with Arduino.  There are many sensors you can choose from depending on what gasses or aspect of air quality you are interested in.  We were particularly interested in detecting levels of benzene as an indicator of air pollution caused by combustion engines.

For this tutorial we will be using the MQ-135 sensor which detects levels of: NH3, Benzene, Alcohol, NOx, CO2 and smoke.

For a larger list of sensors check this link



Parts List

You will need:

  • An Arduino unit.  (we used the Uno)
  • MQ-135 sensor (link to source)
  • 5 – jumper wires
  • Breadboard


Set Up

When looking at the sensor there are abbreviations next to the pins you need to wire.

G = Ground

AO = Analog Out

DO = Digital Out

V = Voltage (power source)





Here is a simple diagram of how your sensor should be wired to your Arduino.

Note:  If you are using this particular sensor board you do not need to use a 10 ohm resistor as some of the basic diagrams for this sensor indicate.

gas sensor_bb


Here we have the sensor set up.



Close up of the sensor and the wiring.



For our power source we used the on board 5V output from Arduino.  We wired that to the “V” tab of the sensor board

Next we wired the “G” tab to the ground on the Arduino.

The last step was to wire the Analog Output (AO) to the A0 input on the Arduino.



In our code we wanted to float the voltage readings so that we could eventually use it in Processing applications.

We also wanted to convert the voltage readings of 0-1023 from the sensor to a 0.0-5.0 value which would reflect the true voltage being read.


Run this code to your Arduino and you will be ready to detect changes in the level of detectable gasses!



  • After doing some research about this sensor it was discovered that while the MQ-135 can detect all of the gasses listed above, it cannot distinguish between them.  If you are looking to specifically target one gas, it might be better to find a different sensor.
  • This sensor also needs uses a heater to warm up the sensor.  It has been advised to not use this with a small battery source as it will quickly drain your battery.

Additional Information:

Turn Environmental Light Conditions Into a LED Power Switch

This tutorial allows you to turn environmental data, in this case the amount of light in the setting you are working in, into an on/off switch for LED lights. This tutorial is a precursor to a more complicated setup that will be deployed for turning data gathered by a weather shield into conditions for selecting functions on a Raspberry Pi.

Tutorial Parts List:

  • Arduino UNO (1)
  • Breadboard (1)
  • Photo resistor (1)
  • Jumper wires (7)
  • 10k Ohm resistor (1)
  • 330 Ohm resistor (2)
  • Red LED (1)
  • Yellow LED (1)

Arduino Setup:

Let’s start by setting up the hardware on our Arduino board. Note: the short leg (the negative side) of the LED lights should be below the long leg (the positive side) in this setup. Use the following diagram to guide your setup:



You may also find the following circuit diagram helpful for your setup:



Once you have your board set up, it’s time to enter our code into Arduino. What we are looking to accomplish here is getting our Arduino to sense the level of light in the environment, and use that input to determine which LED light should turn on or off. This tutorial could be altered in many ways, you could use only one LED, and simply have that light turn on/off according to light level. You can also alter the level of brightness/darkness Arduino will use to determine whether the LED(s) should be turned on or off.


The following video illustrates what you should see when you are finished! I used a small keychain light to demonstrate the change of the LED lights under different light conditions. As mentioned earlier, you can alter the light level needed to switch the LEDs on/off in the code.


Environmental Sensing and Responsive Design