0% found this document useful (0 votes)
32 views40 pages

Es&iomt Lab Manuval-3-42

lab

Uploaded by

24ecet02
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)
32 views40 pages

Es&iomt Lab Manuval-3-42

lab

Uploaded by

24ecet02
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/ 40

Ex no: 01

Explore AVR based controllers using Embedded C


Date:

Aim
To Explore AVR/ARM based controllers using Embedded C.

Apparatus Required

1. Personal computer
2. Arduino Uno board
3. Arduino simulator

PROCEDURE

AVR/Arduino Technology Architecture and Its Advantages

Arduino Board
An Arduino board is a one type of microcontroller based kit. The first Arduino technology was
developed in the year 2005 by David Cuartielles and Massimo Banzi. The designers thought to
provide easy and low cost board for students, hobbyists and professionals to build devices.
Arduino board can be purchased from the seller or directly we can make at home using various
basic components. The best examples of Arduino for beginners and hobbyists includes motor
detectors and thermostats, and simple robots
Arduino Technology
A typical example of the Arduino board is Arduino Uno.It includes an ATmega328
microcontroller and it has 28-pins

Arduino Pin Diagram

1
The pin configuration of the Arduino Uno board is shown in the above. It consists of 14-digital i/o
pins. Wherein 6 pins are used as pulse width modulation o/ps and 6 analog i/ps, a USB connection, a
power jack, a 16MHz crystal oscillator, a reset button, and an ICSP header. Arduino board can be
powered either from the personal computer through a USB or external source like a battery or an
adaptor. This board can operate with an external supply of 7-12V by giving voltage reference
through the IORef pin or through the pin Vin.

Digital I/Ps
It comprises of 14-digital I/O pins, each pin take up and provides 40mA current. Some of the pins
have special functions like pins 0 & 1, which acts as a transmitter and receiver respectively. For
serial communication, pins-2 & 3 are external interrupts, 3,5,6,9,11 pins delivers PWM o/p and pin-
13 is used to connect LED.

Analog i/ps: It has 6-analog I/O pins, each pin provide a 10 bits resolution.
Aref: This pin gives a reference to the analog i/ps.
Reset: When the pin is low, then it resets the microcontroller.

Arduino Architecture
Basically, the processor of the Arduino board uses the Harvard architecture where the program code
and program data have separate memory. It consists of two memories such as program memory and
data memory. Wherein the data is stored in data memory and the code is stored in the flash program
memory. The Atmega328 microcontroller has 32kb of flash memory, 2kb of SRAM 1kb of EPROM
and operates with a 16MHz clock speed.

Arduino Architecture

2
Basic Functions of Arduino Technology
 Digital read pin reads the digital value of the given pin.
 Digital write pin is used to write the digital value of the given pin.
 Pin mode pin is used to set the pin to I/O mode.
 Analog read pin reads and returns the value.
 Analog write pin writes the value of the pin.
 Serial. Begins pin sets the beginning of serial communication by setting the rate of bit.

Advantages of Arduino Technology
 It is cheap
 It comes with an open supply hardware feature that permits users to develop their own kit
 The software of the Arduino is well-suited with all kinds of in operation systems like Linux,
Windows, and Macintosh, etc.
 It also comes with open supply software system feature that permits tough software system
developers to use the Arduino code to merge with the prevailing programing language
libraries and may be extended and changed.
 For beginners, it is very simple to use.

Simple program
BLINK LED
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}

Result

Thus the program for AVR based controllers are verified.

3
Ex no:02
Basic and arithmetic Programs Using Embedded C
Date:

Aim:
To write Basic and arithmetic Programs Using Embedded C

Apparatus Required
1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Procedure

 Data Types: Embedded systems typically support various data types, such as integers (signed and
unsigned), floating-point numbers, and fixed-point numbers. The choice of data type depends on
factors like the required range, precision, and memory constraints.
 Binary Representation: Arithmetic operations in embedded systems are performed using binary
