Showing posts with label 06.Sensors. Show all posts
Showing posts with label 06.Sensors. Show all posts

Sunday, July 24, 2016

Ping Ultrasonic Range Finder


The SEN136B5B is an ultrasonic range finder from Seeedstudio. It detects the distance of the closest object in front of the sensor (from 3 cm up to 400 cm). It works by sending out a burst of ultrasound and listening for the echo when it bounces off of an object. It pings the obstacles with ultrasound. The Arduino board sends a short pulse to trigger the detection, then listens for a pulse on the same pin using the pulseIn() function. The duration of this second pulse is equal to the time taken by the ultrasound to travel to the object and back to the sensor. Using the speed of sound, this time can be converted to distance.


Step 1: What You Need?

Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.

The 5V pin of the SEN136B5B is connected to the 5V pin on the board, the GND pin is connected to the GND pin, and the SIG (signal) pin is connected to digital pin 7 on the board.





Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.

Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 06.Sensors >> Ping

Click press the "upload" button (see the button with right arrow mark).
Note: You also can replace the SEN136B5B with Ultrasound Ultrasonic Sensor HC-SR04, refer to here.

06.Sensors Ping

Memsic 2125 Accelerometer



The Memsic 2125 (datasheet) is a two-axis accelerometer capable of measuring acceleration up to plus or minus 2g. It has a simple digital interface: two pins (one for each axis) emit pulses whose duration corresponds to the acceleration of that axis. By measuring the length of that pulse, in microseconds, using the pulseIn() function, it is possible to determine the rate of acceleration and to use that data for your purposes.



Step 1: What You Need?

Don't have components? Don't worry. Just click the component's name. 



Step 2: Build Your Circuit.

Use the small triangle on the Memsic to properly orient the sensor on your breadboard. Connect the 5V and GND pins of the Memsic 2125 to the power and ground ports on the board. Connect digital pin 2 of the board to the X out pin of the accelerometer, and digital pin 3 to the Y out pin.

Your Arduino  must be connected to your computer in order for it to transmit serial data.



Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.


Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 06.Sensors >> Memsic2125

Click press the "upload" button (see the button with right arrow mark).

Download:

Arduino IDE




Sources:https://www.arduino.cc/en/Tutorial/Memsic2125

06.Sensors Accelerometer library Memsic2125

Saturday, July 23, 2016

Knock


This tutorial shows you how to use a Piezo element to detect vibration, in this case, a knock on a door, table, or other solid surface.

A piezo is an electronic device that generates a voltage when it's physically deformed by a vibration, sound wave, or mechanical strain. Similarly, when you put a voltage across a piezo, it vibrates and creates a tone. Piezos can be used both to play tones and to detect tones.

The sketch reads the piezo output using the analogRead() command, encoding the voltage range from 0 to 5 volts to a numerical range from 0 to 1023 in a process referred to as analog-to-digital conversion, or ADC.

If the sensors output is stronger than a certain threshold, your board will send the string "Knock!" to the computer over the serial port.

Open the serial monitor to see this text.


Step 1: What You Need?

Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.

Piezos are polarized, meaning that voltage passes through them (or out of them) in a specific direction. Connect the Black wire (the lower voltage) to ground and the Red wire (the higher voltage) to analog pin 0. Additionally, connect a 1-megohm resistor in parallel to the Piezo element to limit the voltage and current produced by the piezo and to protect the analog input.

It is possible to acquire piezo elements without a plastic housing. These will look like a metallic disc, and are easier to use as input sensors. Piezo sensors work best when firmly pressed against, taped, or glued their sensing surface.

Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.

Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 06. Sensors >> Knock

Click press the "upload" button (see the button with right arrow mark).

In the code below, the incoming piezo data is compared to a threshold value set by the user. Try raising or lowering this value to increase your sensor's overall sensitivity.

Download: 




06.Sensors Knock library

ADXL3xx Accelerometer


This tutorial shows you how to read an Analog Devices ADXL3xx series (e.g.ADXL320, ADXL321, ADXL322, ADXL330) accelerometer and communicate the acceleration to the a personal computer through the serial monitor of the Arduino Software (IDE) or another application that receives data over the serial port.

This tutorial was built using the breakout boards from Sparkfun. The adafruit accelerometer breakout board also works, though it must be wired differently.

The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. To read this, all you need is the analogRead() function.


Step 1: What You Need?

Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.

The accelerometer uses very little current, so it can be plugged into your board and run directly off of the output from the digital output pins. To do this, you'll use three of the analog input pins as digital I/O pins, for power and ground to the accelerometer, and for the self-test pin. You'll use the other three analog inputs to read the accelerometer's analog outputs.



Here are the pin connections for the configuration shown above:


Breakout Board PinSelf-TestZ-AxisY-AxisX-AxisGroundVDD
Arduino Analog Input Pin012345
Or, if you're using just the accelerometer:
ADXL3xxPinSelf-TestZOutYOutXOutGroundVDD
Arduino PinNone(unconnected)Analog Input 1Analog Input 2Analog Input 3GND5V
Please, be aware that some accelerometers use 3.3V power supply and might be damaged by 5V. Check the supplier's documentation to find out which is the correct voltage.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.

Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 06.Sensors >> ADXL3xx

Click press the "upload" button (see the button with right arrow mark).

The accelerometer connections are defined as constants at the beginning of the sketch, using the two Analog pins 4 and 5 as source of power. This is accomplished using them as Digital I/O pins 18 and 19. If needed, A0 is D14, A1 is D15 and so on.
const int groundpin = 18; 
const int powerpin = 19;

Setting pin 19 (A5) as HIGH and pin 18 (A4) as LOW provides the 5V with few milliamps needed by the accelerometer to work.
pinMode(groundpin, OUTPUT); 
pinMode(powerpin, OUTPUT); 
digitalWrite(groundpin, LOW); 
digitalWrite(powerpin, HIGH);

This solution allows the breakout boards from Sparkfun to be connected directly to your Arduino board. Different boards may be connected to standard 5V - or 3.3V -and GND pins. In this latter case, the code may be amended commenting the lines above in the void setup() section.

Data

Here are some accelerometer readings collected by positioning the y-axis of anADXL322 2g accelerometer at various angles from ground. Values should be the same for the other axes, but will vary based on the sensitivity of the device. With the axis horizontal (i.e. parallel to ground or 0°), the accelerometer reading should be around 512, but values at other angles will be different for a different accelerometer (e.g. the ADXL302 5g one).

Angle-90-80-70-60-50-40-30-20-100
Acceleration662660654642628610589563537510
Angle0102030405060708090
Acceleration510485455433408390374363357355


Download:

Arduino IDE




Sources:https://www.arduino.cc/en/Tutorial/ADXL3xx
06.Sensors library

 

  • Copyright © Arduino Tutorial ™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.