Embedded & IOMT Lab Manual
Embedded & IOMT Lab Manual
IOMT LABORATORY
SYLLABUS
COURSE OBJECTIVES:
Acquire knowledge and understand the hardware architecture and programming aspects of
embedded system design.
Understand IoT architecture and Build simple IoT Systems using embedded target 89 boards.
Understand IoMT infrastructure for healthcare applications.
LIST OF EXPERIMENTS
1. Explore AVR/ARM based controllers using Embedded C.
2. Write Basic and arithmetic Programs Using Embedded C.
3. Write Embedded C program to test interrupt and timers.
4. Develop Real time applications – clock generation, waveform generation, counter using
embedded C.
5. Explore different communication methods with IoT devices.
6. To interface LED/Buzzer with platform/ Aurdino /Raspberry Pi. and write an embedded C
program to turn on / off LED/Buzzer with specified delay.
7. To interface DC/stepper motor using relay with open platform/ Aurdino /Raspberry Pi. and
write an embedded C program to turn on motor if push button is pressed.
8. Develop simple application – testing infrared sensor – IoT Applications – using open
platform/Raspberry Pi.
9. Develop simple application to interface DHT11 sensor with and write a program to display
temperature humidity readings in LCD.
10. Develop IoMT Application using open platform/ Aurdino. /Raspberry Pi. and sensors such
as temperature, ECG, Pulse etc.
11. Deploy IoMT applications using platforms.
12. Mini Project.
TOTAL: 45 PERIODS
COURSE OUTCOMES:
At the end of the course, the students will be able to:
CO1: Explain hardware architecture of embedded systems and use of software design tools
CO2: Describe IoT Architectures and Build simple IoT Systems using embedded target boards.
CO3: Exhibit understanding of IoMT infrastructure for healthcare with simple applications.
Marks Marks
Evaluation Parameters
Allotted Awarded
Aim & Hardware / Software Required: 10
Design & Circuit Diagram / Algorithm &
30
Flowchart:
Observation & Calculation / Program: 30
Graph / Output & Result: 20
Viva Voce: 10
Total: 100
To study the procedure for complication and debugging of program using IAR work bench.
APPARATUS&SOFTWARE REQUIRED
PROCEDURE
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
1. To create a new project, choose Project>Create New Project. The Create New Project
Dialog box appears, which lets you base your new project on a project template.
2. Make sure the Tool chain is set to ARM, and click OK.
3. Select the project template Empty project, and click ok button. This simply creates
an empty project that uses default project setting.
4. In the standard Save As dialog box that appears, specify where you want to place
your project file, that is, in your newly created projects directory. Type your
project name in the File name box, and click Save to create the new project.
E.g. LED.
To Creating your Application ‘C’ file, Choose FILE menu and select NEW>File
Edit the application code in C Language. E.g. Led_1.c. To Save your ‘C’ file,
ChooseFile>Save As. In the standard Save As dialog box that appears, specify where you
wantto place your project file, that is, in your project directory. Type your filename in the
Filename box, and click Save to create the new project. E.g. Led_1.c
1. In the Workspace window, select the destination to which you want to add a source
file; a group or, as in this case, directly to the project.
2. Choose Project>Add Files to open a standard browse dialog box. Locate the files
LED_1.c
Select them in the file selection list, and click Open to add them to the project.
To save your work space, Choose File>Save Workspace and specify where you want to
place your workspace file. In this tutorial, you should place it in your newly created
project directory. Type LED in the File name box, and click save button.
Now you will set the project options. For application projects, options can be set on all
levels of nodes. First you will set the general options to suit the processor configuration in
this tutorial. Because these options must be the same for the whole build configuration,
they must be set on the project node.
1. Select the project folder icon LED_OUT - Debug in the Workspace window and choose
Project>Options. Then select General Options to select your Controller.
3. The Output options are used for specifying details about the output format and the level
of debugging information included in the output file. Select output format as “Intel
Extended”, output file in the format of .hex format.
4. Select the linker file menu, linker configuration file available at project directory.
To Compile your Project, Choose Project>Rebuild ALL
5. Now click ok. Now your project is configured for your specified controller (i.e.)
STM32F407ZG.
Then right click on your project file and click add add files.
2. If your project has no error, then it will show Building successfully and the Hex file
will be generated.
RESULT:
Thus the study of the procedure for compilation and debugging is studied.
AIM:
To develop a Embedded C program for arithmetic operation
EQUIPMENTS:
1. VSK-SCM4 Development board.
2. IAR IDE software.
3. Flash Loader Demonstrator. .
THEORY:
The Arithmetic operators are some of the C Programming Operator, which are used to
perform arithmetic operations includes operators like Addition, Subtraction, Multiplication,
Division and Modulus.All these Arithmetic operators in C are binary operators which means they
operate on two operands.
PROCEDURE:
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.
PROGRAM CODING:
#include<stdio.h>
int main()
{
int a,b,c;
float x;
printf("\nEnter 2 Nos : ");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nTotal : %d",c);
c=a-b;
printf("\nDifference : %d",c);
c=a*b;
printf("\nMul : %d",c);
x=(float)a/(float)b;
printf("\nDiv : %0.2f",x);
c=a%b;
printf("\nMod : %d",c);
return 0;
}
OUTPUT
Enter 2 Nos : 25 10
Total : 35
Difference : 15
Mul : 250
Div : 2.50
Mod : 5
RESULT:
The C-Language program for arithmetic operation was written & output is verified
with
runnin Exp. Write Embedded C program to test interrupt and timers. g the
3
RTC No.: from a
Da
default te: /specif
ied time .
AIM:
To develop a C-Language program to write and read a data in EEPROM and also to
analyze its performance with the interrupt
Theory
Serial-interface EEPROM’s are used in a broad spectrum of consumer,
automotive, telecommunication, medical, industrial and PC related markets. Primarily
used to store personal preference data and configuration/setup data, Serial EEPROM’s
are the most flexible type of nonvolatile memory utilized today. Compared to other
NVM solutions, Serial EEPROM devices offer a lower pin count, smaller packages,
lower voltages, as well as lower power consumption
PROCEDURE
PROGRAM: READ
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
#define SLAVE_ADDRESS1 0xA6 // the slave address (example)
#define SLAVE_ADDRESS2 0xA7 // the slave address (example)
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();
int main(void)
{
USART2_config();
printf("\n welcome to EEPROM");
init_I2C1();
int i;
I2C_start(I2C1, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a
}
void USART2_config()
I2C_Mode_I2C;
// I2C mode I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading (can be
changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
// wait for I2C1 EV5 --> Slave has acknowledged start condition while(!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
I2C_SendData(I2Cx, data);
// wait for I2C1 EV8_2 --> byte has been transmitted
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)
{
// enable acknowledge of recieved data
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
I2C_GenerateSTOP(I2Cx, ENABLE);
}
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
I2C_start(I2Cx, SLAVE_ADDRESS2, I2C_Direction_Receiver); // start a transmission
In Master transmitter mode
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1);
Delay(200); return(j);
}
READ
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); int
int main(void)
{
USART2_config();
printf("\n welcome to EEPROM");
init_I2C1();
int i,gk;
void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; RCC->APB1ENR |
= 1 <<17; GPIOA-
return data;
}
void init_I2C1()
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
// configure I2C1
I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz I2C_InitStruct.I2C_Mode =
I2C_Mode_I2C; // I2C mode I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
// 50% duty cycle --> standard I2C_InitStruct.I2C_OwnAddress1 = 0x00;
// own address, not relevant in master mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading
(can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;// set address length
to 7 bit addresses
I2C_Init(I2C1, &I2C_InitStruct); // init I2C1
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
*/
if(direction == I2C_Direction_Transmitter)
{
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
I2C_GenerateSTOP(I2Cx, ENABLE);
}
int I2C_read(I2C_TypeDef* I2Cx,uint8_t MSB_addr,uint8_t LSB_addr)
{
int j;
I2C_start(I2Cx, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a transmission in
Master transmitter mode Delay(200);
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
I2C_start(I2Cx, SLAVE_ADDRESS2, I2C_Direction_Receiver); // start a transmission in
Master transmitter mode
Delay(200);
j = I2C_ReceiveData(I2C1);
//printf("\n %d",j);
I2C_stop(I2C1); Delay(200);
return(j);
}
Procedure to View the Result
4. Then read the data from that memory location. The read data will be displayed in the
terminal window.
RESULT:
The C-Language program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.
It is clocked by a 32.768 kHz external crystal, resonator or oscillator, the internal low power RC
oscillator or the high-speed external clock divided by 128. The internal low speed RC has A
typical frequency of 32 kHz. The RTC can be calibrated using an external 512 Hz output to
compensate for any natural quartz deviation.
Two alarm registers are used to generate an alarm at a specific time and calendar fields can be
independently masked for alarm comparison. To generate a periodic interrupt, a 16-bit
programmable binary auto-reload down counter with programmable resolution is available and
allows automatic wakeup and periodic alarms from every 120 µs to e very 36 hours
Serial Communication
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time. The
advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs
8). The disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8
wires. Serial ports lower cable costs and make cables smaller.
PROCEDURE
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile
and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.
PROGRAM:
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include "misc.h"
#include "stdio.h"
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();
int main(void)
{
USART2_config();
printf("\n welcome to RTC");
init_I2C1();
int gk_sec,gk_min,gk_hrr;
I2C_start(I2C1, SLAVE_ADDRESS1, I2C_Direction_Transmitter); // start a transmission
in Master transmitter mode
I2C_write(I2C1,0x00); //send RTC second address
I2C_write(I2C1,0x00); //send RTC second data
I2C_write(I2C1,0x00); //send RTC min data
I2C_write(I2C1,0x08); //send RTC hour data I2C_stop(I2C1);
Delay(500);
while(1)
{
void Delay(int t)
{
int y,u; for(y=0;y<t;y++)
for(u=0;u<t;u++);
}
return(r_value);
}
int BCD_to_DECIMAL(int bcd)
{
int gk_MSB,gk_LSB,decimal; gk_MSB =
(bcd&0xF0)>>4; gk_LSB = (bcd&0x0F);
decimal =(gk_MSB*10)+gk_LSB;
return(decimal);
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; RCC->APB1ENR |=
1 <<17; GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;//115200 baud rate
USART2->CR3 = 0x0000; USART2-
>CR2 = 0x000; USART2->CR1 =
0x200C;
return data;
}
void init_I2C1()
{
I2C_InitTypeDef I2C_InitStruct;
/* setup SCL and SDA pins
* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB9
*/
RCC->AHB1ENR |= 1<<1; //CLK to port B RCC-
>APB1ENR |= 1<<21; // CLK to I2C1
GPIOB->MODER = 0x00082000; //PB6 & PB9 =>i2c pins (SDA,SCL) GPIOB-
>AFR[0] = 0x04000000;
GPIOB->AFR[1] = 0x00000040;
GPIOB->OTYPER = 0xFFFFFFFF; //open drain GPIOB-
>OSPEEDR =0xAAAAAAAA; //50 MHZ GPIOB->PUPDR =
0x55555555; //pull up
// configure I2C1I2C_InitStruct.I2C_ClockSpeed = 100000; // 100kHz
I2C_GenerateSTART(I2Cx, ENABLE);
// wait for I2C1 EV5 --> Slave has acknowledged start condition while(!
I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
// Send slave Address for write
I2C_Send7bitAddress(I2Cx, address, direction);
I2C_AcknowledgeConfig(I2Cx, ENABLE);
// wait until one byte has been received
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
// read data from I2C data register and return data byte uint8_t
data = I2C_ReceiveData(I2Cx);
return data;
}
OUTPUT:
RESULT:
The C-Language program for reading RTC and displaying it in PC was written &
output is verified with running the RTC from a default/specified time .
EQUIPMENTS:
ESP 8266 module or Wi-Fi module
Connecting cables or USB cables Software
THEORY:
PROCEDURE:
1. STEP1: Start the process.
2. STEP2: Start Arduino IDE 1.8.8.
3. STEP3: Include the file directory ESP 8266 in Arduino.
4. STEP4: Then enter the coding to Wi-Fi module or ESP 8266 module.
5. STEP5: Then enter the coding in Arduino software.
6. STEP6: Connect the USB cable to the Wi-Fi module and the
7. Arduino connected system with available network.
8. STEP7: Select toolsSelect boardNode MCU 0.9C ESP-12 module
9. and then SelectPort.
10. STEP8: Upload the coding to ESP 8266 module and open serial
11. monitor to View the available network connects IP address.
12. STEP9: Stop the process.
PROGRAM CODING:
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "Error"; // The SSID (name) of the Wi-Fi network
you want to connect to
const char* password = "networkerror"; // The password of the WiFi network
void setup() {
Serial.begin(115200); // Start the Serial communication to send
messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.print(“...")
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to
connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
void loop() {
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266
to the computer
}
}
OUTPUT
RESULT:
Thus the output for connecting with the available Wi-Fi using Arduino has been successfully
AIM:
To control LED Using Arduino Uno board
EQUIPMENTS:
Universal Board
Arduino board Led
12V Adaptor
Power jack
USB Cable
HARDWARE PROCEDURE:
• LED pin is Connected to Arduino Uno pin of 2.
• Power jack is connected to the Arduino Uno.
• USB connector is connected to Arduino Uno to monitor.
• Connect the 12V power supply to development board.
• Check the output from the development board
SOFTWARE PROCEDURE:
Click on Arduino IDE
Click on file
Click on New
Write a Program as per circuit Pin connections
Click on Save
Click on Verify
Click on Upload the code into Arduino Uno by using USB cable
Program:
const int led = 2;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
Result:
Thus the control of LED Using Arduino Uno board is done.
Theory
Stepper Motor
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central
metal gear. To make the motor shaft turn, first one electromagnet is given power, which makes
the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are
thus aligned to the first electromagnet, they are slightly offset from the next electromagnet. So
when the next electromagnet is turned on and the first will turn off, the gear rotates slightly to
align with the next one and from there the process is repeated. Each of those slight rotations is
called a "step." In that way, the motor can be turned to a precised angle. There are two basic
arrangements for the electromagnetic coils: bipolar and unipolar.
PROCEDURE:
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of How to create a New Project to add the necessary file, compile and
build the program.
4. Follow the procedures in How to Download a Code to Our Controller to download your code
PROGRAM:
STEPPER MOTOR:
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
static int i=0;
/* private prototype functions*/
void anticlock_wise();
void clock_wise(); void
delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}
void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
GPIOB->OSPEEDR = 0xFFFFFFFF;
}
void main(void)
{
motor_PIN_config();
while(1)
{ anticlock_wise();
delay(); clock_wise();
delay();
}
}
void anticlock_wise()
{
for(i=0;i<56;i++)
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0x6000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0x5000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
}
}
void clock_wise()
{
for(i=0;i<56;i++)
{
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0x5000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0x6000;
delay(); delay(); delay();delay(); delay(); GPIOB-
>ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
}
}
TEMPERATURE SENSOR
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_adc.h"
IO uint32_t uhADCxConvertedValue = 0;
ADC_Config(ADC_Channel_1);
//ADC_Config(ADC_Channel_1); USART2_config();
ADC3->CR2 |=0x40000000;
while(1)
{
temp =uhADCxConvertedValue;
gk =temp*3.3; gk /=4095; gk *=100;
printf("\n Temperature = %3.2f°C",gk);
// printf("\n ADC3 channel_0 value = %d ",uhADCxConvertedValue);
}
}
void USART2_config()
{
RCC->AHB1ENR |= high << 0; RCC->APB1ENR |= high <<17;
RCC->APB2ENR |= (high<<10);
DMA2_Stream0 ->CR = (low<<6 |low<<7 |high<<8 | //p to m,circular
low<<9 |low<<10 |high<<11 |low<<12 |high<<13 |low<<14| //p-fixed,m-fixed,p-
16,m-16
p,m transfer
low<<16 |high<<17 |low<<21 |low<<22 |low<<23 |low<<24| //high priority,single low <<25 |high<<26 |
low<<27); //channel 2
DMA2_Stream0 ->FCR =(high <<0 |low <<1 |low<<2); //FIFO disable,1\2 fifo
DMA2_Stream0 ->NDTR =1; //buffer size
DMA2_Stream0 ->PAR = 0x4001224C; //p-base address
DMA2_Stream0 ->M0AR =(uint32_t)&uhADCxConvertedValue; //memory address
DMA2_Stream0 ->CR |= high <<0; //steam enable
ADC3->CR2 =(high <<0 |high <<1 |low <<11 | //ADC enable,continuous conv mode,right align
low <<24 |low<<25 |low<<26 |low<<27| //TI_cc1 external trigger
low<<28 |low <<29); //ext_conversion edge none
/* Enable DMA request after last transfer (Single-ADC mode) */ /* Enable ADC3 DMA */
}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
void lcd_sep_data(int a)
{
int d1,d2,d3,d4,d5,d6;
d1 = a/1000;
d2 = a%1000; d3
=d2/100; d4 =
d2%100; d5 = d4/10;
d6 = d4%10;
lcd_out(d1+0x30);
lcd_out(d3+0x30);
lcd_out(d5+0x30);
lcd_out(d6+0x30);
delay(1000);}
PROCEDURE TO VIEW THE RESULT
OUTPUT
STEPPER MOTOR
TEMPERATURE SENSOR
RESULT:
Thus the c program is written and executed by verifying the output using ARM
processor.
EQUIPMENTS:
Universal Board
Arduino board
POT sensor
IR Sensor
12V Adaptor
Power jack USB Cable
Jumper Wires
HARDWARE PROCEDURE:
LED pin is Connected to Arduino Uno pin of 11 & 12.
POT pin is connected to the Arduino pin A1.
IR Sensor Pin is connected to the Arduino Pin 4.
Power jack is connected to the Arduino.
USB connector is connected to Arduino Uno to monitor.
Connect the 12V power supply to development board.
Check the output from the development board.
SOFTWARE PROCEDURE:
Click on Arduino IDE
Click on file
Click on New
Write a Program as per circuit Pin connections
Click on Save
Click on Verify
Click on Upload the code into Arduino Uno by using USB cable.
Program:
#define LED_PIN 11
#define POTENTIOMETER_PIN A1
void setup() {
// put your setup code here, to run once:
pinMode(4,INPUT);
pinMode(12,OUTPUT);//LED
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:potentiometer loop
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int brightness = potentiometerValue / 4;
analogWrite(LED_PIN, brightness);
//ir loop
if(digitalRead(4)==LOW){
digitalWrite(12,HIGH);
}
else {
digitalWrite(12,LOW);
}
}
RESULT:
Infrared Sensor is successfully tested by Arduino microcontroller Board
AIM:
To Interface DHT11 Using Arduino Uno board and upload sensor data to Cloud.
EQUIPMENTS:
Universal Board
Arduino board
DHT11 sensor
WIFI Module
LCD
WIFI Module
12V Adaptor
Power jack
USB Cable
Jumper Wires
HARDWARE PROCEDURE:
LCD pins connected to Arduino Uno pin 2,3, 4, 5, 6, and 7.
DHT11 pin connected to the 10 pin of Arduino board.
Wifi module pins RX & TX are connected to 8 and 9 pin of Arduino ( RX = 8, TX = 9).
USB connector is connected to Arduino Uno to monitor.
Place Wifi Module in IOT development Board.
Connect the 12V power supply to development board.
Power jack is connected to the Arduino Uno.
Check the output from the development board.
SOFTWARE PROCEDURE:
Click on Arduino IDE
Click on file
Click on New
Write a Program as per circuit Pin connections
Click on Save
Create an Account in Things Speak, then create a channel.
Go to API keys in that Channel and then copy “Write API key”.
Go to Arduino code and paste Write API key.
Give your mobile hotspot name and password in Arduino code.
Click on save & Click on Verify.
Click on Upload the code into Arduino Uno by using USB cable.
After that open things Speak account and click on private view
DHT11 Sensor data will be uploaded and it will be shown as graph in Private view on
Things Speak account.
PROGRAM CODING:
#include <dht.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
LiquidCrystallcd(2,3, 4, 5, 6, 7);
SoftwareSerialwifi(8, 9); // TX, RX
String apiKey = "TRNIC1L9BXBXT322"; /// Write API Key
dhtDHT;
#define DHT11_PIN 10
const int buzzer = 13;
void setup(){
lcd.begin(16, 2);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, 0);
project_Name();
Serial.begin(9600);
Serial.println("AT");
delay(1000);
Serial.println("AT+CMGF=1");
delay(1000);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
lcd.setCursor(0,0);
lcd.print("WiFi module ");
lcd.setCursor(0,1);
lcd.print("Initilizing.... ");
wifi.begin(115200);
wifi.println("AT+RST");
delay(4000);
wifi.println("AT+CWMODE=3");
delay(4000);
wifi.print("AT+CWJAP=");
wifi.write('"');
wifi.print("STTMANI");
wifi.write('"');
wifi.write(',');
wifi.write('"');
wifi.print("hailucky123,./");
wifi.write('"');
wifi.println();
delay(1000);
lcd.setCursor(0,0);
lcd.print("WiFi module ");
lcd.setCursor(0,1);
lcd.print("Initilized..... ");
delay(1000);
lcd.clear();
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
//SendWiFi_Data();
//delay(1000);
lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.setCursor(12,0);
lcd.print(DHT.temperature);
lcd.setCursor(9,1);
lcd.print(DHT.humidity);
delay(500);
/* Tempurature Data Process*/
if(DHT.temperature> 45)
{
buzzer_sound();
}
/* Humidity Data Process*/
if(DHT.humidity< 30)
{
buzzer_sound();
}
lcd.setCursor(15,1);
lcd.write(0x20);
SendWiFi_Data();
delay(1000);
}
void SendWiFi_Data(){
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
wifi.println(cmd);
delay(1500);
String getStr ="GET /update?api_key=";
getStr += apiKey;
getStr +="&field1=";
getStr += String(DHT.temperature);
getStr +="&field2=";
getStr += String(DHT.humidity);
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
wifi.println(cmd);
delay(1500);
wifi.println(getStr);
delay(1000);
}
void buzzer_sound()
{
digitalWrite(buzzer, HIGH);
delay(600);
digitalWrite(buzzer, LOW);
delay(400);
digitalWrite(buzzer, HIGH);
delay(600);
digitalWrite(buzzer, LOW);
delay(400);
}
void project_Name(){
lcd.setCursor(0,0);
lcd.print(" ESP8266 ");
lcd.setCursor(0,1);
lcd.print(" Interfacing ");
delay(3000);
lcd.clear();
}
RESULT
DHT11 sense the surrounding temperature and measure humidity in surrounding air
that temperature and humidity shown by LCD display and Sensor data will be successfully
AIM:
To write a program to get temperature notification using Arduino.
EQUIPMENTS:
Temperature and humidity sensor.
2. Jumper wires
3. Connectivity cable or USB cable.
ALGORITHM:
STEP 1: Start the process.
STEP 2: Start Arduino 1.8.8
STEP 3: Include the DHT library to the Arduino software.
STEP 4: Then enter the coding in Arduino software.
STEP 5: Complete the coding in Arduino.
STEP 6: In Arduino board connect VCC to the power supply 5V and
connect SIG to digital signal DT and connect SND to ground GND
using jumper wires.
STEP 7: Connect the arduino board with USB cable to the system.
STEP 8: Select tools Selected.
STEP 9: Upload the coding to arduino board. Then the output will
be displayed in the serial monitor.
STEP 10: Stop the process.
BLOCK DIAGRAM:
PROGRAM CODING:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
delay(500);
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);
}
void loop()
{
DHT.read11(dht_apin);
Serial.print("THS:th01:None:");
Serial.print(DHT.humidity);
Serial.print("%,");
IoT Applications
Department of Information Technology 23
//Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("degC");
delay(2000);//Wait 5 seconds before accessing sensor again.
}
OUTPUT:
RESULT
Thus the output to get temperature notification using Arduino has successfully executed
AIM:
To develop a C-Language program for reading an on-chip ADC, convert into decimal and to
display it in PC and to generate a square wave depending on this ADC reading. The ADC
input is connected to any analog sensor/ on board potentiometer.
APPARATUS&SOFTWARE REQUIRED
PROCEDURE
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to download
your code.
PROGRAM:
ADC
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_adc.h"
int ConvertedValue = 0; //Converted value read from ADC1 void
adc_configure()
{
//Clock configuration
RCC->APB2ENR |= 1<<10; //The ADC3 is connected the APB2 peripheral bus thus we will use its
clock source
RCC->AHB1ENR |= 1<<0; //Clock for the ADC port!! Do not forget about this one ;)
//Analog pin configuration
GPIOA->MODER |=0x0000000F; //analog mode PA1,PA2
GPIOA->OSPEEDR = 0xFFFFFFFF;
GPIOA->PUPDR = 0x00000000;
/* ADC configuration */
USART2->CR1 = 0x200C;
}
int main(void)
{
USART2_config();
adc_configure();//Start configuration while(1)
{
ConvertedValue = adc_convert();//Read the ADC converted value printf("\n ADC
value => %d",ConvertedValue); //print the ADC value
}
}
int putchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
DAC
The two 12-bit buffered DAC channels can be used to convert two digital signals into
two analog voltage signal outputs.
This dual digital Interface supports the following features:
two DAC converters: one for each output channel
8-bit or 12-bit monotonic output
left or right data alignment in 12-bit mode
synchronized update capability
noise-wave generation
triangular-wave generation
dual DAC channel independent or simultaneous conversions
DMA capability for each channel
external triggers for conversion
input voltage reference VREF+
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through the
timer update outputs that are also connected to different DMA streams.
PROGRAM
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_syscfg.h"
#define sine_wave_gk
//#define triangular_wave_gk
//#define square_wave_gk
//#define sawtooth_wave_gk unsigned
int sine_wave[200]=
{2048,2112,2176,2240,2304,2368,2431,2494,2557,2619,2680,2741,2801,2860,2919,2977,3034,
3090,3144,3198,3251,3302,3352,3401,3449,3495,3540,3583,3625,3665,3704,3741,3776,3809,
3841,3871,3900,3926,3951,3973,3994,4013,4030,4045,4058,4069,4078,4085,4090,4093,4095,
4093,4090,4085,4078,4069,4058,4045,4030,4013,3994,3973,3951,3926,3900,3871,3841,3809,
3776,3741,3704,3665,3625,3583,3540,3495,3449,3401,3352,3302,3251,3198,3144,3090,3034,
2977,2919,2860,2801,2741,2680,2619,2557,2494,2431,2368,2304,2240,2176,2112,2048,1984,
1920,1856,1792,1728,1665,1602,1539,1477,1416,1355,1295,1236,1177,1119,1062,1006,952,898,
845,794,744,695,647,601,556,513,471,431,392,355,320,287,255,225,196,170,145,123,102,83,66,
51,38,27,18,11,6,3,1,3,6,11,18,27,38,51,66,83,102,123,145,170,196,225,255,287,320,355,392,431,
471,513,556,601,647,695,744,794,845,898,952,1006,1062,1119,1177,1236,1295,1355,1416,1477,
1539,1602,1665,1728,1792,1856,1920,1984};
int main(void)
{
static int i;
int j;
GPIO_InitTypeDef GPIO_InitStructure;
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
/* GPIOA clock enable (to be used with DAC) */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* DAC Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//TIM6_Config();
while (1)
{
j=0;
#if defined sine_wave_gk
for(i=0;i<200;i++)
{
DAC->DHR12R2 = sine_wave[i];
DAC_Cmd(DAC_Channel_2, ENABLE);
}
#elif defined triangular_wave_gk
for(i=0;i<=4095;i++)
{
DAC->DHR12R2 = i; DAC_Cmd(DAC_Channel_2,
ENABLE);
}
for(i=4095;i>=0;i--)
{
DAC->DHR12R2 = i; DAC_Cmd(DAC_Channel_2,
ENABLE);
}
OUTPUT
ADC:
RESULT:
Thus the C program is written and executed by verifying the output using ARM processor.
AIM:
To write a C program to generate a PWM and to vary the brightness of the LED depending on the
duty cycle.
4. CRO
THEORY
The PWM is based on the standard timer block and inherits all of its features.
The timer is designed to count cycles of the peripheral clock (PCLK) and optionally
generate interrupts or perform other actions when specified timer values occur, based
on seven match registers. The PWM function is also based on match register events
PROCEDURE
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
downloadyour code.
PROGRAM:
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_t PrescalerValue = 0;
{
USART2_config();
TIM3_Config();
while(1)
{
void TIM3_Config(void)
{
RCC->APB1ENR |=1<<1; RCC-
>AHB1ENR |=1<<2;
GPIOC->MODER |=0x0000A000;
GPIOC->AFR[0]|=0x22000000;
}
int switch_read()
{
int val;
mx_pinout_config();
val = ((GPIOE->IDR)&0x14);
if(val == 0x04)
{
if(duty_cycle <= 0)
{
duty_cycle =1;
}
duty_cycle--; //variable decrement
delay(250);
}
else if(val == 0x10)
{
duty_cycle++; //variable increment
delay(250);
if(duty >= 1500)
{
duty =1500;
}
}
return(duty_cycle);
}
void mx_pinout_config(void)
{
/*Enable or disable the AHB1 peripheral clock */ RCC-
>AHB1ENR |= 1<<3; // enable the clock to portD RCC-
>AHB1ENR |= 1<<4; //enable clock to portE
GPIOE->MODER |=0x00000000; //set portE as i/p mode,other pins are input moode
GPIOE->OTYPER =0x00000000; GPIOE-
>PUPDR = 0x00000000; GPIOE->OSPEEDR
=0xAAAAAAAA;
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to PORTA RCC-
>APB1ENR |= 1 <<17; //clock to USART2
GPIOA->MODER |= 0x000000A0; //AF mode GPIOA-
>AFR[0] |= 0x00007700; //USART2 AF USART2-
>BRR = 0x16D;//115200 baud rate USART2->CR3 =
0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
OUTPUT
RESULT:
The C program to vary the intensity of the LED depending on the duty cycle of the PWM
has
been Exp.
13 Interfacing Keypad and LCD
develo No.: ped
Da
and is
te:
verifie d.
AIM:
To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD module.
The display should come in the desired line and column.
LCD
Liquid crystals are a phase of matter whose order is intermediate between that of a
liquid and that of a crystal. The molecules are typically rod-shaped organic matters
about 25 Angstroms in length and their ordering is a function of temperature.
The molecular orientation can be controlled with applied electric fields.
A standard character LCD is probably the most widely used data Visualization
component. Character LCDs are available in various kinds of models.
1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4…
2. Color: Yellow, Green, Gray, Blue…
The Character LCD communicates with the microcontroller via 8 bit data bus.
The pin description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively;
V0 is used for controlling LCD contrast.
RS (Register Select) - If RS = 0, the instruction command code register is selected,
allowing the user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed
on the LCD.
RW (Read/Write) - RW allows the user to write information to the LCD or read
information from it. RW=1 when reading; RW=0 when writing.
EN (Enable) - The LCD to latch information presented to its data pins uses the
enable pin. When data is supplied to data pins, a high to low pulse must be applied
to this pin in order for the LCD to latch in the data present at the data pins.
D0 – D7 - The 8-bit data pins, are used to send information to the LCD or read the
contents of the LCD’s internal registers. To display letters and numbers,
we send ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while
making RS = 1
PROCEDURE
1) Write the c program for the given task and execute using IAR
2) Follow the steps 1 of How to create a New project
3) Type the below code and save it with the name (anyname.c)
4) Follow the steps 2 to 6 of How to create a New Project to add the necessary file,
compile and build the program
5) Follow the procedures in How to Download a Code to Our Controller to
download your code.
PROGRAM:
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
unsigned char d1[] = {" WELCOME "};
unsigned char d2[] = {" Press any Key"};
unsigned char i;
/*ptototype functions */
void delay(int a);
void mx_pinout_config(void);
void busy_check();
void command_write(int comm);
void lcd_init();
void lcd_out(unsigned char a);
void lcd_stringout(unsigned char *gk);
void mx_pinout_config(void);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check(); int val;
void main(void)
{
mx_pinout_config();
lcd_init(); //send initial commands
command_write(0x80); lcd_stringout(d1);
command_write(0xC0); lcd_stringout(d2);
while (1)
{
Row1_check();
Row2_check();
Row3_check();
Row4_check();
void Row1_check()
{
/*1 st row */
void Row2_check()
{
/*2nd row */
GPIOD->BSRRH = 0x0002; //low PD0
GPIOD->BSRRL = 0x000D; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7 if(val ==
0xE0) //1st column
{
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>8"); delay(100);
}
else if(val== 0xD0) //2nd column
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>9");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>A"); delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>B"); delay(100);
}
// GPIOD->BSRRH = 0x000E; //low PD0
}
void Row3_check()
{
/*3rd row */
GPIOD->BSRRH = 0x0004; //low PD0
GPIOD->BSRRL = 0x000B; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
command_write(0x80); lcd_stringout("You
Pressed =>5"); delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80); lcd_stringout("You
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>7"); delay(100);
}
}
void Row4_check()
{
/*4th row*/
GPIOD->BSRRH = 0x0008; //low PD0
GPIOD->BSRRL = 0x0007; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80); lcd_stringout("You
Pressed =>2"); delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
}
}
void delay(int a)
{
int i,j; for(i=0;i<a;i++)
for(j=0;j<a;j++);
void busy_check()
{
delay(200);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin
}
GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
int i;
busy_check();
}
}
void mx_pinout_config(void)
{
/*Enable or disable the AHB1 peripheral clock */ RCC-
>AHB1ENR |= 1<<3; // enable the clock to portF RCC-
>AHB1ENR |= 1<<4; //enable clock to portB,C,G
GPIOD->MODER |=0x00000055; //set port D0-D3 as o/p mode,other pins are input moode
GPIOD->OTYPER =0x00000000; GPIOD-
>PUPDR = 0x00000000; GPIOD->OSPEEDR
=0xAAAAAAAA;
/*Enable pin */
GPIOE->MODER = 0X55555555; // lcd_pins OUTPUT MODE SELECT GPIOE-
>OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->ODR = 0x00000000;
}
OUTPUT
RESULT:
The C-Language program for displaying the Key pressed in the Keyboard is displayed in the
LCD module and the output was verified on the LCD on the desires line and column/address.