representation. Numbers are typically stored in binary format using a fixed number of bits. For
example, an 8-bit microcontroller can store values from 0 to 255.
 Integer Arithmetic: Embedded systems often deal with integer arithmetic. Addition and
subtraction of integers are straightforward and can be performed using binary addition and
subtraction algorithms. Multiplication and division operations may require more complex
algorithms like shifting and bit manipulation.

4
Program

Arithmetic Program
void setup() {
// Initialize Serial

// Communication
Serial.begin(57600);
}
void loop() {
int num1 = 10; // First

// number
int num2 = 5; // Second

//number
int result; // Result
// Perform arithmetic
//operations
result = num1 + num2; // Addition
Serial.print("Sum: ");
Serial.println(result);
result = num1 - num2;
// Subtraction
Serial.print("Difference: ");
Serial.println(result);
result = num1 * num2;
//multiplication
Serial.print("Product: ");
Serial.println(result);
result = num1 / num2;
// Division
5
Serial.print("Quotient: ");
Serial.println(result);
delay(1000);
// Delay for 1 second
}

Program to Find the Sum of Two Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(57600);
}

void loop() {
// Define two variables to hold the numbers
int num1 = 10;
int num2 = 20;

// Find the sum of the two numbers


int sum = num1 + num2;

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Sum: ");
Serial.println(sum);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

6
Program to Calculate the Average of Three Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(9600);
}

void loop() {
// Define three variables to hold the numbers
int num1 = 10;
int num2 = 20;
int num3 = 30;

// Calculate the average of the three numbers


float average = (num1 + num2 + num3) / 3.0;

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Number 3: ");
Serial.println(num3);
Serial.print("Average: ");
Serial.println(average);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

7
Program to Find the Maximum of Two Numbers:

void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(57600);
}

void loop() {
// Define two variables to hold the numbers
int num1 = 10;
int num2 = 20;

// Find the maximum of the two numbers


int maxNum = max(num1, num2);

// Print the results to the Serial Monitor (optional)


Serial.print("Number 1: ");
Serial.println(num1);
Serial.print("Number 2: ");
Serial.println(num2);
Serial.print("Maximum: ");
Serial.println(maxNum);

// Do nothing for a short period to avoid spamming the Serial Monitor (optional)
delay(5000);
}

Result:

Thus the embedded C programs to perform basic and arithmetic Programs are verified.
8
Ex no: 0 3 Embedded C program to test interrupt and timers
Date:

Aim
To write Embedded C program to test interrupt and timers.

Apparatus Required
1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Program

Interrupts
const int interruptPin = 2; // Pin for the external interrupt
volatile int counter = 0; // Counter variable

void ISR_function() {
counter++; // Increment the counter when the interrupt occurs
}

void setup() {
pinMode(interruptPin, INPUT_PULLUP); // Set the interrupt pin as input with pull-up resistor
attachInterrupt(digitalPinToInterrupt(interruptPin), ISR_function, FALLING); // Attach ISR to the
interrupt pin
Serial.begin(9600); // Initialize Serial communication
}

void loop() {
// Main program code (runs repeatedly)
Serial.println("Counter: " + String(counter)); // Display the counter value on the Serial Monitor
delay(1000); // Add a short delay to avoid flooding the Serial Monitor

9
}

Timers

const int ledPin = 13; // Pin number for the LED

void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
initializeTimer1(); // Initialize Timer 1
}

void loop() {
// The main program doesn't need to do anything
// The LED blinking is handled by the timer
}

void initializeTimer1() {
noInterrupts(); // Disable interrupts while setting up the timer

// Set Timer 1 to CTC (Clear Timer on Compare) mode


TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;

// Set the desired interval for the timer in microseconds


unsigned long intervalMicros = 1000000; // 1 second
unsigned long prescaler = 64; // Timer 1 prescaler = 64 (change as needed)

// Calculate the compare value based on the clock speed and desired interval
unsigned long compareValue = (F_CPU / (prescaler * intervalMicros)) - 1;
OCR1A = compareValue;

// Enable the compare interrupt for Timer 1

10
TIMSK1 |= (1 << OCIE1A);

// Set Timer 1 prescaler to 64


TCCR1B |= (1 << CS11) | (1 << CS10);

interrupts(); // Re-enable interrupts after setting up the timer


}

