Microcontroller
Microcontroller
Aim:
To study the 8051 microcontroller, its architecture, instruction set, and addressing
modes.
8051 Microcontroller:
The Intel 8051 is an 8-bit microcontroller that became the foundation for many
embedded systems due to its simplicity and versatility. Various manufacturers, including
Atmel, NXP, and Microchip, have developed their own versions of the 8051.
Key Features:
CPU: 8-bit processor
Memory:
Pin 21 (P2.0 / A8) Port 2, Pin 0. General-purpose I/O or address bit A8.
Pin 22 (P2.1 / A9) Port 2, Pin 1. General-purpose I/O or address bit A9.
Pin 23 (P2.2 / A10) Port 2, Pin 2. General-purpose I/O or address bit A10.
Pin 24 (P2.3 / A11) Port 2, Pin 3. General-purpose I/O or address bit A11.
Pin 25 (P2.4 / A12) Port 2, Pin 4. General-purpose I/O or address bit A12.
Pin 26 (P2.5 / A13) Port 2, Pin 5. General-purpose I/O or address bit A13.
Pin 27 (P2.6 / A14) Port 2, Pin 6. General-purpose I/O or address bit A14.
Pin 28 (P2.7 / A15) Port 2, Pin 7. General-purpose I/O or address bit A15.
Logic Operations
Mnemonic Explanation
ANL A, Rn AND register with Accumulator
ORL A, Rn OR register with Accumulator
XRL A, Rn XOR register with Accumulator
CLR A Clear Accumulator
CPL A Complement Accumulator
RL A Rotate left
RLC A Rotate left through carry
RR A Rotate right
RRC A Rotate right through carry
SWAP A Swap nibbles in Accumulator
Immediate Addressing
Operand is a constant value. Example: MOV A, #25H (Move 25H to A)
Register Addressing
Operand is a Register. Example: MOV A, R2 (Move content of R2 to A)
Direct Addressing
Operand is a direct memory address.Example: MOV A, 30H (Move content of
address 30H to A)
Register Indirect Addressing
Address of the operand is given in a Register. Example: MOV A, @R0
Indexed Based Addressing
Used for accessing lookup tables in ROM. Example: MOVC A, @A+DPTR
(Move data from ROM using A + DPTR as address).
Result:
Thus the 8051 microcontroller, its architecture, instruction set and addressing modes
were studied.
Ex No: 1b 8 BIT ADDITION USING 8051
Date:
MICROCONTROLLER
Aim:
To perform 8-bit Addition using the 8051 Microcontroller.
Algorithm:
1. Initialize the microcontroller and set up registers.
2. Load the first 8-bit number into the accumulator.
3. Load the second 8-bit number into a general-purpose register.
4. Perform the addition using the `ADD` instruction.
5. Store the sum result in a memory location.
6. End the program or repeat the process for a new set of numbers.
Flowchart:
Program:
ORG 0000H
MOV A, #25H
ADD A, R0
MOV 30H, A
JMP $
END
Output:
Result:
Thus the 8-bit Addition using 8051 Microcontroller was written, executed, and the output was
verified successfully
Ex No:1c 16-BIT ADDITION USING
Date: 8051 MICROCONTROLLER
Aim:
To perform 16-bit addition using the 8051 microcontroller.
Algorithm:
Flowchart:
Program:
ORG 0000H
MOV A, R0 ADD
A, R2 MOV 30H,
A JNC
NO_CARRY INC
R1
NO_CARRY:
MOV A, R1 ADD
A, R3
MO V 31H, A
JMP $
END
Output:
Result:
Thus the 16-bit addition using 8051 microcontroller was written, executed and output
was verified successfully.
Ex No: 1d 16 BIT SUBTRACTION USING 8051
Date: MICROCONTROLLER
Aim:
To perform 16-bit subtraction of two numbers using 8051 microcontroller.
Algorithm:
Flowchart:
START
SUBB A, LSB2
STORE RESULT IN R7
SUBB A, MSB2
STORE RESULT IN R1
STOP
Program:
ORG 00H
CLR A
CLR C
MOV A, #62H
SUBB A, #96H
MOV R7, A
MOV A, #27H
SUBB A, #12H
MOV R1, A
END
Output:
Result:
Thus the 16 bit Subtraction using 8051 microcontroller was written, executed and the output was
verified successfully.
Ex No:1e 16 BIT MULTIPLICATION USING 8051
Date: MICROCONTROLLER
Aim:
To perform multiplication of two 16-bit numbers and store the 32-bit result in memory.
Algorithm:
Start
Stop
Program:
ORG 00H
MOV R2, A
INC R0
MOV R3, A
INC R0
MOV R4, A
INC R0
MOV R5, A
MOV A, R2
MOV B, R4
MUL AB
MOV A, R3
MOV B, R4
MUL AB
MOV R6, A
MOV R7, B
MOV A, R2
MOV B, R5
MUL AB
ADD A, R6
MOV R6, A
ADDC B, R7
MOV R7, B
MOV A, 41H
ADD A, R6
MOV 42H, A
MOV A, R7
ADDC A, #00H
MOV 43H, A
MOV A, R3
MOV B, R5
MUL AB
MOV 44H, A
MOV 45H, B
Output:
Result:
Then the 16-bit multiplication was executed successfully.
Ex No:1f 16 BIT DIVISION USING 8051
Date: MICROCONTROLLER
Aim:
To divide a 16-bit number by an 8-bit number and store the 16-bit quotient and 8-bit
remainder.
Algorithm:
Flowchart:
Start
Divide New 16 bit Number by Divisor → Final Quotient Low & Remainder
Stop
Program:
ORG 00H
MOV A, @R0
MOV R2, A
INC R0
MOV A, @R0
MOV R3, A
INC R0
MOV A, @R0
MOV R4, A
MOV A, R3
MOV B, R4
DIV AB
MOV R5, A
MOV R6, B
MOV A, R6
MOV B, #0FFH
MUL AB
MOV R7, A
MOV A, R2
MOV B, R4
DIV AB
SJMP $
Output :
Result:
Thus, the 16-bit division was written, executed, and output was verified successfully.
Ex No: 1g LOGICAL OPERATIONS USING 8051
Date: MICROCONTROLLER
Aim:
AND Operation
Algorithm:
Flowchart:
start
Load A
Result in A
stop
Program:
ORG 00H
MOV A, #55H
ANL A, #0F0H
MOV R0, A
HLT
Output :
OR Operation
Algorithm:
Flowchart:
start
Load A
OR A with 0F0H
Result in A
stop
Program:
ORG 00H
MOV A, #55H
ORL A,
#0F0H MOV
R1, A HLT
Output:
XOR Operation
Algorithm:
Load A,B
xOR A,B
Result in A
stop
Program:
ORG 00H
MOV A, #55H
XRL A,
#0F0H MOV
R3, A HLT
Output:
NOT Operation
Algorithm:
Flowchart:
start
Load A
CPL A
Result in A
stop
Program:
ORG 00H
MOV A,
#55H CPL A
MOV R3, A
HLT
Output:
XNOR Operation
Algorithm:
Flowchart:
start
Load A,B
XOR A,B
CPL A
Result in A
stop
Program:
ORG 00H
MOV A, #55H
XRL A,
#0F0H CPL A
MOV R4, A
HLT
Output:
Result:
Thus, the logical operations using 8051 microcontroller were written, executed, and
output was verified successfully.
Ex No: 2 DATA TRANSFER BETWEEN REGISTERS AND
Date: MEMORY
Aim:
To perform data transfer between registers and memory using 8051 micro controller.
Algorithm:
Flowchart:
Program:
ORG 000H
MOV R2,#05H
MOV R0,#40H
MOV R1,#50H
LOOP:
MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ
R2,LOOP END
Output:
Result:
Thus, the data transfer between registers and memory using 8051 microcontroller was
written, executed and the output was verified successfully.
ALU OPERATIONS
Ex No:3a GREATEST NUMBER USING COMPARISON
Date: OPERATION
Aim:
To find the greatest of two numbers using comparison operator in 8051 micro-controller
Algorithm:
Program:
INPUT OUTPUT
Result:
Thus the program for greater number using 8051 microcontroller was written , executed
and the output was verified successfully
Ex No :3b SMALLEST NUMBER USING COMPARISON
Date: OPERATION
Aim:
To find the smallest of two numbers using comparison operation in 8051 micro-controller.
Algorithm:
Program:
Output:
INPUT OUTPUT
Result:
Thus the program for smallest number using 8051 microcontroller was written,executed and output
was verified successfully
Ex No: 3c
RIGHT SHIFT USING SHIFT OPERATION
Date:
Aim:
To perform right shift operation on a number using 8051 micro-controller.
Algorithm:
1. Load the number into AX.
2. Perform right shift operation using SHR.
3. Store the result in memory.
4. Halt the program.
Program:
INPUT OUTPUT
Result:
Thus the program for right shift operation using 8051 microcontroller was written, executed
successfully.
Ex No:3d
LEFT SHIFT USING SHIFT OPERATION
Date:
Aim:
Algorithm:
Program:
0004H into AX
Program
Output:
INPUT OUTPUT
Result:
Thus the program for left shift using 8051 microcontroller was executed
successfully.
Ex No : 4
ARITHMETIC PROGRAMS USING EMBEDDED C
Date:
Aim:
Algorithm:
#include<reg51.h>
X=0x12;
Y=0x34;
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00;
Z=x+y;
P0=z;
A=y-x;
P1=a;
B=x*y;
P2=b;
C=y/x;
P3=c;
While(1);
}
Output:
Result:
Thus the arithmetic programs using Embedded C was written, executed and output was
verified successfully.
Ex No: 5
INTRODUCTION TO ARDUINO PLATFORM
Date:
Aim:
To study the basics of the Arduino platform including its hardware, software, working,
applications, and types.
Introduction:
Arduino is an open-source electronics platform based on easy-to-use hardware and software.
It was initially developed at the Interaction Design Institute Ivrea (IDII) in Ivrea, Italy, with the
goal of providing affordable tools for non-engineers to create interactive digital projects. Over
time, Arduino has grown into a global community of hobbyists, students, and professionals
working on innovative projects in embedded systems and IoT.
Working Of Arduino:
Arduino boards are programmed using the Arduino IDE. Once a program (sketch) is
uploaded, the microcontroller on the Arduino board executes the instructions continuously. It
interacts with sensors, actuators, and other electronic components through its input and output
pins. The Arduino platform allows real-world signals to be read (analog/digital) and responses to
be generated accordingly, making it highly suitable for embedded systems and IoT applications.
Application Of Arduino:
Arduino boards have become a key tool in modern electronics due to their versatility and
ease of use. They are widely applied across various fields, enabling automation, control, and smart
system development.
The Arduino Mega 2560 is designed for advanced and complex projects that require a large
number of input/output pins and greater memory capacity. It is ideal for projects like 3D printers,
robotics, and data-intensive applications.
Features:
54 digital I/O pins – For reading sensors, controlling LEDs, motors, etc.
16 analog inputs – For reading analog sensors like temperature or potentiometers.
256 KB flash memory – For storing larger programs and data.
2. Arduino Nano
Features:
3. Arduino Due
The Arduino Due is the first Arduino board that features a 32-bit ARM Cortex-M3 core
microcontroller. It offers improved performance and higher clock speeds, making it ideal for
applications that require fast computation or processing.
Features:
4. Arduino UNO
The Arduino UNO is the most widely used board, perfect for beginners. It's known for its
ease of use and wide community support.
Features:
Microcontroller: ATmega328P
Operating Voltage: 5V
Digital I/O Pins: 14 (6 with PWM capability)
Analog Input Pins: 6
Clock Speed: 16 MHz
a) Power Pins:
b) Analog Pins:
A0 to A5 – Used for reading analog inputs (0–5V). Commonly used with sensors like
temperature, light, or potentiometers.
c) Digital Pins:
D3, D5, D6, D9, D10, D11 – These pins support Pulse Width Modulation (PWM), which
allows analog-like output using digital signals. Useful for dimming LEDs or controlling
motor speeds.
e) ICSP Header:
In-Circuit Serial Programming (ICSP) – A set of pins used for programming the
microcontroller directly using SPI protocol. Helpful when bootloader reprogramming is
needed.
f) ATmega328 (Microcontroller):
The heart of the Arduino UNO board, this chip handles all processing tasks. It executes
code uploaded via the Arduino IDE and controls all I/O operations.
Not part of the Arduino UNO board itself, but often referred to in Arduino projects using
1602 LCD displays. It’s a common alphanumeric display interface that connects to the
UNO for showing data.
h) USB-B Port:
Used to connect the Arduino UNO to a computer. It serves both as a power source and
communication channel for uploading code and monitoring output through the serial
monitor.
i) Voltage Regulator:
Ensures a stable supply voltage (5V or 3.3V) to the microcontroller and connected
components, regardless of input fluctuations.
Pin Diagram:
Arduino Board:
Result:
The study of the Arduino platform provided knowledge about its origin, hardware
components, software environment (IDE), working mechanism, applications, and various types of
boards. Understanding Arduino lays the foundation for embedded systems and IoT projects.
Ex No: 5b
Date: LED BLINK
Aim:
Algorithm:
1. Start
2. Initialize the led pin
3. Turn on the led x wait for a second
4. Turn off led x wait for a second
5. Stop
Program:
void setup() {
pinMode(ledPin, OUTPUT);
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
Output:
Result:
Thus, the program to make the led blink using Arduino was developed successfully.
Ex No: 5c
Date: LIGHT SENSOR
Aim:
To write a program to detect light using light sensor and Arduino.
Algorithm:
1. Start.
2. Initialize the digital pin.
3. Read the analog value to the sensor.
4. Display the amount of brightness based on the analog value.
5. Stop.
Program:
void setup()
{
Serial.begin(9600);
}
Void loop()
{
Int analogvalue = analogread(a0);
Serial.print("analog reading = ");
Serial.print(analogvalue);
If (analogvalue < 100)
{
Serial.println(" - very bright");
}
Else if (analogvalue < 200)
{
Serial.println(" - bright");
}
Else if (analogvalue < 500)
{
Serial.println(" - light");
}
Else if (analogvalue < 800)
{
Serial.println(" - dim");
}
Else
{
Serial.println(" - dark");
}
Delay(500);
}
Output:
Result:
Thus the program detect light using LDR sensor and arduino was developed successfully.
Ex No:5d TEMPERATURE SENSOR
Date:
Aim:
To write a program to detect temperature using temperature sensor and
Arduino.
Algorithm:
Step 1: Start.
Step 6: Stop.
Program:
int val;
int tempPin = 2;
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(tempPin);
Serial.print("Temperature = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
Output:
Result:
Thus the program to detect temperature using temperature sensor and Arduino
Aim:
Algorithm:
Step 1: Start
Step 2: Initialize variables: led = 9, brightness = 0, fadeamount = 5
Step 3: Set up pin 9 as output to control the led brightness.
Step 4: Enter the loop routine.
Step 5: Set the brightness of pin 9 using analogwrite(led, brightness).
Step 6: Increment the brightness by fadeamount.
Step 7: Check if brightness is at its minimum (0) or maximum (255).
Step 8: If so, reverse the direction of fading by changing the sign of fadeamount
Step 9: Wait for 30 milliseconds to observe the dimming effect using delay(30).
Program:
Int led = 9;
brightness = 0;
Int fadeamount = 5;
void setup()
pinmode(led, output);
}
void loop() {
analogwrite(led, brightness);
Fadeamount = -fadeamount;
delay(30);
Output:
Result:
Thus, the program to make the led blink using Arduino was developed successfully.
Ex No :6 EXPLORE DIFFERENT COMMUNICATION
Date: METHODS WITH IOT DEVICES (GSM, BLUETOOTH)
Aim :
To explore different communication methods with IoT devices using GSM and
Bluetooth.
1. Bluetooth
Algorithm :
6. On button press, send command :P, print name, and control LED.
Program:
#include <SoftwareSerial.h>
#define led 3
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
delay(1000);
pinMode(bt_RX, INPUT);
pinMode(bt_TX, OUTPUT);
pinMode(bt_Vin, OUTPUT);
pinMode(button_Vin, OUTPUT);
pinMode(button_Vout, INPUT_PULLUP);
delay(100);
digitalWrite(bt_Vin, HIGH);
delay(500);
if(BTSerial.available())
if (BTSerial.available()) Serial.write((char)BTSerial.read());
Serial.println("");
void loop() {
if(digitalRead(button_Vout) == 0) { //press
Serial.println("AT");
BTSerial.write(":P\n");
Serial.println("Noman 12084");
digitalWrite(led, LOW);
delay(100);
digitalWrite(led,HIGH);
msg_to_bt = "";
while(Serial.available()){
dByte = Serial.read();
Serial.print((char)dByte);
msg_from_bt = "";
while(BTSerial.available()){
dByte = BTSerial.read();
Serial.print((char)dByte);
atm = "";
delay(100);
atm += msg_from_bt[0];
atm += msg_from_bt[1];
atm += msg_from_bt[2];
if (msg_from_bt != "") {
if (atm == "AT+") {
Serial.print(".");
delay(1000);
BTSerial.read();
digitalWrite(bt_Vin, HIGH);
delay(1000);
Output :
2. GSM :
Algorithm :
1. Start
8. Stop
Program :
void setup() {
Serial.begin(9600);
sim800L.begin(9600);
neo6m.begin(9600);
}
void loop() { }
Output :
Result :
Thus, the exploration of communication between different IoT devices using Bluetooth and
GSM was verified Successfully.
Aim :
To study and understand the features, architecture, and programming capabilities of the
Raspberry Pi Pico W microcontroller platform.
Features:
Raspberry Pi Pico W:
The Raspberry Pi Pico W is based on the RP2040 microcontroller, which was designed by
Raspberry Pi in-house. It combines a powerful ARM Cortex-M0+ processor with built-in Wi-Fi
connectivity, opening up a range of possibilities for IoT projects, remote monitoring, and
wireless communication. The Pico W retains the same form factor as the original Pico, making it
compatible with existing Pico accessories and add-ons.
RP2040 Microcontroller:
At the core of the Raspberry Pi Pico W is the RP2040 microcontroller. It features a dual-core
ARM Cortex-M0+ processor running at 133MHz, providing ample processing power for a wide
range of applications. The microcontroller also includes 264KB of SRAM, which is essential for
storing and manipulating data during runtime. Additionally, the RP2040 incorporates 2MB of
onboard flash memory for program storage, ensuring sufficient space for your code and
firmware.
Wireless Connectivity:
The standout feature of the Raspberry Pi Pico W is its built-in wireless connectivity. It
includes an onboard Cypress CYW43455 Wi-Fi chip, which supports dual-band (2.4GHz and
5GHz) Wi- Fi 802.11b/g/n/ac. This allows the Pico W to seamlessly connect to wireless
networks, communicate with other devices, and access online services. The wireless capability
opens up new avenues for IoT projects, remote monitoring and control, and real-time data
exchange.
Similar to the Raspberry Pi Pico, the Pico W offers a generous number of GPIO pins,
providing flexibility for interfacing with external components and peripherals. It features 26
GPIO pins, of which 3 are analog inputs, and supports various protocols such as UART, SPI, I2C,
and PWM. The Pico W also includes onboard LED indicators and a micro-USB port for power
and data connectivity.
One of the unique features of the RP2040 microcontroller is the inclusion of Programmable
Input/Output (PIO) state machines. These state machines provide additional processing power
and flexibility for handling real-time data and timing-critical applications. The PIO state
machines can be programmed to interface with custom protocols, generate precise waveforms,
and offload tasks from the main processor, enhancing the overall performance of the system.
As with all Raspberry Pi products, the Pico W benefits from the vibrant and supportive
Raspberry Pi community. Raspberry Pi provides extensive documentation, including datasheets,
pinout diagrams, and programming guides, to assist developers in understanding the board's
capabilities. The community offers forums, online tutorials, and project repositories, allowing
users to seek help, share knowledge, and collaborate on innovative projects.
Result:
Thus, the study of the Raspberry Pi Pico W microcontroller platform was completed, and the
key features, wireless capabilities, GPIO options, and programming methods were successfully
understood.
Aim :
To Write a program for blink an LED connected to a microcontroller using Python
programming with the machine and utime modules.
Algorithm :
1. Start
2. Import the pin class from the machine module and the sleep function from the utime
module.
3. Initialise a new pin object named led with pin number 11 and set it as an output pin.
4.2 : Pause the execution for 0.5 seconds using the sleep function to create a
blinking effect.
5. Stop
Program:
from machine import pin
While true:
Led.toggle()
Sleep(0.5)
Output:
Result :
Thus, the LED blinking program was written, executed, and the LED successfully blinked as
expected.
Aim :
To write a program for control an LED using a push button connected to a microcontroller by
writing a Python program with machine and time modules.
Algorithm :
1. Start
2. Initialize LED connected to pin 15 and set it as an output.
3. Initialise the push button connected to pin 16 and set it as an input.
Program:
Result :
Thus, the push button and LED control program was written, executed, and the LED
responded to the button press successfully.
Aim :
To Write a program for blink multiple LEDs connected to GPIO pins of a microcontroller
simultaneously using Python programming with machine and time modules.
Algorithm :
1. Start
2. Import the Pin class from the machine module and the sleep function
from the time module.
3. Define four LED objects (LED1, LED2, LED3, LED4) each connected to GPIO
pins 6, 7, 8, and 9 respectively, all set as output pins.
4. Turn all LEDs on simultaneously.
5. Wait for 1 second.
6. Turn all LEDs off simultaneously.
7. Wait for 1 second.
8. Stop.
Program:
Output:
Result :
Thus, the program for blinking multiple LEDs was written, executed, and the LEDs blinked
simultaneously as intended.
Ex No:8
Date: INTERFACING SENSORS WITH RASPBERRY PI PICO
Aim:
To interface an ultrasonic sensor (HC-SR04) with a Raspberry Pi Pico and measure the
distance of an object using MicroPython.
Algorithm :
4. Record the time when echo pin goes HIGH and then LOW.
Program:
Import utime
Print(“Hello, P1 Pico!”)
Def ultra():
Trigger.low()
Utime.sleep_us(2)
Trigger.high()
Utime.sleep_us(5)
Trigger.low()
While echo.value() == 0:
Signaloff = utime.ticks_us()
While echo.value() == 1:
Signalon = utime.ticks_us()
While True:
Ultra()
Utime.sleep(1)
Output:
Result:
The program successfully interfaces the ultrasonic sensor with the Raspberry Pi Pico and
continuously measures the distance from an object. The output is displayed in centimeters on the
serial monitor.
Ex No: 9 COMMUNICATE BETWEEN ARDUINO AND
RASPBERRY PI USING ANY WIRELESS
Date:
MEDIUM
Aim:
To enable communication between Arduino and Raspberry Pi using any wireless medium
Introduction:
Raspberry Pi Pico:
Arduino:
The HC-05 is a widely used Bluetooth module that enables wireless communication between
electronic devices. It operates over the Serial Port Profile (SPP) and can be configured to act as
either a master or slave device. The HC-05 module is commonly used in hobbyist projects for
establishing Bluetooth connections between microcontrollers, computers, smartphones, and other
devices.
Algorithm:
Hardware Connections:
6. Verify Pairing:
Program:
}
}
}
1. Upload the Arduino code to your Arduino board using the Arduino IDE.
2. Copy the MicroPython code to your Raspberry Pi Pico and run it using a text
editor like Thonny or a similar MicroPython IDE.
Testing:
Hardware/Software Requirements:
S. No Software Quantity
1 Blynk Cloud 1
Cloud Platform:
Blynk:
Blynk is a smart platform that allows users to create their Internet of Things applications without the
need for coding or electronics knowledge. It is based on the idea of physical programming & provides
a platform to create and control devices where users can connect physical devices to the Internet and
Procedure:
Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign in using
Step 4: Now we need to add a ‘New Device’ now. Select a New Device from ‘Template’.
Step 5: Select the device from a template that you created earlier and also give any name to the
device. Click on Create.A new device will be created. You will find the Blynk Authentication
title to it and Create Datastream as Virtual Pin Configure the switch settings as per the image
Result:
Thus the setup of a cloud platform to log the data from IOT devices was created and implemented
successfully.
AIM :
To test the log data using raspberry pi and upload to the cloud platform.
PROCEDURE:
PROGRAM:
import machine
import utime
import
urequests
import network
# Constants
API_KEY = "ZSX5SRTSRJ61XVU6"
THINGSPEAK_URL = "https://api.thingspeak.com/update?api_key={}".format(API_KEY)
WIFI_SSID = "@ms.Balaji"
WIFI_PASSWORD = "@msbalaji"
wlan = network.WLAN(network.STA_IF)
def connect_to_wifi():
wlan.active(True)
if not wlan.isconnected():
print("Connecting to WiFi...")
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
retry = 0
utime.sleep(1)
retry += 1
if wlan.isconnected():
print("Connected to WiFi")
else:
def read_ir_sensor():
return ir_sensor.value()
def send_to_thingspeak(data):
try:
response = urequests.get(url)
response.close()
except Exception as e:
# Main loop
connect_to_wifi()
while True:
ir_data = read_ir_sensor()
print("IR Sensor Data:", ir_data)
send_to_thingspeak(ir_data)
OUTPUT:
RESULT:
Thus, to test the log data using raspberry pi and upload to the cloud platform is done
successfully and the output has been verified.
Ex no:12
DESIGN AN IOT BASED SYSTEM
Date:
Aim:
To design an IOT-driven system that autonomously modulates LED luminance based on real- time
ambient light intensity measurements acquired through a Light Dependent Resistor (LDR)
Algorithm:
Program:
void setup() {
OUTPUT);
void loop() {
int ldr = analogRead(A0); // Read the value from LDR (Light Dependent Resistor)
int bri = map(ldr, 0, 1023, 0, 255); // Map the LDR value to brightness range (0 -255)
Output:
Result:
Thus, the experiment to design an IOT-based system that automatically adjusts LED
brightness according to ambient light intensity sensed by an LDR (Light Dependent Resistor) has
been successfully written, executed, and the output has been verified.