0% found this document useful (0 votes)
3 views

21ECO106J - LAB _Manual-Experiments 3

The document outlines experiments for sensor interfacing using Arduino, focusing on temperature monitoring, displacement measurement, and PWM-based servo motor control. It includes hardware and software requirements, theoretical background, code structure, and lab procedures for each experiment. Each section also contains pre-lab and post-lab questions to reinforce learning.

Uploaded by

kpnx8cpmmk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

21ECO106J - LAB _Manual-Experiments 3

The document outlines experiments for sensor interfacing using Arduino, focusing on temperature monitoring, displacement measurement, and PWM-based servo motor control. It includes hardware and software requirements, theoretical background, code structure, and lab procedures for each experiment. Each section also contains pre-lab and post-lab questions to reinforce learning.

Uploaded by

kpnx8cpmmk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Exp.

4: SENSOR INTERFACING FOR TEMPERATURE MONITORING

Aim: To indicate the temperature in “Red”, “Yellow”, “Green” LEDs and also send the
value to terminal in PC via serial port.

Components Requirement:

Hardware components: (i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:

The Temperature Sensor LM35 series are precision integrated-circuit temperature devices with an
output voltage linearly proportional to the Centigrade temperature.
The LM35 device has an advantage over linear temperature sensors calibrated in Kelvin, as the user is
not required to subtract a large constant voltage from the output to obtain convenient Centigrade
scaling. The LM35 device does not require any external calibration or trimming to provide typical
accuracies of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range. 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.

15
Code Structure:

void setup()
{
// put your setup code here, to run once:
}

void loop()
{
// put your main code here, to run repeatedly:
}

Pre-Lab Questions:

1. What is temperature sensor?


2. What are the 2 types of serial communication?
Procedure:

1. Connect the Arduino Uno Development Board to the Desktop/Laptop through


Type B USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
16
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Note:
 Red LED should glow when temperature is greater than 70 degree Celsius
 Yellow LED should glow when temperature is greater than 21 degree Celsius
and less than 70 degreeCelsius.
 Green LED should glow when temperature is Less than 20 degree Celsius

Post Lab:

1. Why temper sensor is connected to A0?


2. List few Arduino serial communications functions.

Output:

Paste your Screenshots here.

17
Code:

int sensorValue = 0;

int SerialValue = 0;

void setup()

pinMode(A0, INPUT);

pinMode(13, OUTPUT); //red

pinMode(12, OUTPUT); //green

pinMode(11, OUTPUT); //yellow

Serial.begin(9600);

void loop()

sensorValue = analogRead(A0);

SerialValue = (sensorValue-102)/2;

Serial.println(SerialValue);

if (SerialValue>70)

// ONLY RED GLOWS

digitalWrite(13,HIGH);

digitalWrite(12,LOW);

18
digitalWrite(11,LOW);

if (SerialValue>21 &&SerialValue<70)

// ONLY YELLOW GLOWS

digitalWrite(13,LOW);

digitalWrite(12,LOW);

digitalWrite(11,HIGH);

if(SerialValue<20)

// ONLY GREEN GLOWS

digitalWrite(13,LOW);

digitalWrite(12,HIGH);

digitalWrite(11,LOW);

delay(2); // Wait for 2 millisecond(s)

Result:

19
Exp5: Sensor Interfacing for Displacement Measurement

Aim: To indicate the distance range using three LEDs and use ultrasonic sensor to measure distance.

Components Requirement:

Hardware components : i) Desktop/ Laptop (Host)


(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable
Software Tools : Arduino IDE,
Tinker cad online Virtual Lab (For simulation)

Theory:

Ultrasonic sensor HC-SR04 is used here to measure distance in range of 2cm-400cm with accuracy of
3mm. The sensor module consists of ultrasonic transmitter, receiver and the control circuit. The work-
ing principle of ultrasonic sensor is as follows:

 High level signal is sent for 10us using Trigger.


 The module sends eight 40 KHz signals automatically, and then detects whether pulse is re-
ceived or not.
 If the signal is received, then it is through high level. The time of high duration is the time gap
between sending and receiving the signal.
 Distance= (Time x Speed of Sound in Air (340 m/s))/2

20
Code Structure

void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Bare minimum code

 setup : It is called only when the Arduino is powered on or reset. It is used to initialize vari-
ables and pin modes
 loop : The loop functions runs continuously till the device is powered off. The main logic
of the code goes here. Similar to while (1) for micro-controller programming.

PinMode

 A pin on arduino can be set as input or output by using pinMode function.


 pinMode(9, OUTPUT); // sets pin 9 as output pin
 pinMode(9, INPUT); // sets pin as input pin

Prelab Questions:
1. What are ultrasonic sensors?
2. What environmental conditions affect an ultrasonic sensor?

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB ca-
ble.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

PostLab Questions:

1. Write a note on the Arduino function used to detect the length of a pulse.
2. What is a dead zone in ultrasonic ranging?

21
Output:

Paste your Screenshots here.

Code.
long cm = 0;

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

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}

void loop()
{
cm =readUltrasonicDistance(7, 6);

Serial.print(cm);
Serial.println("cm");

if (cm > 250) {


22
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= 250 && cm > 175) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (cm <= 175 && cm > 100) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
if (cm <= 100) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}

delay(100); // Wait for 100 millisecond(s)


}

long readUltrasonicDistance(int triggerPin, int echoPin)


{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds *0.01723
return (pulseIn(echoPin, HIGH)*0.01723);

RESULT:

23
Exp. 6: PWM BASED SERVO MOTOR INTERFACING

Aim: To interface a Servo Motor using PWM Signals.

Components Requirement:
Hardware components: (i) Desktop/ Laptop (Host)
(ii) Arduino Uno Development Board (Target)
(iii) Type B USB Cable

Software Tools: Arduino IDE, Tinkercad online Virtual Lab (For simulation)

Theory:
A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear
position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position
feedback. It also requires a relatively sophisticated controller, often a dedicated module designed spe-
cifically for use with servomotors.
Servomotors are not a specific class of motor, although the term servomotor is often used to refer to a
motor suitable for use in a closed-loop control system.
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital
control is used to create a square wave, a signal switched between on and off. This on-off pattern can
simulate voltages in between the full Vcc of the board (e.g., 5 V on Uno, 3.3 V on a MKR board) and
off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal
spends off.

24
Code Structure
void setup() { // put your setup code here, to run once:
}
void loop() { // put your main code here, to run repeatedly:
}

Pre lab Questions:


1. Write about the construction of the Servo Motor.
2. List the applications of Servo Motor.

Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B USB cable.
2. Make the circuit connection accordingly.
3. Write the code and compile it in Arduino IDE.
4. Select USB port in Arduino IDE.
5. Select Arduino Uno Development Board in Arduino IDE.
6. Download the code into Arduino Uno Development Board
7. Run the code in Arduino Uno Development Board.
8. Observe and verify the output.

Post lab Questions:


1. List the advantages and disadvantages of Servo Motor.

2. How PWM is used to control the Servo Motor?

Output:

Paste your Screenshots here.

25
CODE:

#include <Servo.h>
int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9);
}
void loop()
{
for (pos = 0; pos<= 180; pos += 1) {
servo_9.write(pos);
delay(15);
}
for (pos = 180; pos>= 0; pos -= 1) {
servo_9.write(pos);
delay(15);
}
}

26
CODE:
int sensorValue = 0;
int outputValue = 0;
void setup() {
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(A0);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(9, outputValue);
Serial.print("sensor =");
Serial.print(sensorValue);
Serial.print("\toutput =");
Serial.println(outputValue);
delay(2);
}

RESULT:

27

You might also like