// Timer 1 Compare Match A ISR


ISR(TIMER1_COMPA_vect) {
// Toggle the LED state
digitalWrite(ledPin, !digitalRead(ledPin));
}

Result :
Thus, the program to test interrupt and timers are verified.

11
Ex no: 0 4 Develop Real time applications – clock generation, waveform generation,
Date: counter using embedded C

Aim
To develop Real time applications – clock generation, waveform generation, counter using
embedded C.

Apparatus Required
1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Program

clock generation
const int pulsePin = 9; // Pin number for the pulse wave output

void setup() {
pinMode(pulsePin, OUTPUT); // Set the pulse pin as an output
Serial.begin(9600); // Initialize Serial communication
}

void loop() {
// Generate and print the pulse wave
for (int i = 0; i < 100; i++) {
digitalWrite(pulsePin, HIGH); // Set the pin to HIGH
delay(10); // Pulse width: 10 milliseconds (adjust as needed)
digitalWrite(pulsePin, LOW); // Set the pin to LOW
delay(990); // Gap between pulses: 990 milliseconds (adjust as needed)
Serial.println("1"); // Print "1" to the Serial Monitor during the pulse
Serial.println("0"); // Print "0" to the Serial Monitor during the gap
}
}
12
Wave form generation

const int numSamples = 100; // Number of samples for the sine wave
const int amplitude = 50; // Amplitude of the sine wave
const int frequency = 1; // Frequency of the sine wave (in Hz)
const int offset = 128; // Offset to center the sine wave around 0 (0 to 255)

void setup() {
Serial.begin(9600); // Initialize Serial communication
}

void loop() {
// Generate and print the sine wave
for (int i = 0; i < numSamples; i++) {
float angle = 2 * PI * frequency * i / numSamples;
int sinValue = amplitude * sin(angle) + offset;
Serial.println(sinValue); // Print the sine value to the Serial Monitor
delay(10); // Delay to control the sine wave frequency (lower values for higher frequency)
}
}

Counter program

unsigned long previousMillis = 0; // Variable to store the last time the counter was updated
const long interval = 1000; // Interval in milliseconds (1 second)

int counter = 0; // Counter variable

void setup() {
Serial.begin(9600); // Initialize Serial communication
}

13
void loop() {
unsigned long currentMillis = millis(); // Get the current time

// Check if the time interval has passed to update the counter


if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // Update the last time counter was updated
counter++; // Increment the counter
Serial.println("Counter: " + String(counter)); // Display the counter value on the Serial Monitor
}

// Other tasks or logic can be performed here


// Just make sure it doesn't take too long, so the counter updates smoothly
}

Result

Thus the program for clock generation, waveform generation, counter are verified
14
Ex no: 05
Explore different communication methods with IoT devices
Date:

Aim

To explore different communication methods with IoT devices (Zigbee, GSM, Bluetooth)
Arduino programs to communicate with IoT devices using Zigbee, GSM, and Bluetooth

Apparatus Required

1. Personal computer
2. Arduino Uno board
3. Arduino simulator
4. Zigbee, GSM and Bluetooth board

Zigbee Communication:

#include <SoftwareSerial.h>
SoftwareSerial zigbee(2, 3); // RX, TX
void setup() {
Serial.begin(9600);
zigbee.begin(9600);
}
void loop() {
if (zigbee.available()) {
char receivedData = zigbee.read();
Serial.print("Received data: ");
Serial.println(receivedData);
}
if (Serial.available()) {
char sendData = Serial.read();
15
zigbee.print(sendData);
}
}

Procedure

