AMITY UNIVERSITY CHHATTISGARH - 492014
LABORATORY RECORD NOTEBOOK
Submitted in partial fulfillment of requirement of
Bachelor of Science in Information Technology
(B.Sc. IT)
Arduino Interface Lab Manual
B.Sc. IT (Semester -
6)
Batch 20201– 2024
Akshat Pandey
AMITY UNIVERSITY CHHATTISGARH
(Batch 2021-2024)
Enrollment Number: A80904921017
This is to certify that this is a bonafide record of the work
done by Mr. Akshat Pandey Enrollment Number
A80904921017 of the year 2021-2024 B.SC IT
Department of AIIT in the Introduction to Arduino
Interface Laboratory in the 6th semester.
University Examination held on Amity University Chhattisgarh
University Exam Held on
Faculty In-Charge Director (ASET)
1. Arduino Solar Tracker.
//Servo motor library
#include <Servo.h>
//Initialize variables
int mode = 0;
int axe = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int prevButtonState1 = 0;
int prevButtonState2 = 0;
int ldrtopr= 0; // top-right LDR
int ldrtopl = 1; // top-left LDR
int ldrbotr = 2; // bottom-right LDR
int ldrbotl = 3; // bottom-left LDR
int topl = 0;
int topr = 0;
int botl = 0;
int botr = 0;
//Declare two servos
Servo servo_updown;
Servo servo_rightleft;
int threshold_value=10; //measurement sensitivity
void setup()
{
Serial.begin(9600); //serial connection setup //opens serial port, sets data rate
to 9600 bps
Serial.println("CLEARDATA"); //clear all data that’s been place in already
Serial.println("LABEL,t,voltage,current,power,Mode"); //define the column headings (PLX-DAQ
command)
pinMode(12, INPUT); //Mode switch Button
pinMode(11, INPUT); //Axis switch
pinMode(A4, INPUT); //Potentiometer for right-left movement and for up-down
movement
servo_updown.attach(5); //Servo motor up-down movement
servo_rightleft.attach(6); //Servo motor right-left movement
}
void loop()
{
// pv_power();
char Mode;
float volt = analogRead(A5)*5.0/1023;
float voltage = 2*volt; // Volt=(R1/R1+R2)*Voltage / R1=R2=10Ohms =>
voltage=2*volt)
float current = voltage/20; // I=voltage/(R1+R2)
float power = voltage*current;
Serial.print("DATA,TIME,"); // PLX-DAQ command
Serial.print(voltage); //send the voltage to serial port
Serial.print(",");
Serial.print(current); //send the current to serial port
Serial.print(",");
Serial.print(power); //send the power to serial port
Serial.print(",");
// Serial.println(Mode);
buttonState1 = digitalRead(12);
if (buttonState1 != prevButtonState1) {
if (buttonState1 == HIGH) {
//Change mode and ligh up the correct indicator
if (mode == 1) {
mode = 0;
} else {
mode = 1;
}
}
}
prevButtonState1 = buttonState1;
delay(50); // Wait for 50 millisecond(s)
if (mode == 0) {
Mode='M';
Serial.println(Mode); //send Mode "Manual" to serial port
manualsolartracker();
} else { // mode automatic
Mode = 'A';
Serial.println(Mode);
automaticsolartracker(); //send Mode "Automatic" to serial port
}
}
void automaticsolartracker(){
//capturing analog values of each LDR
topr= analogRead(ldrtopr); //capturing analog value of top right LDR
topl= analogRead(ldrtopl); //capturing analog value of top left LDR
botr= analogRead(ldrbotr); //capturing analog value of bot right LDR
botl= analogRead(ldrbotl); //capturing analog value of bot left LDR
// calculating average
int avgtop = (topr + topl) / 2; //average of top LDRs
int avgbot = (botr + botl) / 2; //average of bottom LDRs
int avgleft = (topl + botl) / 2; //average of left LDRs
int avgright = (topr + botr) / 2; //average of right LDRs
//Get the different
int diffelev = avgtop - avgbot; //Get the different average betwen LDRs top and LDRs bot
int diffazi = avgright - avgleft; //Get the different average betwen LDRs right and LDRs left
//left-right movement of solar tracker
if (abs(diffazi) >= threshold_value){ //Change position only if light difference is bigger then
the threshold_value
if (diffazi > 0) {
if (servo_rightleft.read() < 180) {
servo_rightleft.write((servo_updown.read() + 2));
}
}
if (diffazi < 0) {
if (servo_rightleft.read() > 0) {
servo_rightleft.write((servo_updown.read() - 2));
}
}
}
//up-down movement of solar tracker
if (abs(diffelev) >= threshold_value){ //Change position only if light difference is bigger then
thethreshold_value
if (diffelev > 0) {
if (servo_updown.read() < 180) {
servo_updown.write((servo_rightleft.read() - 2));
}
}
if (diffelev < 0) {
if (servo_updown.read() > 0) {
servo_updown.write((servo_rightleft.read() + 2));
}
}
}
}
void manualsolartracker(){
buttonState2 = digitalRead(13);
if (buttonState2 != prevButtonState2) {
if (buttonState2 == HIGH) {
//Change mode and ligh up the correct indicator
if (axe == 1) {
axe = 0;
} else {
axe = 1;
}
}
}
prevButtonState2 = buttonState2;
delay(50); // Wait for 50 millisecond(s)
if (axe == 0) { //control right-left movement
servo_rightleft.write(map(analogRead(A4), 0, 1023, 0, 180));
} else { // //control up-down movement
servo_updown.write(map(analogRead(A4), 0, 1023, 0, 180));
}
}
2. Arduino Gas Detecting Alarm System
Step 1: About Project and Schematic Drawing We have used a gas sensor module to detect gases. If a
gas leakage occurs, the sensor gives a HIGH pulse and when the Arduino gets a HIGH pulse from the
sensor, it sends a signal to the LCD and the piezo buzzer. Then the LCD would show the “Evacuate"
message and activates the piezo buzzer which beeps again and again until the gas detector doesn't
sense the gas in the environment. Else, the gas sensor gives LOW pulse to the Arduino, then LCD
would then show the “All Clear” message.
Step 2: Gather All the Supplies Step
3: Setup(Part 1)
Steps
1. Connect Arduino 5V to positive power rail
2. Connect Arduino GND to negative power rail
3. Connect Arduino A0 to gas sensor B1
4. Connect gas sensor A1, H2, A2 to positive power rail
5. Connect gas sensor H2 to ground
6. Connect gas sensor B2 to 4.7k ohms resistor, then to ground
7. Connect piezo positive terminal to Arduino pin 4
8. Connect piezo negative terminal to 1k ohms resistor, then to ground
9. Connect cathodes of the two LEDs to 1k ohms resistor, then to ground
10. Connect the anode of the red LED to Arduino pin 2 11. Connect the anode of the green LED to
Arduino pin
Step 4: Setup(Part 2)
1. Connect LCD ground, contrast, and LED cathode to ground 2. Connect LCD anode to 1k ohms
resistor, then to the positive power rail 3. Connect LCD power to the positive power rail 4. Connect
LCD register select to Arduino pin 5 5. Connect LCD read/write to ground 6. Connect LCD enable to
Arduino pin 6 7. Connect LCD terminal 4,5,6,7 to Arduino pin 8,9,10,11 Step
5 step - Code Arduino Code for Gas Detecting Alarm System.
6: Run the Simulation When you run the simulation, the LCD should be able to display both safe and
evaluate messages, while the piezo buzzer should be able to beep if the gas sensor detect any gas
leaks.
3. ULTRASONIC SENSOR
1. WAP to measure distance using ultrasonic sensor with circuit diagram
2. Interfacing GSM and GPS Module using Arduino.
GPS Module
GSM Module
Materials Needed:
• Arduino Uno
• GPS Module
• GSM Module • Connecting Wires
• USB - type connector connected to a computer with Arduino IDE
• Breadboard is optional
Step 1: Connecting GSM and GPS Module to the Arduino
GSM Module to Arduino
• TX connected to pin 11
• RX connected to pin 10
• 5V from the module to 5V of Arduino
• two Grounds from the module to the Ground to Arduino
GPS Module to Arduino
• Vcc connected to 5V of Arduino
• RX from the module to the TX of Arduino (pin 1)
• TX from the module to the RX of Arduino (pin 2)
• GND to GND
Step 2: Software Connection
• Connect the USB Cable to a PC or Laptop
Open Arduino IDE, change your board to Arduino Uno: Go to Tools > Board: > Arduino/Genuino Uno
Also change the Port settings: Go to Tools > Port: > COM6 (Arduino/ Genuino Uno).
Then, download the library TinyGPS++ this will be used for later purposes. After which,
extract the file and copy the folder then Go to your Program Files and find the Arduino
Folder > libraries then paste the folder of TinyGPS++.
Step 3: The Code:
4. Study the Temperature sensor and Write Program foe monitor temperature using
Arduino.
Connecting to a Temperature Sensor
These sensors have little chips in them and need to be handled properly. Be careful of static
electricity when handling them and make sure the power supply is connected up correctly and
is between 2.7 and 5.5V DC.
They come in a "TO-92" package which means the chip is housed in a plastic hemi-cylinder
with three legs. The legs can be bent easily to allow the sensor to be plugged into a breadboard.
You can also solder to the pins to connect long wires.
Reading the Analog Temperature Data
To read the temperature value from the sensor, and that is plugging the output pin directly
into an Analog (ADC) input. Remember that you can use anywhere between 2.7V and 5.5V
as the power supply. The analog voltage reading will range from about 0V (ground) to about
1.75V.
If you're using a 5V Arduino, and connecting the sensor directly into an Analog pin, you can
use these formulas to turn the 10-bit analog reading into a temperature:
Voltage at pin in milliVolts = (reading from ADC) * (5000/1024)
This formula converts the number 0-1023 from the ADC into 0-5000mV (= 5V)
If you're using a 3.3V Arduino, you'll want to use this:
Voltage at pin in milliVolts = (reading from ADC) * (3300/1024)
This formula converts the number 0-1023 from the ADC into 0-3300mV (= 3.3V)
Then, to convert millivolts into temperature, use this formula:
Centigrade temperature = [(analog voltage in mV) - 500] / 10
Code: