You are on page 1of 13

Internet of Things (IoT) EC4045 n Elective

MODULE II

Sensors & Interfacing


Explain the working of 3 axes Accelerometer.
How an Accelerometer Works
Accelerometers are electromechanical devices that sense either static or dynamic forces of acceleration. Static
forces include gravity, while dynamic forces can include vibrations and movement.

Axes of measurement for a triple axis accelerometer


Accelerometers can measure acceleration on one, two, or three axes. 3-axis
3 axis units are becoming more common as
the cost of development for them decreases.
Generally, accelerometers contain capacitive plates internally. Some of these are fixed, while others are attached
to minuscule springs that move internally as acceleration forces act upon the sensor. As these plates move in
relation to each other, the capacitance between them changes. From these changes in capacitance, the
acceleration can be determined.
Other accelerometers can be centered around piezoelectric materials. These tiny crystal structures output
electrical charge when placed under mechanical stress ( e.g. acceleration).

An example of the inside of a piezoelect


piezoelectric accelerometer
Internet of Things (IoT) EC4045 Open Elective-II

Design an IoT application using Arduino UNO and 3 axes accelerometer. Draw block
diagram, Arduino UNO connection diagram, Sample program

ADXL3xx Accelerometer
This tutorial shows you how to read from the ADXL3xx series
(e.g. ADXL320, ADXL321, ADXL322, ADXL330) accelerometer and receive the values in 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.

Hardware Required

 Arduino or Genuino Board


 ADXL3xx Accelerometer

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.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:
click the image to enlarge
Internet of Things (IoT) EC4045 Open Elective-II

Here are the pin connections for the configuration shown above:

Breakout Board Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD

Arduino Analog Input Pin 0 1 2 3 4 5

Or, if you're using just the accelerometer:

ADXL3xx Pin Self-Test ZOut YOut XOut Ground VDD

Analog Input Analog Input Analog Input


Arduino Pin None (unconnected) GND 5V
1 2 3

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.

Code
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);
Internet of Things (IoT) EC4045

This solution allows the breakout boards from Sparkfun to be connected directly to your Arduino or Genuino
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.

/*
ADXL3xx

Reads an Analog Devices ADXL3xx accelerometer and communicates the


acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from SparkFun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80

The circuit:
- analog 0: accelerometer self test
- analog 1: z-axis
- analog 2: y-axis
- analog 3: x-axis
- analog 4: ground
- analog 5: vcc

created 2 Jul 2008


by David A. Mellis
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/ADXL3xx
*/

// these constants describe the pins. They won't change:


const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)