This program sets up communication between an Arduino and a Zigbee module using
SoftwareSerial. It reads data from the Zigbee module and prints it to the serial monitor, and it also
allows data to be sent from the serial monitor to the Zigbee module.

GSM Communication (Sending SMS):


#include <SoftwareSerial.h>
SoftwareSerial gsm(2, 3); // RX, TX

void setup() {
Serial.begin(9600);
gsm.begin(9600);
delay(2000);
gsm.println("AT+CMGF=1"); // Set SMS mode to text
delay(1000);
gsm.println("AT+CMGS=\"+1234567890\""); // Replace with desired phone number
delay(1000);
gsm.println("Hello from Arduino!"); // Replace with desired message
delay(1000);
gsm.println((char)26); // Send Ctrl+Z to end the message
}

16
void loop() {
// Empty loop
}

Procedure
This program uses SoftwareSerial to establish communication between an Arduino and a GSM
module. It sends an SMS message containing a predefined message to a specified phone number.
Bluetooth Communication:

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
}

void loop() {
if (bluetooth.available()) {
char receivedData = bluetooth.read();
Serial.print("Received data: ");
Serial.println(receivedData);
}

if (Serial.available()) {
char sendData = Serial.read();
bluetooth.print(sendData);
}
}

17
Procedure

This program establishes communication between an Arduino and a Bluetooth module using
SoftwareSerial. It reads data from the Bluetooth module and prints it to the serial monitor, and it also
allows data to be sent from the serial monitor to the Bluetooth module.
Make sure to adjust the pins used for SoftwareSerial communication and modify the specific
settings based on your IoT devices' requirements. Additionally, ensure that you have the necessary
libraries installed for Zigbee, GSM, or Bluetooth communication.

Result:

Thus the Arduino programs to communicate with IoT devices (Zigbee, GSM, Bluetooth) are written
and verified for its execution.

18
Ex no: 06 To interface LED/Buzzer with Arduino and write an embedded C program
Date: to turn on / off LED/Buzzer with specified delay

Aim

To interface LED/Buzzer with platform/ Aurdino /Raspberry Pi and write an embedded C program to
turn on / off LED/Buzzer with specified delay.

Program
This program blinks the built-in LED on the Arduino board with a 1-second interval.

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}

Button LED Control:


This program controls an LED using a button. When the button is pressed, the LED turns
on, and when released, it turns off.
const int buttonPin = 2;
const int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}

19
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

Result:

Thus the basic Arduino programs are verified for its execution

20
Ex no: 07 Interface stepper motor using relay with Arduino and write an
Date: embedded C program to turn on motor if push button is pressed.

Aim
To interface stepper motor using relay with Arduino and write an embedded C program to turn on
motor if push button is pressed.

Apparatus Required

1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Program
To interface stepper motor using relay with open platform/ Arduino
// Define the pins connected to the ULN2003A inputs
const int in1Pin = 8;
const int in2Pin = 9;
const int in3Pin = 10;
const int in4Pin = 11;
void setup() {
// Set the IN pins as outputs
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
}
void loop() {
// Rotate the stepper motor clockwise
rotateClockwise(200); // 200 steps
delay(1000); // Pause for 1 second
// Rotate the stepper motor counterclockwise
21
rotateCounterclockwise(200); // 200 steps
delay(1000); // Pause for 1 second
}
// Function to rotate the stepper motor clockwise
void rotateClockwise(int steps) {
for (int i = 0; i < steps; i++) {
digitalWrite(in1Pin, HIGH);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(10);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, HIGH);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(10);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, HIGH);
digitalWrite(in4Pin, LOW);
delay(10);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, HIGH);
delay(10);
}
}
// Function to rotate the stepper motor counterclockwise
void rotateCounterclockwise(int steps) {
for (int i = 0; i < steps; i++) {
digitalWrite(in1Pin, LOW);

22
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, HIGH);
delay(10);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, HIGH);
digitalWrite(in4Pin, LOW);
delay(10);
digitalWrite(in1Pin, LOW);
digitalWrite(in2Pin, HIGH);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(10);
digitalWrite(in1Pin, HIGH);
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(10);
}
}

