SlideShare a Scribd company logo
Library Requirements:
 Adafruit_BMP280_Library
 Adafruit-GFX-Library
 Adafruit_SSD1306
 MFRC522
 Adafruit_MPU6050.h
1. Soil moisture threshold check to actuate the relay
Code:
sensorValue = analogRead(sensorPin);
Set threshold to 400
If the sensor value is > the threshold
Trigger relay
To trigger relay
if (sensorValue > threshold limit) {
digitalWrite(A2, HIGH);
}
else {
digitalWrite(A2, LOW);
}
delay(1000);
}
Pin Connection
3V --> VCC
GND --> GND
A0 --> A0
2. Read Temperature & pressure using BMP sensor.
Note that, you can change the I2C address without modifying the library, just
type: bmp.begin(0x77);
Code:
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // I2C Interface
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
bmp.begin();
}
void loop() {
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure()/100); //displaying the Pressure
in hPa, you can change the unit
Serial.println(" hPa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1019.66));
//The "1019.66" is the pressure(hPa) at sea
level in day in your region
Serial.println(" m");
//If you don't know it, modify it until you
get your current altitude
Serial.println();
delay(2000);
}
3. Using RFID to display welcome message on Serial
OLED Display - Arduino
Vcc - 3.3V
GND - GND
SCL - Analog Pin 5
SDA - Analog Pin 4
Code:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
// Init array that will store new NUID
byte nuidPICC[4];
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
RFID Reader - Arduino
RST ▶ Digital Pin 9
IRQ ▶ Unconnected
MISO ▶ Digital Pin 12
MOSI ▶ Digital Pin 11
SCK ▶ Digital Pin 13
SDA ▶ Digital Pin 10
}
void loop() {
// Reset the loop if no new card present on the sensor/reader.
This saves the entire process when idle.
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));
if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
Serial.println(F("A new card has been detected."));
// Store NUID into nuidPICC array
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
Serial.println(F("The NUID tag is:"));
Serial.print(F("In hex: "));
printHex(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
Serial.print(F("In dec: "));
printDec(rfid.uid.uidByte, rfid.uid.size);
Serial.println();
}
else Serial.println(F("Card read previously."));
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void printHex(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* Helper routine to dump a byte array as dec values to Serial.
*/
void printDec(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], DEC);
}
}
4. Ultrasonic sensor to find the distance & height
int trigPin = 6; // HC-SR04 trigger pin
int echoPin = 7; // HC-SR04 echo pin
float duration, distance;
void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT); // define trigger pin as output
}
void loop()
{
digitalWrite(echoPin, LOW); // set the echo pin LOW
digitalWrite(trigPin, LOW); // set the trigger pin LOW
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // set the trigger pin HIGH for 10μs
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // measure the echo time (μs)
distance = (duration/2.0)*0.0343; // convert echo time to
distance (cm)
if(distance>400 || distance<2)
Serial.println("0");
else
{
Serial.print("90, ");
Serial.print(distance, 1);
Serial.println(" ,cm");
}
delay(1000);
}
5. Accelerometer to find out the vibrations and see the plottings
// Basic demo for accelerometer readings from Adafruit MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
mpu.begin();
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print(a.acceleration.z);
Serial.print(", ");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print(g.gyro.z);
Serial.println("");
delay(10);
}

More Related Content

DOCX
codings related to avr micro controller
PDF
ADC (Analog to Digital conversion) using LPC 1768
PPT
Cs423 raw sockets_bw
DOCX
DOCX
Codigo fuente
PPT
W8_2: Inside the UoS Educational Processor
PPTX
Controller Implementation in Verilog
DOC
22 microcontroller programs
codings related to avr micro controller
ADC (Analog to Digital conversion) using LPC 1768
Cs423 raw sockets_bw
Codigo fuente
W8_2: Inside the UoS Educational Processor
Controller Implementation in Verilog
22 microcontroller programs

What's hot (20)

PDF
iCloud keychain
PPT
Switch & LED using TMS320C6745 DSP
PDF
Connectivity for Local Sensors and Actuators Using nRF24L01+
PDF
selected input/output - sensors and actuators
PDF
ゆるふわコンピュータ (IPSJ-ONE2017)
PPT
Led blinking using TMS320C6745
PDF
Computron príručka
DOC
All VLSI programs
PPTX
Cisco IOS shellcode: All-in-one
PDF
Vectorization on x86: all you need to know
PPT
Classical cryptography
PPT
Classical cryptography1
PDF
Seven segment display
DOCX
PDF
深入淺出C語言
PDF
Dsd lab Practical File
DOCX
PPT
Interfacing UART with tms320C6745
PDF
The IoT Academy IoT Training Arduino Part 3 programming
PDF
Exploring the x64
iCloud keychain
Switch & LED using TMS320C6745 DSP
Connectivity for Local Sensors and Actuators Using nRF24L01+
selected input/output - sensors and actuators
ゆるふわコンピュータ (IPSJ-ONE2017)
Led blinking using TMS320C6745
Computron príručka
All VLSI programs
Cisco IOS shellcode: All-in-one
Vectorization on x86: all you need to know
Classical cryptography
Classical cryptography1
Seven segment display
深入淺出C語言
Dsd lab Practical File
Interfacing UART with tms320C6745
The IoT Academy IoT Training Arduino Part 3 programming
Exploring the x64
Ad

