0% found this document useful (0 votes)
16 views37 pages

Fssi Abhinay

Uploaded by

ayeitsyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views37 pages

Fssi Abhinay

Uploaded by

ayeitsyash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Marwadi University

Faculty of Engineering & Technology


Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 1: Adding more LEDs and generate pattern.

Circuit in Tinkercad:

Code:

void setup ( )
{
pinMode (13, OUTPUT) ;
pinMode (13, OUTPUT) ;
pinMode (13, OUTPUT) ;
}
void loop ( )
{
digitalWrite (13, HIGH) ;
delay (1000) ;
digitalWrite (13, LOW) ;
delay (1000) ;
digitalWrite (12, HIGH) ;
delay (1000) ;
digitalWrite (12, LOW) ;
delay (1000) ;
digitalWrite (11, HIGH) ;
delay (1000) ;
digitalWrite (11, LOW) ;
delay (1000) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 2: Adding two Seven segment module.

Circuit in Tinkercad:

Code:

int disp_pin[7]; /* array for a-g pins of 7-Segment display */

void define_segment_pins(int a, int b, int c, int d, int e, int f, int g) /* Assigns 7-segment display pins to board
*/
{
disp_pin[0] = a;
disp_pin[1] = b;
disp_pin[2] = c;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

disp_pin[3] = d;
disp_pin[4] = e;
disp_pin[5] = f;
disp_pin[6] = g;
}

void display_number(int num) /* Function for displaying number (0-9) */


{
switch(num)
{
case 0:
digitalWrite(disp_pin[0], LOW); /* Drive disp_pin[0] to LOW */
digitalWrite(disp_pin[1], LOW); /* Driving LOW turns on LED segment for common anode display */
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], LOW);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], HIGH);
break;
case 1:
digitalWrite(disp_pin[0], HIGH); /* Drive disp_pin[7] to HIGH */
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], HIGH); /* Driving HIGH turns off LED segment for common anode display */
digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], HIGH);
digitalWrite(disp_pin[6], HIGH);
break;
case 2:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], HIGH);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], LOW);
digitalWrite(disp_pin[5], HIGH);
digitalWrite(disp_pin[6], LOW);
break;
case 3:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], HIGH);
digitalWrite(disp_pin[6], LOW);
break;
case 4:
digitalWrite(disp_pin[0], HIGH);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], HIGH);
digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], LOW);
break;
case 5:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], HIGH);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], LOW);
break;
case 6:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], HIGH);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], LOW);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], LOW);
break;
case 7:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], HIGH);
digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], HIGH);
digitalWrite(disp_pin[6], HIGH);
break;
case 8:
digitalWrite(disp_pin[0], LOW);
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], LOW);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], LOW);
break;
case 9:
digitalWrite(disp_pin[0], LOW);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], HIGH);
digitalWrite(disp_pin[5], LOW);
digitalWrite(disp_pin[6], LOW);
break;
default:
digitalWrite(disp_pin[0], HIGH);
digitalWrite(disp_pin[1], LOW);
digitalWrite(disp_pin[2], LOW);
digitalWrite(disp_pin[3], LOW);
digitalWrite(disp_pin[4], LOW);
digitalWrite(disp_pin[5], HIGH);
digitalWrite(disp_pin[6], LOW);
break;
}
}

void setup ( ) {
pinMode (6, OUTPUT) ;
pinMode (7, OUTPUT) ;
pinMode (8, OUTPUT) ;
pinMode (9, OUTPUT) ;
pinMode (10, OUTPUT) ;
pinMode (11, OUTPUT) ;
pinMode (12, OUTPUT) ;
define_segment_pins (12, 11, 10, 9, 8, 7, 6) ;
}