Result
Thus the program to interface stepper motor using relay with audrino and also to turn on motor if
push button is pressed using embedded C are verified.

23
Ex no: 08 Develop simple application – testing infrared sensor using Raspberry
Date: Pi/cloud platfrom.

Aim
Develop simple application – testing infrared sensor – IoT Applications – using open platform/Raspberry
Pi

Apparatus Required
1. Personal computer
2. Raspberry Pi board
3. Cloud platform

Procedure
1. Make sure you have WiringPi installed on your Raspberry Pi. If not, you can install it by following
the instructions at: http://wiringpi.com/download-and-install/
2. Create a new C source file, for example, ir_sensor_test.c.
3. Open the file in a text editor and add the following code
4. Save the file and exit the text editor.
5. Open a terminal on your Raspberry Pi.
6. Compile the program using the following command:

Program

#include <wiringPi.h>
#include <stdio.h>
#define IR_SENSOR_PIN 1 // Use the appropriate GPIO pin number
int main(void) {
if (wiringPiSetup() == -1) {
24
printf("Unable to initialize WiringPi\n");
return 1;
}
pinMode(IR_SENSOR_PIN, INPUT);
while (1) {
int sensorValue = digitalRead(IR_SENSOR_PIN);

if (sensorValue == HIGH) {
printf("Object detected!\n");
} else {
printf("No object detected.\n");
}
delay(100); // Delay for 100 milliseconds
}

return 0;
}

Procedure
1. The program will continuously read the state of the IR sensor pin and print "Object detected!" or "No
object detected." based on the sensor's output.
2. Please note that you might need to adjust the IR_SENSOR_PIN value in the code to match the GPIO pin
number you connected the IR sensor output to.
3. Ensure that you have the necessary permissions to access GPIO pins. You may need to run the program
with root privileges (e.g., using sudo) or add your user to the gpio gro

Program
IOT application
#include <stdio.h>
#include <stdlib.h>

25
#include <wiringPi.h>
#include <mosquitto.h>
#define IR_SENSOR_PIN 17
#define MQTT_HOST "your_mqtt_host"
#define MQTT_PORT 1883
#define MQTT_TOPIC "your_topic"

void mqtt_connect_callback(struct mosquitto *mosq, void *obj, int result)


{
if (result == 0)
{
printf("MQTT connected successfully.\n");
}
else
{
printf("MQTT connection failed.\n");
}
}

int main(void)
{
wiringPiSetupGpio(); // Initialize WiringPi

pinMode(IR_SENSOR_PIN, INPUT); // Set IR sensor pin as input

struct mosquitto *mosq = NULL;


mosquitto_lib_init(); // Initialize Mosquitto library
mosq = mosquitto_new(NULL, true, NULL);
if (mosq == NULL)

26
{
printf("Failed to create MQTT instance.\n");
return 1;
}
mosquitto_connect_callback_set(mosq, mqtt_connect_callback);
if (mosquitto_connect(mosq, MQTT_HOST, MQTT_PORT, 60) != MOSQ_ERR_SUCCESS)
{
printf("Failed to connect to MQTT broker.\n");
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
return 1;
}
while (1)
{
int sensorValue = digitalRead(IR_SENSOR_PIN);
if (sensorValue == HIGH)
{
char message[10];
snprintf(message, sizeof(message), "%d", sensorValue);
mosquitto_publish(mosq, NULL, MQTT_TOPIC, sizeof(message), message, 0, false);
}
delay(500); // Delay for 500 milliseconds
} mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
return 0;
}

Result
Thus the program for IOT application based IR sensor are verified

27
Ex no: 0 9 Develop simple application to interface DHT11 sensor with Arduino and
Date: write a program to display temperature humidity readings in LCD.

