Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 1
Date:
Measure Analog signal from Temperature Sensor

AIM: To Measure Analog signal from Temperature Sensor

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 Temperature sensor (LM35)
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 LM35 SENSOR:
LM35 is a temperature sensor which can measure temperature in the range of -55°C to 150°C. It is a
3-terminal device that provides analog voltage proportional to the temperature. Higher the
temperature, higher is the output voltage. The output analog voltage can be converted to digital form
using ADC so that a microcontroller can process it.

Measuring the temperature of surroundings using LM35 and displaying it on the serial monitor of Arduino.
Here, LM35 output is given to analog pin A0 of Arduino UNO. This analog voltage is converted to its digital
form and processed to get the temperature reading.

1
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

CIRCUIT CONFIGURATION:

PROCEDURE:

Hardware Procedure:

 LM35 is connected to Arduino Uno Analog pin A0.


 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

2
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Program:

void setup()

Serial.begin(9600);

Serial.println("Analog Read Test");

void loop()

int a = analogRead(A0);

Serial.print("Output of ADC = ");

Serial.println(a);

Serial.print("The voltage measured im millivolt = ");

int mv = a * 4.88;

Serial.print(mv);

Serial.println("mv");

delay(1000);

/* LM35 Temp Sensor*/

void setup()

Serial.begin(9600);

Serial.println("LM35 Temperature sensor test");

void loop()

int a = analogRead(A0);

Serial.print("Output of ADC = ");

Serial.println(a);

a = a * 4.88; // convert it to millivolts

int temp = a / 10;

3
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Serial.print("Temperature = ");

Serial.println(temp);

delay(1000);

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:
LM35 sense the surrounding temperature and that temperature shown by serial monitor using Arduino board.

Result:

Signature of the Faculty

4
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 2

Date:
Generate PWM output

AIM: To Generate PWM output

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 LED
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.
Arduino Uno has 6 8-bit PWM channels. The pins with symbol ‘~’ represents that it has PWM support.
These PWM pins are shown in below image.

 Pulse Width Modulation (PWM):


It is a technique by which width of a pulse is varied while keeping the frequency of the wave constant.
It is a method for generating an analog signal using a digital source.
A PWM signal consists of two main components that define its behavior: a duty cycle and a frequency.

a) Duty Cycle of a signal:


A period of a pulse consists of an ON cycle (5V) and an OFF cycle (0V). The fraction for
which the signal is ON over a period is known as a duty cycle.

5
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Pulse Width Modulated signals with different duty cycle are shown below

FIG:PWM Duty Cycle

b) Frequency of Signal:
The frequency of a signal determines how fast the PWM completes a cycle which means
how fast it switches between ON (high) and OFF (low) states. By repeating this ON-OFF
pattern at a fast-enough rate, and with a certain duty cycle, the output will appear to
behave like a constant voltage analog signal when providing power to devices.

6
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

CIRCUIT CONFIGURATION:

PROCEDURE:

Hardware Procedure:

 LED is connected to Arduino Uno pin 6.


 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

7
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Program:

int led = 6;