void loop() {
int I ;
for(i = 9; i>=0; i--)
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

{
display_number (i) ;
delay (1000) ;
}
for(i = 0; i<=9; i++)
{
display_number (i) ;
delay(1000) ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 3: To display custom characters on the LCD.

Circuit in Tinkercad:

Code:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2 ;
LiquidCrystal lcd (rs, en, d4, d5, d6, d7) ;
byte Heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
};

byte Sound[8] = {
0b00001,
0b00011,
0b00101,
0b01001,
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

0b01011,
0b11011,
0b11000,
};

void setup ( )
{
lcd.begin (16, 2) ;
lcd.createChar (0, Heart) ;
lcd.createChar (1, Sound) ;

lcd.setCursor (2, 0);


lcd.print (“I LOVE INDIA”) ;
}
void loop ( )
{
lcd.setCursor (0, 0) ;
lcd.write (byte (0)) ;

lcd.setCursor (15, 0) ;
lcd.write (byte (0)) ;

lcd.setCursor (0, 1) ;
lcd.write (byte (0)) ;

lcd.setCursor (15, 1) ;
lcd.write (byte (0)) ;
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 4: To display Temperature data on the LCD.

Circuit in Tinkercad:

Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd (12, 11, 5, 4, 3, 2) ;
int celsius ;
void setup ( )
{
Serial.begin (9600) ;
lcd.begin (16, 2) ;

lcd.print (“Temp Display: ”) ;


Serial.println (“Temp Display: ”) ;
}
void loop ( )
{
Celsius = map (((analogRead (A0) – 20) * 3.04), 0, 1023, -40, 125) ;

lcd.setCursor (0, 0) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

lcd.print (“Temp Display”) ;

lcd.setCursor (0, 1) ;
lcd.print (celsius) ;

lcd.print (“C”) ;
Serial.println (Celsius) ;
delay (1000) ;
lcd clear ( ) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 5: Displaying Readings (Temperature and Humidity) on LCD.

Circuit in Tinkercad:

Code:
#include <dht.h>
#include <LiquidCrystal.h>
const int rs =12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2 ;
LiquidCrystal lcd (rs, en, d4, d5, d6, d7) ;
#define outPin 8
dht DHT ;
void setup ( )
{
Serial.begin (9600) ;
lcd.begin (16, 2) ;
}
void loop ( )
{
int readData = DHT.read22 (outPin) ;
float t = DHT.temperature ;
float h = DHT.humidity ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

Serial.print (“Temperature = ”) ;
Serial.print (t) ;
Serial.print (“degree C = ”) ;
Serial.print ((t * 9.0 / 5.0+32.0)) ;
Serial.println (“degree F = ”) ;
Serial.print (“Humidity = ”) ;
Serial.print (h) ;
Serial.println (“ % ”) ;
Serial.println (“ ”) ;

lcd.setCursor (0, 0) ;
lcd.print (String (“Temp = ”) + String (t)) ;
lcd.setCursor (0, 1) ;
lcd.print (String (“Humidity = “) + String (h)) ;

delay (2000) ;

}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 6: To design and implement a PIR sensor-based system that automatically
controls lights based on the presence or absence of motion, enhancing energy efficiency and convenience in a
home environment.

Circuit in Tinkercad:

Code:

int ledPin = 13 ;
int inputPin = 8 ;
int pirState = LOW ;
int val = 0 ;
void setup ( )
{
pinMode (ledPin, OUTPUT) ;
pinMode (inputPin, INPUT);
Serial.begin (9600) ;
}
void loop ( )
{
val = digitalRead (inputPin) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

if (val == HIGH)
{
digitalWrite (ledPin, HIGH) ;
if (pitState == LOW)
{
pirState = HIGH ;
}
}
else
{
digitalWrite (ledPin, LOW) ;
if (pirState == HIGH)
{
pirState = LOW ;
}
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 7: To display distance on LCD display.

Circuit in Tinkercad:

Code:
#include <LiquidCrystal.h>
#define max_distance 200

LiquidCrystal lcd (12, 11, 5, 4, 3, 2) ;


const int trigPin = 9 ;
const int echoPin = 10 ;
long duration ;
int distance ;
void setup( )
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

{
lcd.begin (16,2);
pinMode (trigPin, OUTPUT) ;
pinMode (echoPin, INPUT) ;
}
void loop ( )
{
digitalWrite (trigPin, LOW) ;
delayMicroseconds (2) ;
digitalWrite (trigPin, HIGH) ;
delayMicroseconds (10) ;
digitalWrite (trigPin, LOW) ;

duration = pulseIn (echoPin, HIGH) ;

distance = duration*0.034/2 ;

lcd.setCursor (0,0) ;
lcd.print ("Distance: ") ;
lcd.print (distance) ;
lcd.print (" cm") ;
delay (500) ;
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 8: To design Item Counter using IR sensor.

Circuit in Tinkercad:

Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd (5,6,7,8,9,10) ;
int irPin=2 ;
int count=0 ;
boolean state = true ;
void setup( )
{
Serial.begin(9600) ;
lcd.begin(16,2) ;
pinMode(irPin, INPUT) ;
lcd.setCursor(0,0) ;
lcd.print("Count No : ") ;
}
void loop( )
{
if (digitalRead(irPin) && state) {
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

count++ ;
state = false ;
Serial.print("0Count: ") ;
Serial.println(count) ;
lcd.setCursor(12,0) ;
lcd.print(count) ;
delay(100) ;
}
if (digitalRead(irPin))
{
state = true ;
delay(100) ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 9: Automatic Street Light Controller Using LDR Sensor.

Circuit in Tinkercad:

Code:
const int ledPin = 5 ;
const int ldrPin = A0 ;
void setup ( ) {
Serial.begin (9600) ;
pinMode (ledPin, OUTPUT) ;
pinMode (ldrPin, INPUT) ;
}
void loop ( )
{
int ldrStatus = analogRead(ldrPin) ;
if (ldrStatus <= 200) {
digitalWrite (ledPin, HIGH) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

Serial.print ("Darkness over here, turn on the LED : ") ;


Serial.println (ldrStatus) ;
}
else
{
digitalWrite (ledPin, LOW) ;
Serial.print ("There is sufficeint light, turn off the LED : ") ;
Serial.println (ldrStatus) ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 10: Add to the LED indication system to improve its effectiveness for gas
detection in safety-critical applications.

Circuit in Tinkercad:

Code:
int LED = A1 ;
const int gas = 0 ;
int MQ2pin = A0 ;

void setup ( ) {
Serial.begin (9600) ;
}
void loop ( )
{
float sensorValue, MQ2pin ;
sensorValue = analogRead(MQ2pin) ;

if (sensorValue >= 470)


{
digitalWrite (LED, HIGH) ;
Serial.print (sensorValue) ;
Serial.println ("SMOKE DETECTED") ;
}
else
{
digitalWrite (LED, LOW) ;
Serial.println ("Sensor Value: ") ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

Serial.println (sensorValue) ;
}
delay (1000) ;
}
float getsensorValue (int pin)
{
return (analogRead (pin)) ;
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 11: Measuring Soil Moisture using Digital Output (D0).

Circuit in Tinkercad:

Code:

#define sensorPower 7
#define sensorPin 6

void setup ( )
{
pinMode (sensorPower, OUTPUT) ;
digitalWrite (sensorPower, LOW) ;
Serial.begin (9600) ;
}
int readSensor ()
{
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

digitalWrite (sensorPower, HIGH) ;


delay(10) ;
int val = digitalRead (sensorPin) ;
digitalWrite (sensorPower, LOW) ;
return val ;
}

void loop ( )
{
int val = readSensor () ;
Serial.print ("Digital Output: ") ;
Serial.println (val) ;

if (val == 0)
{
Serial.println ("Status: Soil is too dry - time to water!") ;
}
else
{
Serial.println ("Status: Soil moisture is perfect") ;
}
delay (1000) ;
Serial.println () ;
}

POST LAB EXERCISE 12: . I2C Controlled 7 Segment LED Display.


Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

Circuit in Tinkercad:

Code:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>
Adafruit_7segment matrix = Adafruit_7segment() ;
void setup ( )
{
matrix.begin(0x70) ;
}
void loop ( )
{
for (int numb = 0; numb <= 9999; numb++)
{
matrix.print (numb) ;
matrix.writeDisplay () ;
delay(200) ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 13: To control a DC motor's movement in left, right, forward, and
backward directions using Arduino.

Circuit in Tinkercad:

Code:

// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3 ;
int in3 = 5 ;
int in4 = 4 ;
void setup ( )
{
pinMode (enA, OUTPUT) ; // Set all the motor control pins to outputs
pinMode (enB, OUTPUT) ;
pinMode (in1, OUTPUT) ;
pinMode (in2, OUTPUT) ;
pinMode (in3, OUTPUT) ;
pinMode (in4, OUTPUT) ;
digitalWrite (in1, LOW) ; // Turn off motors - Initial state
digitalWrite (in2, LOW) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, LOW) ;
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

void loop ( )
{
directionControl () ; //Function is used to control the motor spin directions
//Only direction control function used for PostLab
delay(1000) ;
}
void directionControl ()
{
analogWrite (enA, 255) ;// Set motors to run at maximum speed (PWM range = 0 to 255 Max)
analogWrite (enB, 255) ;
//FORWARD
digitalWrite (in1, HIGH) ;
digitalWrite (in2, LOW) ;
digitalWrite (in3, HIGH) ;
digitalWrite (in4, LOW) ;
delay (2000) ;
//MOTORS OFF
digitalWrite (in1, LOW) ;
digitalWrite (in2, LOW) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, LOW) ;
delay(1000) ;
//BACKWARD
digitalWrite (in1, LOW) ;
digitalWrite (in2, HIGH) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, HIGH) ;
delay(2000) ;
//MOTORS OFF
digitalWrite (in1, LOW) ;
digitalWrite (in2, LOW) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, LOW) ;
delay(1000) ;
//RIGHT
digitalWrite (in1, HIGH) ;
digitalWrite (in2, LOW) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, HIGH) ;
delay(2000) ;
//MOTORS OFF
digitalWrite (in1, LOW) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

digitalWrite (in2, LOW) ;


digitalWrite (in3, LOW) ;
digitalWrite (in4, LOW) ;
delay(1000) ;
//LEFT
digitalWrite (in1, LOW) ;
digitalWrite (in2, HIGH) ;
digitalWrite (in3, HIGH) ;
digitalWrite (in4, LOW) ;
delay(2000) ;
//MOTORS OFF
digitalWrite (in1, LOW) ;
digitalWrite (in2, LOW) ;
digitalWrite (in3, LOW) ;
digitalWrite (in4, LOW) ;
delay(1000) ;
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 14: Interfacing a FSR with Arduino and controlling an LED as an indicator
based on pressure.

Circuit in Tinkercad:

Code:

int ledPin = 7 ;
int ledPin2 = 6 ;
int ledPin3 = 5 ;
int fsrPin = A0 ;
int fsrReading ;
void setup ( )
{
Serial.begin (9600) ;
pinMode (fsrPin, INPUT) ;
pinMode (ledPin, OUTPUT) ;
pinMode (ledPin2, OUTPUT) ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

pinMode (ledPin3, OUTPUT) ;


}
void loop ( )
{
fsrReading = analogRead (fsrPin) ;
Serial.print ("Analog reading = ") ;
Serial.println (fsrReading) ; //prints the raw analog reading
delay (1000) ;
if (fsrReading > 300 && fsrReading < 500)
{
digitalWrite (ledPin, LOW) ;
digitalWrite (ledPin2, LOW) ;
digitalWrite (ledPin3, HIGH) ;
Serial.println ("Low Pressure Applied\n") ;
}
if (fsrReading > 500 && fsrReading < 850)
{
digitalWrite (ledPin,LOW) ;
digitalWrite (ledPin3,LOW) ;
digitalWrite (ledPin2,HIGH) ;
Serial.println ("Medium Pressure Applied\n") ;
}
if (fsrReading > 850)
{
digitalWrite (ledPin2, LOW) ;
digitalWrite (ledPin3, LOW) ;
digitalWrite (ledPin, HIGH) ;
Serial.println ("High Pressure Applied\n") ;
}
if (fsrReading < 300)
{
digitalWrite (ledPin, LOW) ;
digitalWrite (ledPin2, LOW) ;
digitalWrite (ledPin3,LOW) ;
Serial.println ("No Pressure\n") ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 15: Interfacing a FSR with Arduino and controlling an LED as an indicator
based on pressure.

Circuit in Tinkercad:

Code:

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x20,16,2) ;
const byte ROWS = 4 ; //four rows
const byte COLS = 4 ; //four columns
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6} ; //connect to the row pinouts of the keypad
byte colPins [COLS] = {5, 4, 3, 2} ; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad ( makeKeymap(keys), rowPins, colPins, ROWS, COLS ) ;
void setup ( )
{
Serial.begin (9600) ;
lcd.init () ;
// turn on the backlight
lcd.backlight () ;
lcd.display () ;
}
void loop( )
{
char key = keypad.getKey () ;// Read the key
// Print if key pressed
if (key)
{
Serial.print ("Key Pressed: ") ;
Serial.println (key) ;
lcd.setCursor (0,0) ;
lcd.print(key) ;
}
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 16: To perform using the SPI communication protocol, where the Arduino
Mega is configured as the master device and the Arduino UNO as the slave. Data is transferred between the two
devices, demonstrating effective communication through SPI.

Circuit in Tinkercad:

Code:

#include <LiquidCrystal.h>
#define MISO 12
#define MOSI 11
#define PIN_CLOCK 13
#define CHIP_SELECT 10
int receivedTemperature ;
bool newDataReceived = false ;
void setup_pins ( )
{
DDRB &= ~((1 << 2) | (1 << 3) | (1 << 5)) ; // MOSI, PIN_CLOCK, CHIP_SELECT as
input DDRB |= (1 << 4) ; // MISO as output
DDRD = (0 << 2) | (0 << 3); //DDRC=0x00 ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

// DDRC = (0 << 2) | (0 << 3) | (0 << 4) | (0 << 5) ;


}
bool readPin (int pin)
{
return PINB & (1 << (pin - 8)) ;
}
byte receive_byte ()
{
byte receivedByte = 0 ;
for (int i = 0; i < 8; i++)
{
while (!readPin(PIN_CLOCK)) ; // Wait for clock to go high
receivedByte |= readPin(MOSI) << (7 - i) ;
while (readPin(PIN_CLOCK)) ; // Wait for clock to go low
}
return receivedByte ;
}
void receive_data ()
{
byte highByte, lowByte ;
if (!readPin (CHIP_SELECT))
{
highByte = receive_byte () ;
lowByte = receive_byte () ;
receivedTemperature = (highByte << 8) | lowByte;
newDataReceived = true ;
}
}
void setup ( )
{ Serial.begin(9600) ;
setup_pins ( ) ;
}
void loop ( )
{
receive_data ( ) ;
if (newDataReceived)
{
Serial.print ("Received current temp: ") ;
Serial.print (receivedTemperature) ;
Serial.print (char(176)) ;
Serial.println ("C") ;
newDataReceived = false ;
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

POST LAB EXERCISE 19: Add control for multiple LEDs connected to different GPIO pins and
control them through the Blynk app.

Code:

#define BLYNK_TEMPLATE_ID "TMPL3Z2dYCHmw1"


#define BLYNK_TEMPLATE_NAME "WiFi LED Control"
#define BLYNK_AUTH_TOKEN "smCn3jsq7VcCGORuW4ZqOMf6-IzugBJ1"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "smCn3jsq7VcCGORuW4ZqOMf6-IzugBJ1" ;
char ssid[] = "ram" ;
char pass[] = "11111111" ;
void setup ( )
{
Blynk.begin (auth, ssid, pass);
pinMode (D1, OUTPUT) ; // Set GPIO pin as output
pinMode (D3, OUTPUT) ;
pinMode (D5, OUTPUT) ; // Set GPIO pin as output
}
BLYNK_WRITE (V0) // This function runs when the button on Blynk app is pressed
{
int pinValue = param.asInt () ; // Get the value from the button
digitalWrite (D1, pinValue) ; // Control the LED
}
BLYNK_WRITE(V1) // This function runs when the button on Blynk app is pressed
{
int pinValue2 = param.asInt () ; // Get the value from the button
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

digitalWrite (D3, pinValue2) ; // Control the LED


}
BLYNK_WRITE (V2) // This function runs when the button on Blynk app is pressed
{
int pinValue3 = param.asInt () ; // Get the value from the button
digitalWrite (D5, pinValue3) ; // Control the LED
}
void loop ()
{
Blynk.run () ; // Keeps the Blynk connection alive
}
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Post Lab Exercise
sensor interfacing (01CT1103)
Name: Abhinay Reddy Date: Enrollment No: 92400133128

You might also like