Aim
To develop simple application to interface DHT11 sensor with Arduino and write a program to
display temperature humidity readings in LCD.

Apparatus Required
1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Program

Interfacing a Temperature and Humidity Sensor (DHT11) with Raspberry Pi:

import Adafruit_DHT

sensor = Adafruit_DHT.DHT11
pin = 4

while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:


print(f'Temperature: {temperature}°C, Humidity: {humidity}%')
else:
print('Failed to retrieve data from the sensor!')

This program interfaces a DHT11 temperature and humidity sensor with the Arduino
using the Adafruit_DHT library. It continuously reads and prints the temperature and

28
humidity values from the sensor.

Program to display temperature humidity readings in LCD.

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN D1 // Pin connected to the DHT11 sensor


#define DHTTYPE DHT11 // DHT 11

DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else
{
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F(" °C"));
29
}

dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
} else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
}

This program is used to replace the lcd.h and lcd_init() with the appropriate header file and
initialization function for your specific LCD module. The readTemperatureHumidity() function should
be implemented according to the method of reading temperature and humidity values from your
sensors.

Result:

Thus the programs for interfacing of various sensors with Raspberry Pi and also display
temperature humidity readings are written and verified for its execution

30
Ex no: 1 0 Develop IoMT Application using Aurdino and sensors such as temperature,
Date: ECG, Pulse

Aim

To Develop IoMT Application using Aurdino and sensors such as temperature, ECG, Pulse.

Apparatus Required

1. Personal computer
2. Arduino Uno board
3. Arduino simulator

Program

#include <OneWire.h
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MAX30102.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

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

sensors.begin();

if (!pulseSensor.begin(Wire, I2C_SPEED_FAST)) {
Serial.println("Sensor not found. Check wiring!");
31
while (1);
}

pulseSensor.setup();
}

void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);

int ecgValue = analogRead(A0);

pulseSensor.getHR();
int pulseRate = pulseSensor.getHeartRate();

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");

Serial.print("ECG: ");
Serial.println(ecgValue);

Serial.print("Pulse Rate: ");


Serial.print(pulseRate);
Serial.println(" BPM");

delay(1000);
}}

Result:
Thus the programs for communicating Arduino with Raspberry Pi are written and verified for its
execution.

32
Ex no: 1 1 Deploy IoMT applications using platforms
Date:

Aim
To deploy IoMT applications using platforms

Procedure
This program interfaces an HC-SR04 ultrasonic distance sensor with the Raspberry Pi. It uses
the GPIO library to control the GPIO pins. It continuously measures and prints the distance in
centimeters.

Program
Interfacing an Ultrasonic Distance Sensor (HC-SR04) with Raspberry Pi
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
trigger_pin = 18
echo_pin = 24
GPIO.setup(trigger_pin, GPIO.OUT)
GPIO.setup(echo_pin, GPIO.IN)

while True:
GPIO.output(trigger_pin, True)
time.sleep(0.00001)
GPIO.output(trigger_pin, False)
start_time = time.time()
stop_time = time.time()
while GPIO.input(echo_pin) == 0:
start_time = time.time()

while GPIO.input(echo_pin) == 1:
stop_time = time.time()

33
elapsed_time = stop_time - start_time
distance = (elapsed_time * 34300) / 2
print(f'Distance: {distance} cm')
time.sleep(1)

Interfacing an Pressure Sensor with Arduino Pi:


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(9600);

if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}

void loop() {
sensors_event_t pressureEvent;
bmp.getEvent(&pressureEvent);

if (pressureEvent.pressure) {
float pressurePa = pressureEvent.pressure;
float pressurePsi = pressurePa * 0.0001450377; // Conversion to psi

Serial.print("Pressure (Pa): ");


Serial.print(pressurePa);
Serial.print(" Pressure (psi): ");
Serial.println(pressurePsi);
}

34
delay(1000); // Adjust the delay as per your requirements
}