Similar to Solution doc (20)

PDF
Gaztea Tech Robotica 2016
PPTX
Sensors and Actuators in Arduino, Introduction
PDF
UDP.yash
PPTX
Attendance System using ESP8266(Wi-Fi) with MySQL
PDF
COMPUTER NETWORKS AND SECURITY PRACTICAL
PDF
Getting Started With Raspberry Pi - UCSD 2013
PDF
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
PDF
Arduino uno basic Experiments for beginner
PDF
An Example MIPS
PPTX
Monitoring temperature rumah dengan display lcd dan recording
PDF
What will be quantization step size in numbers and in voltage for th.pdf
DOCX
Microcontroladores: programas de CCS Compiler.docx
PDF
Arduino shield wifi-monitorizarelocuinta
PPTX
Monitoring temperature ruangan dengan display lcd
PPTX
Monitoring temperature rumah dengan display lcd dan recording
PDF
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
PPTX
Arduino Programming
PPTX
用Raspberry Pi 學Linux I2C Driver
PPTX
Monitoring Temperature Room With Display LCD and Data Recording
PPTX
Monitoring temperature ruangan dengan display lcd
Gaztea Tech Robotica 2016
Sensors and Actuators in Arduino, Introduction
UDP.yash
Attendance System using ESP8266(Wi-Fi) with MySQL
COMPUTER NETWORKS AND SECURITY PRACTICAL
Getting Started With Raspberry Pi - UCSD 2013
WIFI ESP01 interfacing with Arduino UNO with Sensor DHT11
Arduino uno basic Experiments for beginner
An Example MIPS
Monitoring temperature rumah dengan display lcd dan recording
What will be quantization step size in numbers and in voltage for th.pdf
Microcontroladores: programas de CCS Compiler.docx
Arduino shield wifi-monitorizarelocuinta
Monitoring temperature ruangan dengan display lcd
Monitoring temperature rumah dengan display lcd dan recording
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
Arduino Programming
用Raspberry Pi 學Linux I2C Driver
Monitoring Temperature Room With Display LCD and Data Recording
Monitoring temperature ruangan dengan display lcd
Ad

More from JIGAR MAKHIJA (20)

PPTX
Php gd library
PPTX
Php pattern matching
PPTX
Php cookies
PPTX
Php functions
PPTX
Php sessions
PPTX
Php server variables
PDF
Db function
PDF
C++ version 1
PDF
C++ Version 2
PPTX
SAP Ui5 content
PDF
Overview on Application protocols in Internet of Things
PDF
125 green iot
PDF
Msp430 g2 with ble(Bluetooth Low Energy)
PDF
Embedded system lab work
PPTX
Presentation on iot- Internet of Things
PPTX
PDF
Learn Japanese -Basic kanji 120
PPTX
View Alignment Techniques
DOCX
Letters (complaints & invitations)
PDF
Letter Writing invitation-letter
Php gd library
Php pattern matching
Php cookies
Php functions
Php sessions
Php server variables
Db function
C++ version 1
C++ Version 2
SAP Ui5 content
Overview on Application protocols in Internet of Things
125 green iot
Msp430 g2 with ble(Bluetooth Low Energy)
Embedded system lab work
Presentation on iot- Internet of Things
Learn Japanese -Basic kanji 120
View Alignment Techniques
Letters (complaints & invitations)
Letter Writing invitation-letter

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
master seminar digital applications in india
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
GDM (1) (1).pptx small presentation for students
102 student loan defaulters named and shamed – Is someone you know on the list?
Microbial diseases, their pathogenesis and prophylaxis
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
master seminar digital applications in india
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
RMMM.pdf make it easy to upload and study
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
GDM (1) (1).pptx small presentation for students

