21ECO106J - LAB _Manual-Experiments 3
21ECO106J - LAB _Manual-Experiments 3
Aim: To indicate the temperature in “Red”, “Yellow”, “Green” LEDs and also send the
value to terminal in PC via serial port.
Components Requirement:
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:
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:
Output:
17
Code:
int sensorValue = 0;
int SerialValue = 0;
void setup()
pinMode(A0, INPUT);
Serial.begin(9600);
void loop()
sensorValue = analogRead(A0);
SerialValue = (sensorValue-102)/2;
Serial.println(SerialValue);
if (SerialValue>70)
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
18
digitalWrite(11,LOW);
if (SerialValue>21 &&SerialValue<70)
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
if(SerialValue<20)
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
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:
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:
20
Code Structure
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
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
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:
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");
RESULT:
23
Exp. 6: PWM BASED SERVO MOTOR INTERFACING
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:
}
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.
Output:
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