Result
Thus the program to deploy IoMT applications using platforms are verified

35
Ex no: 12 MINI PROJECT TOPICS
Date:

1. Remote Patient Monitoring System using IOMT


2. Mental Health Monitoring and Support
3. Emergency Response System
4. Smart Health Monitoring for Chronic Conditions
5. Fall Detection and Prevention
6. Medication Adherence System
7. IoMT-Enabled Smart Biowaste Management System Design
8. On-Board Diagnostic (OBD) System
9. Brain-Actuated Humanoid Robot Navigation Control
10. IoT-Enabled Environmental Monitoring and Control System Design

36
Ex no: 1 3
Communication between Arduino and Raspberry PI using Bluetooth
Date:

Program to Communicate between Arduino and Raspberry PI using Bluetooth

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3); // RX, TX

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

void loop() {
if (bluetooth.available()) {
char receivedData = bluetooth.read();
Serial.print("Received data: ");
Serial.println(receivedData);
}

if (Serial.available()) {
char sendData = Serial.read();
bluetooth.print(sendData);
}
}

Raspberry Pi (Python) Code:


import serial

ser = serial.Serial('/dev/rfcomm0', 9600) # Update with the correct Bluetooth serial port

37
try:
while True:
message = input("Enter a message to send: ")
ser.write(message.encode())
print("Message sent")
except KeyboardInterrupt:
pass

ser.close()

In the Arduino code, we use the SoftwareSerial library to establish communication with the
Bluetooth module. It reads data from the Bluetooth module and prints it to the serial monitor. It
also allows data to be sent from the serial monitor to the Bluetooth module.
On the Raspberry Pi, we use the serial library to establish communication with the Bluetooth
module. It prompts the user to enter a message, sends it to the Arduino over Bluetooth, and prints a
confirmation message.
Make sure to pair the Arduino and Raspberry Pi via Bluetooth and identify the correct serial
port (/dev/rfcomm0 in this example) on the Raspberry Pi before running the code.

Result:
Thus the programs for communicating Arduino with Raspberry Pi are written and verified for its
execution

38
Ex no: 1 4
8051 Assembly Language using simulator
Date:

Write 8051 Assembly Language experiments using simulator.

Aim
1 a. To Write an ALP to move a block of data from one internal memory location to other.

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV R0,#30H ;r0=30h i.e. initial block memory location
MOV R1,#40H ;r1=40h i.e. block memory location where data has to
transfer
MOV R2,#05H ; load counter as 05h (n) in register r2
NEXT: MOV A,@R0 ;copy the contents of memory location pointed by
register r0 into A
MOV @R1,A ;copy the contents of register A into memory location
pointed by reg r1
INC R0 ;increment register r0
INC R1 ;increment register r1
DJNZ R2, NEXT ;decrement register r2 if not equal to zero jump to
next
LCALL 0003H ;end of asm file

39
1b) Write an ALP to move a block of data from one external memory location to other

Label Opcode and Operands Comments


ORG 0000H
LJMP 8000H
ORG 8000H
MOV R0,#04H ;load the counter as 04h (n) in register r0
MOV R1,#81H ;higher byte of initial block=81h in register r1
MOV R2,#85H ;higher byte of memory location where data has;to
transfer=85h in reg r2
MOV R3,#00H ;lower byte of both initial and final block=00h in register r3
UP: MOV DPH,R1 ;DPH=contents of register r1
MOV DPL,R3 ;DPL=contents of register r3
MOVX A,@DPTR ;copy the contents of memory location pointed by DPTRinto
reg A
MOV DPH,R2 ;dph=contents of register r2
MOVX @DPTR,A ;copy the contents of reg A into memory location pointedby
reg dptr
INC R3 ;increment register r3
DJNZ R0,UP ;decrement register r0 if not equal to zero jump to up
LCALL 0003H ;end of asm file

Result:

Thus the data transfer between registers and memory in 8051 has been tested and verified.

40

You might also like