void setup() {
// initialize the serial communications:
Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal digital pins.
// This makes it possible to directly connect the breakout board to the
// Arduino. If you use the normal 5V and GND pins on the Arduino,
// you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}

void loop() {
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Internet of Things (IoT) EC4045

Serial.println();
// delay before next reading:
delay(100);
}

What is a hygrometer? What are the parameters a hygrometer measures? Explain the working
of hygrometer with suitable diagram.

 Hygrometer measures humidity.

A hygrometer is weather instrument used to measure the amount of humidity in the


atmosphere. There are two main types of hygrometers -- a dry and wet bulb psychrometer and
a mechanical hygrometer.

What is Humidity?

Humidity is the amount of water vapor in the atmosphere caused by condensation and
evaporation. It can be measured as absolute humidity (the amount of water vapor in a unit
volume of air), or a relative humidity (the ratio of moisture in the atmosphere to the
maximum moisture the atmosphere can hold). It is what gives you that uncomfortable sticky
feeling on a hot day and can cause heat stroke. We feel most comfortable with relative
humidity between 30% and 60%.

How do Hygrometers Work?

Wet and dry bulb psychrometers are the most simple and common way of measuring
humidity. This type of hygrometer uses two basic mercury thermometers, one with a wet bulb
one with a dry bulb. Evaporation from the water on the wet bulb causes its temperature
reading to drop, causing it to show a lower temperature than the dry bulb.
Internet of Things (IoT) EC4045

Relative humidity is calculated by comparing the readings using a calculation tablethat


compares the ambient temperature (the temperature given by the dry bulb) to the difference in
temperatures between the two thermometers.

A mechanical hygrometer uses a slightly more complex system, based on one of the first
hygrometers designed in 1783 by Horace Bénédict de Saussure. This system uses an organic
material (usually human hair) that expands and contracts as a result of the surrounding
humidity (that also explains why you always seem to have a bad hair day when it’s hot and
humid!). The organic material is held under slight tension by a spring, which is linked to a
needle gauge that indicates the level of humidity based on how the hair has moved.

How Does Humidity Affect Us?

Humidity is important for our comfort and our health. Humidity has been linked to
sleepiness, lethargy, lack of observations, lower observation skills, and irritability. Humidity
also plays a factor in heat stroke and heat exhaustion.

As well as affecting people, too much or too little humidity can affect your possessions. Too
little humidity can dry out and damage furniture. In contrast, too much humidity can cause
moisture stains, condensation, swelling, and mold.

Getting the Best Results from a Hygrometer

Hygrometers must be calibrated at least once a year to ensure they provide the most accurate
results possible. Even the best, most expensive hygrometer’s accuracy is likely to alter over
time.

To calibrate, place your hygrometer in a sealed container alongside a cup of salt water, and
place it in a room where the temperature stays relatively constant throughout the day (e.g. not
by a fireplace or front door), then leave it to sit for 10 hours. At the end of the 10 hours, the
hygrometer should display a relative humidity level of 75% (the standard) -- if not, you need
to adjust the display.

What is DHT11 Sensor? Draw the pin diagram and connection to interface to an
Arduino UNO. Write how interfacing will be done and what data will be acquired.

 DHT11 is a Temperature and Humidity Sensor.

The DHT-11 is a digital-output relative humidity and temperature sensor. It uses a capacitive
humidity sensor and a thermistor to measure the surrounding air. Compared to the DHT22, this sensor
is less precise, less accurate and works in a smaller range of temperature and humidity, but its smaller
and less expensive.
Technical details:
 Power: 3-5V
 Current: 2.5mA
 Humidity: 20-95%, ±5% accuracy
 Temperature: 0 to 50°C, ±2°C accuracy

Components required:
Internet of Things (IoT) EC4045

 Arduino uno
 Breadboard
 DHT-11

Circuit:

Code:
/* How to use DHT-11 sensor with Arduino uno
Temperature and humidity sensor
Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com */

//Libraries
#include <DHT.h>

//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11 (AM2302)
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value

void setup()
{
Serial.begin(9600);
Internet of Things (IoT) EC4045

dht.begin();
}

void loop()
{
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
}

Output:

Describe the working of IR Sensor using suitable diagram of a IR TX-RX. What kind of
typical IoT applications can be designed using IR LED and IR detector? Give one such
design using block diagram.

An IR sensor is an electronic instrument used to sense certain characteristics of its


surroundings by either emitting and/or detecting Infrared radiation. Infrared sensors can also
measure heat emitted by an object and detect motion. Few of the key applications of the IR
sensor are:

 Night Vision Devices


 Line Follower Arrays
Internet of Things (IoT) EC4045

 Motion Detectors

One of the popular uses of the IR sensor in the DIY Electronics Community is for the line
follower robots and ping sensors. So, in this Instructable I'll show you how to make an IR
sensor which can detect objects and can be used in simple applications.
These are the things you need to make an IR object sensor:
 Arduino Uno
 IR transmitter
 IR Receiver
 Resistors 220 Ohm (2 nos)
 LED
 BreadBoard

Follow the schematic to make the circuit. Here, the voltage produced by the IR Receiver is
converted from analog to digital and is used as a reference to know whether the object is
detected or not. This pic can be called as the signal pin. An LED is used to indicate the
detection of the object

Connection/ Circuit:
Internet of Things (IoT) EC4045

Code:

onst int analogInPin = A0; // Analog input pin that the receiver is attached to
int sensorValue = 0; // value read from the receiver
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
//initialize the indicator LED:
pinMode(13, OUTPUT);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// print the results to the serial monitor:
Serial.print("\nsensor = ");
Serial.print(sensorValue);
//the threshold found fron analog In Out program was when object is detected, the sensor value is be
low 100
//set the threshold whihc you get
//the threshold varies for different sets of emitter-receiver pairs
if(sensorValue < 100){ //checks if object is there or not
digitalWrite(13, HIGH);
Serial.print("\nObject Detected");
}
else{
digitalWrite(13, LOW);
Serial.print("\nNo object in Front");
}
delay(500);
}
Internet of Things (IoT) EC4045

