FRIENDz

FAILURE IS THE SIGN OF SUCCESS!!

Detecting Rotation Using a Gyroscope

Arduino-Detecting Rotation Using a Gyroscope:
         Most low-cost gyroscopes use an analog voltage proportional to rotation rate, although some also  output using I2C. This recipe works with a gyro with an analog output proportional to rotation rate. Figure 6-16 shows an LISY300AL breakout board from SparkFun. Many low-cost gyros, such as the one used here, are 3.3V devices and must not be plugged into the 5V power pin.The Gyro OUT connection is the analog output and is connected to Arduino analog input 0. The PD connection enables the gyro to be switched into low power mode and is connected to analog pin 1 (in this sketch, it is used as a digital output pin). You can connect PD to any digital pin; the pin used here was chosen to keep the wiring neater. If you don’t need to switch the gyro into low-power mode, you can connect the PD line to Gnd.

Reading RFID Tags using Arduino

RFID Connected with Arduino
A tag consists of a start character followed by a 10-digit tag and is terminated by an end character. The sketch waits for a complete tag message to be available and displays the tag if it is valid. The tag is received as ASCII digits (see Recipe 4.4 for more on receiving ASCII digits). You may want to convert this into a number if you want to store or compare the values received. To do this, change the last few lines as follows:
if( Serial.read() == endByte) // check for the correct end character
{
tag[bytesread] = 0; // terminate the string
long tagValue = atol(tag); // convert the ASCII tag to a long integer

Measuring Temperature LM35

Arduino-Measuring Temperature using LM35:
The LM35 temperature sensor produces an analog voltage directly proportional to temperature with an output of 1 millivolt per 0.1°C (10 mV per degree). The sketch converts the analogRead values into millivolts and divides this by 10 to get degrees. The sensor accuracy is around 0.5°C, and in many cases you can use integer math instead of floating point. The following sketch turns on pin 2 when the temperature is above a threshold:
       This recipe displays the temperature in Fahrenheit and Celsius (Centigrade) using the popular LM35

Detecting Vibration

Arduino-Detecting Vibration

           A Piezo sensor, also known as a knock sensor, produces a voltage in response to physical stress. The more it is stressed, the higher the voltage. The Piezo is polarized and the positive side (usually a red wire or a wire marked with a “+”) is connected to the analog input; the negative wire (usually black or marked with a “-”) is connected to ground. A high-value resistor (1 megohm) is connected across the sensor.
The voltage is detected by Arduino analogRead to turn on an LED. The THRESHOLD value determines the level from the sensor that will turn on the LED, and you can decrease or increase this value to
make the sketch more or less sensitive. Piezo sensors can be bought in plastic cases or as bare metal disks

Measuring Distance

Arduino-Measuring Distance using PING:
             Ultrasonic sensors provide a measurement of the time it takes for sound to bounce off an object and return to the sensor. The “ping” sound pulse is generated when the pingPin level goes HIGH for two microseconds. The sensor will then generate a pulse that terminates when the sound returns. The width of the pulse is proportional to the distance the sound traveled and the sketch then uses the pulseIn function to measure that duration. The speed of sound is 340 meters per second, which is 29 microseconds per centimeter. The formula for the distance of the round trip is: RoundTrip = microseconds / 29.So, the formula for the one-way distance in centimeters is: microseconds / 29 / 2.

Detecting Motion using Arduino

Detecting Motion-Integrating Passive Infrared Detectors
             This code is similar to the pushbutton. That’s because the sensor acts like a switch when motion is detected. Different kinds of PIR sensors are available, and you should check the information for the one you have connected. Some sensors, such as the Parallax, have a jumper that determines how the output behaves when motion is detected. In one mode, the output remains HIGH while motion is detected, or it can be set so that the output goes HIGH briefly and then LOW when triggered. The example sketch in this recipe’s Solution will work in either mode. Other sensors may go LOW on detecting motion. If your sensor’s output

Detecting Light using Arduino

AVR Arduino-Detecting Light:
       The circuit for this recipe is the standard way to use any sensor that changes its resistance based on some physical phenomenon. The circuit in will change the voltage on analog pin 0 when the resistance of the LDR changes with varying light levels. A circuit such as this will not give the full range of possible values from the analog input—0 to 1,023—as the voltage will not be swinging from 0 volts to 5 volts. This is because there will always be a voltage drop across each resistance, so the voltage where they meet will never reach the limits of the power supply. When using sensors such as these, it is important to check the actual values

Detecting Movement using ARDUINO

AVR-Detecting Movement:
          The most common tilt sensor is a ball bearing in a box with contacts at one end. When the box is tilted the ball rolls away from the contacts and the connection is broken. When the box is tilted to roll the other way the ball touches the contacts and completes a circuit. Markings, or pin configurations, show which way the sensor should be oriented. Tilt sensors are sensitive to small movements of around 5 to 10 degrees when
oriented with the ball just touching the contacts. If you position the sensor so that the ball bearing is directly above (or below) the contacts, the LED state will only change if it is turned right over. This can be used to tell if something is upright or upside down. To determine if something is being shaken, you need to check

Reading More Than Six Analog Inputs

ARDUINO-Reading  Analog Inputs
               A standard Arduino board has six analog inputs (the Mega has 16) and there may not be enough
analog inputs available for your application. Perhaps you want to adjust eight parameters in your application by turning knobs on eight potentiometers.Use a multiplexer chip to select and connect multiple voltage sources to one analog input. By sequentially selecting from multiple sources, you can read each source in turn. This recipe uses the popular 4051 chip connected to Arduino. Your analog inputs get connected to the 4051 pins marked Ch 0 to Ch 7. Make sure the voltage on the channel input pins is never higher than 5 volts:

Reading a Keypad

ARDUINO-Reading a Keypad:
      Matrix keypads typically consist of Normally Open switches that connect a row with a column when pressed. Each of the four rows is connected to an input pin and each column is connected to an output pin. The setup function sets the pin modes and enables pull-up resistors on the input pins (see the pull-up recipes in the beginning of this chapter). The getkey function sequentially sets the pin for each column LOW and then checks to see if any of the row pins are LOW. Because pull-up resistors are used, the rows will be high (pulled up) unless a switch is closed (closing a switch produces a LOW signal on the input pin). If they are LOW, this indicates that the switch for that row and column is closed. A delay is used to ensure that the

Controlling LEDs using Switches

ARDUINO-Controlling LEDs using Switches:

You want to create and use a group of values (called arrays). The arrays may be a simple list or they could have two or more dimensions. You want to know how to determine the size of the array and how to access the elements in the array.This sketch creates two arrays: an array of integers for pins connected to switches and an array of pins connected to LEDs:

Servo Motor Rotation using AVR

Servo Motor Interfacing with AVR
Servos are positioning motors with a built-in feedback circuit, and it’s this internal circuitry that makes them so simple to use. As positioning motors, they don’t spin
around and around like traditional motors. Instead, they only rotate through 180
degrees or so, and they can move to the desired position to roughly the nearest
degree on command. This makes them ideal for pulling up the landing gear on a
model airplane, or for moving robot arms.

Timers PWM Demo

AVR Timers PWM :
             You might be wondering why we’re only lighting up three LEDs using the hardware PWM, and the sad reason is that the AVR’s dedicated PWM pins are limited to two per timer, for a total of six: four pins at an 8-bit PWM depth, and two at 16 bits. So the software lights up three LEDs in a row with the PWM values you’ve typed, shifting the new value in, the current values over, and the oldest value out.
As with the rest of the timer/counter-based code demos so far, the event loop is quite sparse. It gets a value from the serial port and then shifts the values up a chain, corresponding to the output compare registers of LED1, LED2, and LED3. Note how we don’t need to use any more variables to store the “previous” values

Brute Force PWM

Brute-Force PWM:
    This code is split up into two distinct parts. The function pwmAllPins() takes care of implementing PWM. The remaining code in the event loop increases and decreases a brightness variable. Calling pwmAllPins() with the increasing and decreasing brightness makes the LEDs pulse in and out. In pwmAllPins(), we have a loop over i, which takes exactly 256 steps each time. Inside the i loop, we compare a variable brightness to i and turn on the LEDs if i is smaller. This has the effect of turning on the LEDs at the beginning of each set
of 256 and then turning them off as soon as i reaches the value brightness, so for higher values of brightness the LEDs stay on for a greater percentage of the 256 steps.

AM Radio

AM Radio Using AVR

This code section really gets to show off what timers can do, and we even get to combine a timer with interrupts. Hold on tight! In the radio code, we’ll be using Timer 0 in CTC mode as we did earlier to generate audio in the improved organ code. That is, we have the counter count up to a value that determines its frequency, and then clear the counter and start over at zero.This code section really gets to show off what timers can do, and we even get to combine a timer with interrupts. Hold on tight! In the radio code, we’ll be using Timer 0 in CTC mode as we did earlier to generate audio in the improved organ code. That is, we have the counter count up to a value that determines its frequency, and then clear the counter and start over at zero.simply turn on and off the carrier signal to modulate it, generating the audio on top.

AVR Interfacing with Capacitive Sensor

Capacitive Sensor:

The basic principle behind capacitive touch sensors is the same: timing how long it takes for a capacitor to charge or discharge. When nobody is nearby, the sensor plate itself will have some roughly fixed capacitance of its own, and it will take a given amount of time to charge and discharge at a given voltage. When you come along, your body capacitance couples with the circuit. The resulting capacitor— made up of you and the sensor—has more capacitance than the sensor’s capacitor alone, and so takes longer to charge and discharge. Measuring the change in charge time, allowing for environmental variation and more, lets you determine when the “button” is pressed.