void setup() {

pinMode(led,OUTPUT); // put your setup code here, to run once:

analogWrite(6,50);

int i;

void loop() {

// put your main code here, to run repeatedly:

for(i = 0; i < 256;i++)

analogWrite(6,i);

delay(20);

delay(1000);

for(i = 255; i >= 0;i--)

analogWrite(6,i);

delay(20);

delay(1000);

8
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:
Generated PWM wave using Arduino board.

Result:

\
Signature of the Faculty

9
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 3
Date:
Drive Single Character Generation on Hyper Terminal

AIM: To Drive single character generation on Hyper Terminal

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 Hyper terminal
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 HYPER TERMINAL:
HyperTerminal is a communications and terminal emulation program that came with the Windows 98
and Windows XP operating systems.

CIRCUIT CONFIGURATION:

10
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

PROCEDURE:

Hardware Procedure:

 Power jack is connected to the Arduino.


 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

Program:
void setup() {

11
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Serial.begin(9600); // 9600 - baud rate

pinMode(2,OUTPUT);

void loop() {

if(Serial.available()){

char s = Serial.read();

Serial.println(s);

if(s=='2'){

digitalWrite(2,HIGH);

Serial.println("LED IS ON");

if(s=='1'){

digitalWrite(2,LOW);

Serial.println("LED IS OFF");

Precautions:

 Take care about given power supply.


 Jumper wires given carefully whenever given circuit connection.

Output:
Single character generation on Hyper Terminal /Tera term using Arduino board.

Result:

12
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Signature of the Faculty

13
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 4
Date:
Drive Given String on Hyper Terminal

AIM: To Drive given string on Hyper Terminal

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 Hyper terminal
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 HYPER TERMINAL:
HyperTerminal is a communications and terminal emulation program that came with the Windows 98
and Windows XP operating systems.

CIRCUIT CONFIGURATION:

14
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

PROCEDURE:
Hardware Procedure:

15
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

 Power jack is connected to the Arduino.


 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

Program:

void setup() {

Serial.begin(9600); // 9600 - baud rate

pinMode(2,OUTPUT);

void loop() {

if(Serial.available()){

char mystring = Serial.read();

Serial.println(mystring);

if(mystring=='2'){

digitalWrite(2,HIGH);

Serial.println("LED IS ON");

if(mystring=='1'){

digitalWrite(2,LOW);

Serial.println("LED IS OFF");

Precautions:

 Take care about given power supply .

16
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

 Jumper wires given carefully whenever given circuit connection.

Output:
String generation on Hyper Terminal using Arduino board.

Result:

Signature of the Faculty

17
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 5
Date:
Full duplex Link establishment using Hyper terminal

AIM: To establishment Full duplex Link using Hyper terminal

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board - 2


 Arduino Software IDE
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.
One Arduino board act as master and another Arduino board act as slave.

 HYPER TERMINAL:
HyperTerminal is a communications and terminal emulation program that came with the Windows 98
and Windows XP operating systems

 FULL DUPLEX LINK:


Full duplex is a bidirectional type of communication system where two end nodes send and receive
data signals at the same time, and a single carrier is simultaneously used for dual communication. Full
duplex is also known as double duplex.

CIRCUIT CONFIGURATION:

18
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

PROCEDURE:

Hardware Procedure:

 Transmitter pin of one Arduino board is connected to another Arduino Uno pin Receiver.
 Receiver pin of one Arduino board is connected to another Arduino Uno pin Transmitter.
 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:
 Click on Arduino IDE
 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

19
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Program:
Code for Master:

//Sender Arduino Board Code (Master)

char mystring[5] = "hi"; //String data which is to be sent

void setup() {

Serial.begin(9600); // Begin the Serial at 9600 Baud rate

void loop() {

Serial.write(mystring,5); //Write the serial data

delay(1000);

Code for Slave:


//Receiver Arduino Board Code

char mystring[5]; //Initialized variable to store receive

void setup() {

Serial.begin(9600); // Begin the Serial at 9600 Baud

void loop() {

Serial.readBytes(mystring,5); //Read the serial data

Serial.println(mystring); //Print data on Serial Monitor

Serial.println(" RECEIVER");

delay(1000);

20
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:
Full duplex link shown by hyper terminal using Arduino board.

Result:

Signature of the Faculty

21
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 6
Date:
Drive A Given Value on A 8 Bit DAC Consisting Of SPI

AIM: To Drive a given value on a 8 bit DAC consisting of SPI

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 DIGITAL TO ANALOG CONVERTER(DAC):


A DAC is a Digital-to-Analog Converter. A DAC [Digital-to-Analog Converter] is a device that
converts digital audio information (comprised of a series of 0s and 1s) into an analog audio signal that
can be sent to a headphone amp.

Digital to Analog Converter (DAC) is mostly used to generate analog signals (e.g. sine wave, triangular wave
etc.) from digital values. In Particle Photon there are total 2 On-Board DAC Pins available, ADC6 (DAC1 or
A6) and ADC3 (DAC2 or A3).

analogWrite(DAC_pin, Value)

This function is used to set the analog value between 0-3.3V which corresponds to digital values 0-4095
Circuit Diagram:

22
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

PROCEDURE:

Hardware Procedure:

 The DAC1 pin of one Arduino board is act as output.


 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

23
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Software Procedure:
 Click on Arduino IDE
 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

Program:

#include <SPI.h> //Include the Arduino SPI Library


#include <DAC_MCP49xx.h> //Include the MCP49xx Arduino Library
// The Arduino pin used for the slave select / chip select
#define SS_PIN 10
DAC_MCP49xx dac(DAC_MCP49xx::MCP4911, SS_PIN);
void setup()
{
Serial.begin(9600);
}
void loop()
{
double u; //Control Signal
int aiPin = 0;
int aiValue;
for (int i=0; i<1023; i++)
{
u = i;
dac.output(u);
aiValue = analogRead(aiPin);
Serial.print("AIValue=");
Serial.println(aiValue);
delay(1000);
}
}

(or)

int value;
void setup() {
pinMode(DAC1, OUTPUT); //use DAC1 pin as a output pin
}

void loop(){
value = 0;
while ( value != 4095 ) //increament value till noe equal to 4095
{
analogWrite(DAC1, value);
value++; //increament value by one

24
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

while ( value != 0 ) //decreament value till noe equal to 0


{
analogWrite(DAC1, value);
value--; //decreament value by one
}
}

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:

Connect the circuit (Arduino + MCP4911) on abreadboard. Use a multi-meter so see if you
get the correct output signal.
On the Multimeter you should see the output slowly increasing from ~0V to ~5V with
intervals of 1000ms.
You can also connect the output from the DAC to an Analog Input Pin on the Arduino. Write
the value to the Serial Monitor.

Result:

Signature of the Faculty

25
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 7
Date:
Drive Stepper motor using Analog GPIOs

AIM: To Drive Stepper motor using Analog GPIOs

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 Stepper motor
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 STEPPER MOTOR:
Stepper motor is a brushless DC motor that divides the full rotation angle of 360° into a number of
equal steps. The motor is rotated by applying a certain sequence of control signals. The speed of
rotation can be changed by changing the rate at which the control signals are applied.

Rotating stepper motor in clockwise and counter clockwise directions alternately. Here, we are using six wire
unipolar stepper motor. Only four wires are required to control this stepper motor. The two centre tap wires of
the stepper motor are connected to 5V supply.
ULN2003 driver is used to drive the stepper motor.

26
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

CIRCUIT CONFIGURATION:

PROCEDURE:

Hardware Procedure:

 Driver module pins of IN1,2,3,4 is connected to Arduino Uno digital pins of 7,6,5,4 respectively.
 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

Program:

void setup() {

pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}

void loop() {
/* Rotation in one direction */
for(int i = 0; i<12; i++)
{

27
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);

/* Rotation in opposite direction */


for(int j = 0; j<12; j++)
{
digitalWrite(7, LOW);

28
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(100);

digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(100);

digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);

digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(100);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(100);
}

29
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:
Control signals given to rotate the stepper motor using Arduino board.

Result:

Signature of the Faculty

30
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Expt. No: 8

Date:
Drive Accelerometer and Display the readings on Hyper Terminal

AIM: To Drive Accelerometer and Display the readings on Hyper Terminal

APPARATUS REQUIRED:

 Universal Board/Arduino Duemilanove Board


 Arduino Software IDE
 Accelerometer
 Hyper terminal
 12V Adaptor
 Power Jack
 USB Cable
 Jumper Wires

THEORY:

 ARDUINO BOARD:
Arduino platform offers open-source hardware and software that is easy to use and is used widely for
hobby projects and prototyping. Many libraries are provided with the software and a large number of
libraries developed by people from around the world are available for free. The functions implemented
in these libraries can be used for quick development purposes. This allows the user to use certain
interfaces or modules without having in depth knowledge about the internal structure or working.

 ACCELEROMETER:
An accelerometer is a device that measures the vibration, or acceleration of motion of a structure.
There are two types of accelerometers in general: AC-response and DC-response.
Accelerometer is an electromechanical device that measures the force of acceleration due to gravity in
g unit. It can be used in applications requiring tilt sensing.

The ADXL335 measures acceleration along X, Y and Z axes and gives analog voltage output proportional to the
acceleration along these 3 axes. Microcontrollers can process these voltages by converting them to digital
signals using ADC.

31
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

CIRCUIT CONFIGURATION:

PROCEDURE:

Hardware Procedure:

 The ADXL335 pins of VCC and GND is connected to Arduino Uno pins of 5V and GND respectively.
 The ADXL335 output pins of X, Y, Z is connected to Arduino Uno analog pins of A1, A2, A3
respectively.
 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

 Click on Arduino IDE


 Click on file
 Click on New
 Write a Program as per circuit Pin connections
 Click on Save
 Click on Verify
 Click on Upload the code into Arduino Uno by using USB cable

32
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Program:

#include <math.h>
const int x_out = A1; /* connect x_out of module to A1 of UNO board */
const int y_out = A2; /* connect y_out of module to A2 of UNO board */
const int z_out = A3; /* connect z_out of module to A3 of UNO board */

void setup()
{
Serial.begin(9600);
}

void loop()
{
int x_adc_value, y_adc_value, z_adc_value;
double x_g_value, y_g_value, z_g_value;
double roll, pitch, yaw;
x_adc_value = analogRead(x_out); /* Digital value of voltage on x_out pin */
y_adc_value = analogRead(y_out); /* Digital value of voltage on y_out pin */
z_adc_value = analogRead(z_out); /* Digital value of voltage on z_out pin */
Serial.print("x = ");
Serial.print(x_adc_value);
Serial.print("\t\t");
Serial.print("y = ");
Serial.print(y_adc_value);
Serial.print("\t\t");
Serial.print("z = ");
Serial.print(z_adc_value);
Serial.print("\t\t");
//delay(100);

x_g_value = ( ( ( (double)(x_adc_value * 5)/1024) - 1.65 ) / 0.330 ); /* Acceleration in x-direction in g units */


y_g_value = ( ( ( (double)(y_adc_value * 5)/1024) - 1.65 ) / 0.330 ); /* Acceleration in y-direction in g units */
z_g_value = ( ( ( (double)(z_adc_value * 5)/1024) - 1.80 ) / 0.330 ); /* Acceleration in z-direction in g units */

roll = ( ( (atan2(y_g_value,z_g_value) * 180) / 3.14 ) + 180 ); /* Formula for roll */


pitch = ( ( (atan2(z_g_value,x_g_value) * 180) / 3.14 ) + 180 ); /* Formula for pitch */
//yaw = ( ( (atan2(x_g_value,y_g_value) * 180) / 3.14 ) + 180 ); /* Formula for yaw */
/* Not possible to measure yaw using accelerometer. Gyroscope must be used if yaw is also required */

Serial.print("Roll = ");
Serial.print(roll);
Serial.print("\t");
Serial.print("Pitch = ");
Serial.print(pitch);
Serial.print("\n\n");
delay(1000);
}

33
ARM BASED/ AURDINO BASED PROGRAMMING (R20)

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.

Output:
Accelerometer sense the vibrations of structure and that vibration directions shown by serial monitor using
Arduino board.

Result:

Signature of the Faculty

34

You might also like