Explain the working of magnetic hall sensor. Where such sensors can be useful in IoT
application? Design such application using suitable block diagram.

This project uses a Hall effect sensor to detect the presence of a magnet. Whenever a magnet
moves past this sensor, it can detect it. This sensor can be used to do a lot of different things.
For instance, if we need to detect a door closing; then we simply have to attach a magnet to
the door and a hall sensor to the frame of the door. Whenever the door closes, the magnet is
placed near the hall effect sensor and we are able to detect that the door has been closed.

Similarly, this same principle can be used to make a speedometer for a bike or any other
vehicle. If a magnet is attached to the wheel and a Hall Effect sensor is placed somewhere in
the frame of the bike, the time taken for the wheel to complete one revolution can be
measured, and with a bit more math, we can detect the bike's movement speed!

How Does It Work?

The Hall effect sensor works on the principle of the Hall effect, which states that whenever a
magnetic field is applied in a direction perpendicular to the flow of electric current in a
conductor, a potential difference is induced. This voltage can be used to detect whether the
sensor is in the proximity of a magnet or not. The Arduino can detect this voltage change
through its interrupt pin and determine whether the magnet is near the sensor or not. The
basic working of the Arduino Hall effect sensor is shown in the picture below.

Arduino Hall effect sensor working


There are many types of Hall effect sensors, and certain types are better for certain
applications. For applications where the speed of detection is not crucial, ordinary Hall effect
sensors like 44E can be used. However, for applications that involve high-speed detection,
like in the case of speedometers, high-frequency Hall effect sensors like US5881 or US1881
should be used. There are two main types of Hall effect sensors: latching and non-latching.

The US1881 is a latching Hall effect sensor. The sensor gives out an output HIGH (5V)
voltage whenever the north pole of a magnet is brought close to it. Even when the magnet is
removed, the sensor still outputs a HIGH voltage and does not go LOW (0V) until the south
pole of the magnet is brought close to it. These sensors that latch on to a particular state are
called latched Hall effect sensors.
Internet of Things (IoT) EC4045

The US5881 is a non-latching Hall effect sensor. The sensor gives an output HIGH voltage
whenever the north pole of a magnet is brought close to it, and switches LOW whenever the
magnet is removed. I personally prefer non-latching Hall effect sensors like the US5881 for
my projects.

Hall effect sensors have three pins: VCC(5V), GND, and Vout(Signal). The pinout of a Hall
effect sensor is as shown below:

Arduino Hall effect sensor pinout

Making the Connections for the Arduino Hall Effect Sensor

Interfacing the Hall effect sensor with Arduino is really simple. The VCC of the sensor is
connected to Arduino's 5V power pin. The GND of the sensor is connected to the GND pin
on the Arduino. The Vout or signal pin of the Hall effect sensor is connected to the Arduino's
interrupt pin (digital pin 2). Furthermore, a 10K resistor is connected between the VCC and
Vout pins of the Hall effect sensor. This is done to pull the output of the Hall effect sensor to
5V. The connections are done as shown below (the side with the printed number is facing
toward you in the diagram):
Internet of Things (IoT) EC4045

Code:
/*
Arduino Hall Effect Sensor Project
by Arvind Sanjeev
Please check out http://diyhacking.com for the tutorial of this
project.
DIY Hacking
*/

volatile byte half_revolutions;


unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
attachInterrupt(0, magnet_detect, RISING);//Initialize the
intterrupt pin (Arduino digital pin 2)
half_revolutions = 0;
rpm = 0;
timeold = 0;
}
void loop()//Measure RPM
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
//Serial.println(rpm,DEC);
}
}
void magnet_detect()//This function is called whenever a
magnet/interrupt is detected by the arduino
{
half_revolutions++;
Serial.println("detect");
}

You might also like