Solution doc

  • 1. Library Requirements:  Adafruit_BMP280_Library  Adafruit-GFX-Library  Adafruit_SSD1306  MFRC522  Adafruit_MPU6050.h 1. Soil moisture threshold check to actuate the relay Code: sensorValue = analogRead(sensorPin); Set threshold to 400 If the sensor value is > the threshold Trigger relay To trigger relay if (sensorValue > threshold limit) { digitalWrite(A2, HIGH); } else { digitalWrite(A2, LOW); } delay(1000); } Pin Connection 3V --> VCC GND --> GND A0 --> A0 2. Read Temperature & pressure using BMP sensor. Note that, you can change the I2C address without modifying the library, just type: bmp.begin(0x77); Code: #include <Adafruit_BMP280.h> Adafruit_BMP280 bmp; // I2C Interface void setup() { Serial.begin(9600); Serial.println(F("BMP280 test")); bmp.begin(); } void loop() {
  • 2. Serial.print(F("Temperature = ")); Serial.print(bmp.readTemperature()); Serial.println(" *C"); Serial.print(F("Pressure = ")); Serial.print(bmp.readPressure()/100); //displaying the Pressure in hPa, you can change the unit Serial.println(" hPa"); Serial.print(F("Approx altitude = ")); Serial.print(bmp.readAltitude(1019.66)); //The "1019.66" is the pressure(hPa) at sea level in day in your region Serial.println(" m"); //If you don't know it, modify it until you get your current altitude Serial.println(); delay(2000); } 3. Using RFID to display welcome message on Serial OLED Display - Arduino Vcc - 3.3V GND - GND SCL - Analog Pin 5 SDA - Analog Pin 4 Code: #include <SPI.h> #include <MFRC522.h> #define SS_PIN 10 #define RST_PIN 9 MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class MFRC522::MIFARE_Key key; // Init array that will store new NUID byte nuidPICC[4]; void setup() { Serial.begin(9600); SPI.begin(); // Init SPI bus rfid.PCD_Init(); // Init MFRC522 for (byte i = 0; i < 6; i++) { key.keyByte[i] = 0xFF; } RFID Reader - Arduino RST ▶ Digital Pin 9 IRQ ▶ Unconnected MISO ▶ Digital Pin 12 MOSI ▶ Digital Pin 11 SCK ▶ Digital Pin 13 SDA ▶ Digital Pin 10
  • 3. } void loop() { // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. if ( ! rfid.PICC_IsNewCardPresent()) return; // Verify if the NUID has been readed if ( ! rfid.PICC_ReadCardSerial()) return; Serial.print(F("PICC type: ")); MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); Serial.println(rfid.PICC_GetTypeName(piccType)); if (rfid.uid.uidByte[0] != nuidPICC[0] || rfid.uid.uidByte[1] != nuidPICC[1] || rfid.uid.uidByte[2] != nuidPICC[2] || rfid.uid.uidByte[3] != nuidPICC[3] ) { Serial.println(F("A new card has been detected.")); // Store NUID into nuidPICC array for (byte i = 0; i < 4; i++) { nuidPICC[i] = rfid.uid.uidByte[i]; } Serial.println(F("The NUID tag is:")); Serial.print(F("In hex: ")); printHex(rfid.uid.uidByte, rfid.uid.size); Serial.println(); Serial.print(F("In dec: ")); printDec(rfid.uid.uidByte, rfid.uid.size); Serial.println(); } else Serial.println(F("Card read previously.")); // Halt PICC rfid.PICC_HaltA(); // Stop encryption on PCD rfid.PCD_StopCrypto1(); } /** * Helper routine to dump a byte array as hex values to Serial. */ void printHex(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } }
  • 4. /** * Helper routine to dump a byte array as dec values to Serial. */ void printDec(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], DEC); } } 4. Ultrasonic sensor to find the distance & height int trigPin = 6; // HC-SR04 trigger pin int echoPin = 7; // HC-SR04 echo pin float duration, distance; void setup() { Serial.begin(9600); pinMode(trigPin, OUTPUT); // define trigger pin as output } void loop() { digitalWrite(echoPin, LOW); // set the echo pin LOW digitalWrite(trigPin, LOW); // set the trigger pin LOW delayMicroseconds(2); digitalWrite(trigPin, HIGH); // set the trigger pin HIGH for 10μs delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); // measure the echo time (μs) distance = (duration/2.0)*0.0343; // convert echo time to distance (cm) if(distance>400 || distance<2) Serial.println("0"); else { Serial.print("90, "); Serial.print(distance, 1); Serial.println(" ,cm"); } delay(1000); } 5. Accelerometer to find out the vibrations and see the plottings // Basic demo for accelerometer readings from Adafruit MPU6050 #include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <Wire.h> Adafruit_MPU6050 mpu;
  • 5. void setup(void) { Serial.begin(115200); mpu.begin(); mpu.setAccelerometerRange(MPU6050_RANGE_16_G); mpu.setGyroRange(MPU6050_RANGE_250_DEG); mpu.setFilterBandwidth(MPU6050_BAND_21_HZ); Serial.println(""); delay(100); } void loop() { /* Get new sensor events with the readings */ sensors_event_t a, g, temp; mpu.getEvent(&a, &g, &temp); /* Print out the values */ Serial.print(a.acceleration.x); Serial.print(","); Serial.print(a.acceleration.y); Serial.print(","); Serial.print(a.acceleration.z); Serial.print(", "); Serial.print(g.gyro.x); Serial.print(","); Serial.print(g.gyro.y); Serial.print(","); Serial.print(g.gyro.z); Serial.println(""); delay(10); }