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

Lords ES&IoT Lab

It contains embedded system and internet of things programs
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 views64 pages

Lords ES&IoT Lab

It contains embedded system and internet of things programs
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/ 64

U21IT7L1 EMBEDDED SYSTEMS AND IOT

SYLLABUS

COURSE OBJECTIVES:

To learn the internal architecture and programming of an embedded processor.


To introduce interfacing, I/O devices to the processor.
To introduce the evolution of the Internet of Things (IoT).
To build a small low-cost embedded IoT system using Arduino/Raspberry Pi/open platform.
To apply the concept of the Internet of Things in real-world scenario.

LIST OF EXPERIMENTS

1. Program to perform basic arithmetic operations (Add,Sub,Mul,Div) using Embedded C.


2. Program to interface 8-bit LED and switch interface
3. To write a Embedded C program to demonstrate Seven Segment using 8051
Microcontroller development kit
4. Program to implement interface of
a. Buzzer b. stepper motor.
5. Introduction to Arduino programming
6. Explore different communication methods with Aurdino
a. Bluetooth b. GSM. c. Zigbee
7. Introduction to Raspberry PI platform and installation of python programming
8. Interfacing sensors with Raspberry PI
9. Communicate between Arduino and Raspberry PI using any wireless medium (Bluetooth)
10. Setup a cloud platform to log the data
11. Log Data using Raspberry PI and upload to the cloud platform
12. Home Automation design an IOT based system

OUTCOMES:

CO1: Explain the architecture of embedded processors.


CO2: Write embedded C programs.
CO3: Design simple embedded applications.
CO4: Compare the communication models in IOT
CO5: Design IoT applications using Arduino/Raspberry Pi /open platform.
U21IT7L1 EMBEDDED SYSTEMS AND IOT

List of 8051 Simulators:


The list of simulators is given below with their features:
MCU 8051: MCU 8051 is an 8051 simulator that is very simple to use and has an interactive
IDE (Integrated Development Environment). It is developed by Martin Osmera and most
important of all is that it is completely free. There are many features for this IDE they are
It supports both C and assembly language for compilation and simulation
It has an in-built source code editor, graphical notepad, ASCII charts, Assembly symbol
viewer, etc. It also supports several 8051 ICs like at89c51, A89S52, 8051, 8052, etc.
It will support certain electronic simulations like LED, 7segment display, LCD etc. whichwill
help in giving the output when you interface these things to the hardware directly.
It has tools like hex decimal editors, base converters, special calculator, file converters,
inbuilt hardware programmers, etc.
It has syntax validation, pop base auto-completion etc.
You can download this tool from https://sourceforge.net/projects/mcu8051ide/files/.

EDSIM 51: This is a virtual 8051 interfaced with virtual peripherals like 7 segment display,
motor, keypad, UART etc. This simulator is exclusively for students developed by James
Rogers,. The features of this simulator are
Have virtual peripherals like ADC, DAC with scope to display, comparator etc.
Supports only assembly language
IDE is completely written in JAVA and supports all the OS.
Completely free and with user guide, examples, etc.
You can download this simulator from the https://www.edsim51.com/index.html.

8051 IDE: This simulation software is exclusively for the Windows operating system (98/xp).
The features of this simulator are
Text editor, assembler, and software simulate in one single program.
Has facilities like Breakpoint setter, execute to break point, predefined simulator watch
window, etc.
It is available in both free version and paid version.
You can download this tool from https://www.acebus.com/win8051.htm

KEIL µVision: KEIL is the most popular software simulator. It has many features like
interactive IDE and supports both C and assembly languages for compilation and simulation.

You can download and get more information from https://www.keil.com/c51/.


INSTALLATION OF KEIL SOFTWARE

Set up Keil IDE for Programming


Keil µVision IDE is a popular way to program MCUs containing the 8051 architectures. It
supports over 50 microcontrollers and has good debugging tools including logic analyzers and
watch windows.
In this article, we will use the AT89C51ED2 microcontroller, which has:
64 KB FLASH ROM
On-chip EEPROM
256 Bytes RAM
In-System programming for uploading the program

2 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


U21IT7L1 EMBEDDED SYSTEMS AND IOT

3 Timer/counters
SPI, UART, PWM

The Keil µVision icon.


To start writing a new program, you need to create a new project. Navigate to project —> New
µVision project. Then save the new project in a folder.
After saving the file, a new window will pop up asking you to select your microcontroller.

As discussed, we are using AT89C51/AT89C51ED2/AT89C52, so select this controller under


the Microchip section (as Atmel is now a part of Microchip).

3 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


U21IT7L1 EMBEDDED SYSTEMS AND IOT

Select ‘Yes’ in the next pop-up, as we do not need this file in our project.

Our project workspace is now ready!

From here, we need to create a file where we can write our C code. Navigate to File —>
New.Once the file is created, save it with .c extension in the same project folder.

4 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


U21IT7L1 EMBEDDED SYSTEMS AND IOT

Next, we have to add that .c or .asm file to our project workspace. Select Add Existing
Files andthen select the created .c or .asm file to get it added.

The workspace and project file are ready.

5 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


U21IT7L1 EMBEDDED SYSTEMS AND IOT

PROCEDURE

1. Create a new project, go to “Project” and close the current project “Close Project”.
2.Next Go to the Project New μVision Project and Create New Project Select Device for
Target.
Select the device AT89C51ED2 or AT89C51 or AT89C52
Add Startup file Next go to “File” and click “New”.
Write a program on the editor window and save it with .asm extension.
Add this source file to Group and click on “Build Target” or F7.
Go to debugging mode to see the result of simulation by clicking Run or step run.8.

6 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


U21IT7L1 EMBEDDED SYSTEMS AND IOT

EXP NO:1 PROGRAM TO PERFORM ARITHMETIC OPERATIONS USING


EMBEDDED C
DATE

AIM: To write an embedded C program for addition, subtraction, multiplication, and division
using the Keil simulator.
SOFTWARE REQUIRED:

S.No Software Requirements Quantity


1 Keil μvision5 IDE 1

PROCEDURE
1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project and Create New Project Select Device
forTarget.
3. Select the device AT89C51ED2 or AT89C51 or AT89C52
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with the .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.
PROGRAM:
#include<REG51.H>
unsigned char a, b;
void main()
{
a=110;
b=204;
P0=a-b;
P1=a+b;
P2=a*b;
P3=a/b;
while(1);
}
OUTPUT:
Port P0=
Port P1=
Port P2=
Port P3=

RESULT:

7 | Prepared by Dr.N.Raj Kumar/IT www.lords.ac.in


EXP NO:2 PROGRAM TO INTERFACE 8-BIT LED AND SWITCH
INTERFACE
DATE

AIM:
To write an embedded C program to interface 8-bit LED and switch interface.

SOFTWARE REQUIRED:

S.No Software Requirements Quantity


1 Keil μvision5 IDE 1
2 LED or Proteus software for simulation 1

PROCEDURE

1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project and Create New Project Select Device for
Target.
3. Select the device LED or Proteus software for simulation
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with the .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.

PROGRAM FOR EXAMPLE OF LED:


#include<REGX51.H>#define LED P2
Void delay (unsigned int d); int main(void)
{
while(1)
{
LED=0x55;
delay(1000); LED=0xAA;
delay (1000);
}
}
Void delay(unsigned int d)
{
unsigned int i,j; for(i=0; i<d; i++) for(j=0;j>101;j++);
}
PROGRAMTOSHOW L-R&R-L SHIFTING:
#include<REGX51.H>#define LED P2
void delay(unsigned intd); int main(void)
{
unsigned int i;
8
while (1)
{
LED=0X01;
for(i=0;i<7;i++)
{
delay(1000); LED=LED<<=0X01;
}
LED=0X80;
for(i=0;i<=7;i++)
{

}}}
delay(100; LED=LED>>=0X01;
void delay(unsigned int d)
{
unsigned i,j; for(i=0;i<d;i++) for(j=0;j<101;j++);
}

OUT PUT:

RESULT:

9
EXP NO:3 PROGRAM TO IMPLEMENT SEVEN SEGMENT DISPLAY
DATE

AIM: Program to implement seven segment display

Three Seven segment display are connected to port0 and the common anode pins of each
seven segment are connected to port 3.3, 3.4 and 3.5 respectively. And the same port0 is
connected to LCD as well, so to avoid the conflict we have provided the slide switch to select
the appropriate display.

General Description:

A seven segment display, as its name indicates, is composed of seven elements.


Individually on or off, they can be combined to produce simplified representations of the Hindu
_Arabic numerals. Often the seven segments are arranged in an oblique, or italic, arrangement,
which aids readability. Each of the numbers 0, 1, 2 and 9 may be represented by two or more
different glyphs on seven-segment displays. LED-based 7-segment display showing the 16 hex
P0.7P0.2P0.1P0.0

digits

The seven segments are arranged as a rectangle of two vertical segments on each side
with one horizontal segment on the top and bottom. Additionally, the seventh segment bisects
P0.7P0.2P0.1P0.0

the rectangle horizontally. There are also fourteen –segment displays and sixteen segment
displays (for full alphanumeric); however, these have mostly been replaced by dot-matrix
displays. The segments of a 7-segment display are referred to by the letters A to G, as shown to
the right, where the optional DP (decimal point an "eighth segment") is used for the display of
non-integer numbers.

It is an image sequence of a "LED" display, which is described technology-wise in the


following section. Notice the variation between uppercase and lowercase letters for A–F; this is
done to obtain a unique, unambiguous shape for each letter.

10
ALGORITHM:
STEP1:ConfiguretheHardwareconnectionsof7-SEGMENTdevices
STEP2: Load the data on the port0 and enable 7-Seg1.
STEP3:Loadthedataontheport0andenable7-Seg2.
STEP4:Loadthedataontheport0andenable7-Seg3.
STEP5: End

11
PROGRAM TO INTERFACE 7 SEGMENT DISPLAY:

#include<REGX51.H>
#define SEG1 {P3_3=0;P3_4=0;P3_5=1;}
#define SEG2 {P3_3=0;P3_4=1;P3_5=0;}
#define SEG3 {P3_3=1;P3_4=0;P3_5=0;}
#defineNULL{P3_3=0;P3_4=0;P3_5=0;}

codeunsignedcharseg[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int main(void)
{
unsignedchari,j,k,m;
nunsigned int l;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
for(k=0;k<10;k++)
{
for(l=0;l<1000;l++)
{
NULL
P0=seg[i];
SEG1
for(m=0;m<50;m++);

NULL
P0=seg[j];
SEG2
for(m=0;m<50;m++);

NULL
P0=seg[k];
SEG3
for(m=0;m<50;m++);
}
}}}
}

12
FLOWCHART:

START

Configureconnectionsfor7-
Segmentdisplays.

Loaddatatocorresponding
Port0 Enable segment1

Loaddatatocorresponding
Port0 Enable segment2

Loaddatatocorresponding
Port0 Enable segment3

STOP

Output

Result

Conclusion:

TheCprogramtodemonstrateLEDSEVENSEGMENTDISPLAYwasexecutedsuccessfully using
8051 Microcontroller development kit.

13
EXP NO:4 a PROGRAM TO IMPLEMENT BUZZER INTERFACE ON IDE
ENVIRONMENT
DATE

AIM:
To write an embedded C program program to interface a. Buzzer b. Stepper Motor

SOFTWARE REQUIRED:

S.No Software Requirements Quantity


1 Keil μvision5 IDE 1
2 Buzzer or Proteus Software 1

PROCEDURE

1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project and Create New Project Select Device for
Target.
3. Select the device buzzer. Or open proteus software for simulation
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with the .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.

PROGRAM FOR EXAMPLE OF BUZZER

Aim: To write a program for demonstrating Relays Buzzer using 8051development kit.
Program Description RELAY
We demonstrate glowing of 2 relays one after the other .A relay is a device that
respondstoasmallcurrentorvoltagechangebyactivatingswitchesorotherdevicesinan electric circuit.
Used for alarming systems.
Ports on MP:

7654 32 10

↓ ↓ ↓
Stepper-Motor Buzzer Relay Relay 1:
Prev=Prev|(1<<0) (forglowing),Prev=Prev&~(1<<0) (for clearing)
Relay2:
Prev=Prev |(1<<1) (forglowing),Prev=Prev&~(1<<1) (forclearing)
Algorithm
Assign LED address for Microcontroller kit

14
While true
Set the first relay to 1 which indicates that it is“ON”
Delay for certain time.
Set the relay to 0which is “OFF”
Delay for certain time.
Settherealy2to„1‟
Delay for certain time.
Settherelay2 to„0‟
Delay for certain time.
Program Description Buzzer
We demonstrate buzzing of two Buzzers. A Buzzer an electrical device that makes a buzzing
noise and is used for signaling .Ports on MP:

7654 32 10

↓ ↓ ↓
Stepper-Motor Buzzer Relay
For 1st Buzzer:
Set Buzzer: Prev=Prev |(1<<2) Reset Buzzer: Prev=Prev&~(1<<2)
For 2nd Buzzer:
Set Buzzer: Prev=Prev |(1<<3) Reset Buzzer: Prev=Prev&~(1<<3)

Algorithm
Assign LED address for Microcontroller kit.
While true.
Set the first buzzerto1whichindicatesthat itis“ON”.
Delay for certain time.
Set the buzzer to0 which is “OFF”
Delay for certain time.
Set thebuzzer2 to „1‟
Delay for certain time.
Set thebuzzer2 to „0‟
Delay for certain time.

PROGRAM TO INTERFACE RELAYAND BUZZER:


#include<REGX51.H>
#define RELAY1 P2_4
#define RELAY2 P2_5
#define RELAY3 P2_6
#define BUZZER P2_7 void delay (unsigned int d); int main(void)
{
P2=0x00;
while(1)
{
RELAY1=1;
delay(1000); RELAY1=0;
delay(1000); RELAY2=1;

15
delay(1000); RELAY2=0;
delay(1000);RELAY3=1;
delay(1000); RELAY3=0;
delay(1000); BUZZER=1;
delay(1000); BUZZER=0;
delay(1000);
}
}

Void delay(unsigned int d)


{
unsigned int i,j; for(i=0;i<d;i++) for(j=0;j<101;j++);
}

OUTPUT

RESULT:

16
EXP NO:4b PROGRAM TO IMPLEMENT STEPPER MOTOR INTERFACE ON IDE
ENVIRONMENT
DATE

AIM:
To write an embedded C program program to interface Stepper Motor

SOFTWARE REQUIRED:

S.No Software Requirements Quantity


1 Keil μvision5 IDE 1
2 Stepper motor or Proteus Software 1

PROCEDURE

1. Create a new project, go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project and Create New Project Select Device for
Target.
3. Select the device buzzer. Or open proteus software for simulation
4. Add Startup file Next go to “File” and click “New”.
5. Write a program on the editor window and save it with the .asm extension.
6. Add this source file to Group and click on “Build Target” or F7.
7. Go to debugging mode to see the result of the simulation by clicking Run or Step run.

PROGRAM FOR EXAMPLE OF STEPPAR MOTOR


Program Definition
To write a program to demonstrate Stepper Motor using 8051 development kit.
Basics of Stepper Motor
Of all motors, step motor is the easiest to control. Direction information is very simple and
comes down to "left" for logical one on that pin and "right "for logical zero. Motor control is also
very simple - every impulse makes the motor operating for one step and if there is no impulse the
motor won't start. Pause between impulses can be shorter or longer and it defines
revolutionrate.Thisratecannotbeinfinitebecausethemotorwon'tbeableto"catchup"withall the
impulses.

The key to driving a stepper is realizing how the motor is constructed. A diagram shows the
representation of a 4 coil motor, so named because 4 coils are used to cause the revolution of the
drive shaft. Each coil must be energized in the correct order for the motor to spin.

The control signals to open and close the switches at the appropriate times in order to spin the
motors. The control unit is commonly a computer or programmable interface controller, with
software directly generating the outputs needed to control the switches.

17
Step angle: It is angle through which motor shaft rotates in one step. step angle is different for
different motor . Selection of motor according to step angle depends on the application, simply if
your equire small increments in rotation choose motor having smaller step angle.
Noofstepsrequiretorotateonecompleterotation=360deg./stepangleindeg. Steps/second
TherelationbetweenRPMandstepspersec.isgivenby,stepsorimpulses/sec.=(RPMX Steps
/revolution) /60

InterfacingTo8051

Coil A Coil B Coil C Coil D Step


0 1 1 0 1
0 0 1 1 2
1 0 0 1 3
1 1 0 0 4

To cause the stepper to rotate, we have to send a pulse to each coil in turn. The 8051 does not
have sufficient drive capability on its output to drive each coil, so there are a number of ways to
drive a stepper, Stepper motors are usually controlled by transistor or driver IC like ULN2003.
Driving current for each coil is then needed about 60mA at +5V supply. A Darlington transistor
array, ULN2003 is used to increase driving capacity of the 8051 chip. Four 4.7k resistors help
the 8051 to provide more sourcing current from the +5V supply.
Controlling Stepper Motor With Two Port Pins Only

D0 D0 Coil energized
0 0 AB
0 1 BC
1 0 CD
1 1 DA
Program Description
Demonstrate “Stepper Motor “rotating in clockwise and anticlockwise direction. A stepper motor
or stepper motor or stepping motor is a brushless DC electric motor that divide sa full rotation
into a number of equal steps.
We consider 10H-16
20H-32
40H-64
80H-128
STPPER MOTOR ALGORITHM

STEP1: Configure the hardware connections of STEPPER Motor.


STEP2:ConnecttheSTEPPERMotortoJ4connectorof8051SDKkit.

18
STEP3:TorunStepperMotorinFARWORDDirectionsend0x01,0x02,0x04,0x08 sequence of data
one at a time to the STEPPER MOTOR ADDRESS
STEP4:TorunStepperMotorinREVERSEDirectionsend0x08,0x04, 0x02,0x01 Sequence of data
one at a time to the STEPPER MOTOR ADRRESS
STEP5:End

PROGRAM FOR STEPPER MOTOR


#include<REGX51.H>
void delay (unsigned intd); int main(void)
{
while(1)
{
P2=0x01;
delay(1000); P2=0x02;
delay(1000); P2=0x04;
delay(1000); P2=0x08;
delay(1000);
}
}

voiddelay(unsignedintd)
{
unsigned int i,j; for(i=0;i<d;i++) for(j=0;j<101;j++);
}

Program Validation
Input :
Stepper(10,1),Here count=10anddirection=1.
Stepper(10,0),Here count=10anddirection=0.
Output:

19
Whencount=10anddirection=1whichmeansthesteppermotorrotatesfor10countsin clockwise
direction with a delay after each count.
Herecount=10anddirection=0whichmeanssteppermotorrotatesfor10countsin anticlockwise
direction with a delay after each count.
Conclusion:
The program to demonstrate Stepper Motor using 8051Microcontroller developmentkit executed
successfully.

OUTPUT:

RESULT:

20
EXP NO:5 INTRODUCTION TO ARDUINO PROGRAMMING
DATE

AIM:
To write and execute different Arduino programming for analog, digital signals and serial
communication.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Arduino IDE 2.0 1
2 Arduino UNO Development Board 1
3 Jumper Wires Few
4 Arduino USB Cable 1

5 Joystick Module 1

PROCEDURE:

CONNECTION:

Arduino UNO Pin Arduino Development Board


2 LED

PROGRAM:

DIGITAL WRITE:
void setup() { pinMode(2, OUTPUT);
}
void loop() { digitalWrite(2, HIGH);delay(1000); digitalWrite(2, LOW);delay(1000);
}
CONNECTION:

Arduino UNO Pin Arduino Development Board


2 LED
5 S1 (SW 1)

21
DIGITAL READ:
void setup() { pinMode(2, OUTPUT);
pinMode(5, INPUT_PULLUP);
}
void loop() {
int sw=digitalRead(5);if(sw==1)
{
for(int i=0; i<5; i++)
{
digitalWrite(2, HIGH);delay(1000); digitalWrite(2, LOW); delay(1000);
}
}
else
{
digitalWrite(2, LOW);
}
}

CONNECTION:

Arduino UNO Pin Arduino Development Board Joystick Module


2 LED
VCC or 5V +5V
GND GND
A0 VRx or VRy

ANALOG READ:
void setup() { pinMode(2, OUTPUT);Serial.begin(9600);
}
void loop() {
int joystick=analogRead(A0);Serial.println(joystick);

if(joystick>800) digitalWrite(2, HIGH); else


digitalWrite(2, LOW);

delay(500);
}

22
CONNECTION:

Arduino UNO Pin Arduino Development Board


3 LED

PWM Pins: 3, 5, 6, 9, 10, 11

23
ANALOG WRITE:
void setup() { pinMode(3, OUTPUT);
}
void loop() {
for(int i=0; i<256;i++) {analogWrite(3,i); delay(20);
}
for(int i=255; i>=0;i--) {analogWrite(3,i); delay(20);
}
}

24
CONNECTION:

Arduino UNO Pin Arduino Development Board


4 LED
SERIAL COMMUNICATION:
void setup() {
Serial.begin(9600); pinMode(4, OUTPUT);
}

void loop() { if(Serial.available()>0)


{
char data=Serial.read();Serial.println(data); if(data=='1'){
digitalWrite(4,HIGH);
}
else if(data=='2'){ digitalWrite(4,LOW);
}
}
}

RESULT:

OUTPUT:

25
EXP NO:6 Different communication methods with IoT devices(Zigbee, GSM,
Bluetooth)
DATE

AIM:
To explore different communication methods with IoT devices (Zigbee, GSM, Bluetooth).

DIFFERENT COMMUNICATION METHODS:


IoT devices require reliable and efficient communication methods to transmit data and
interact withother devices or systems. Here are three commonly used communication
methods for IoT devices:

Zigbee:
Zigbee is a low-power wireless communication protocol designed for short-range
communication between devices. It operates on the 2.4 GHz frequency band and supports
mesh networking, allowing devices to communicate with each other through intermediate
nodes. Zigbee is commonly used in home automation, industrial control, and smart energy
applications.

GSM (Global System for Mobile Communications):


GSM is a widely used cellular network technology that enables IoT devices to connect to the
internet using SIM cards. It operates on various frequency bands and provides wide coverage,
makingit suitable for applications that require long-range communication. GSM is commonly
used in applications such as asset tracking, remote monitoring, and smart cities.

Bluetooth:
Bluetooth is a short-range wireless communication technology that operates on the 2.4 GHz
frequency band. It is commonly used for connecting IoT devices to smartphones, tablets, and
other nearby devices. Bluetooth Low Energy (BLE) is a power-efficient version of Bluetooth
that is idealfor battery-powered IoT devices. Bluetooth is widely used in applications such as
wearable devices, healthcare monitoring, and home automation.

Each communication method has its advantages and limitations, and the choice depends on
the specific requirements of the IoT application. Factors to consider include range, power
consumption, data rate, security, and interoperability with other devices or systems.

RESULT:

26
EXP NO:7. a BLUETOOTH COMMUNICATION
DATE

AIM:
To write a program to control an LED using a Bluetooth module.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Arduino IDE 2.0 1
2 Arduino UNO Development Board 1
3 Jumper Wires Few
4 Arduino USB Cable 1

5 HC-05 Bluetooth Module 1

PROCEDURE:

CONNECTIONS:

Arduino UNO Pin Bluetooth Module Arduino Development Board


VCC 5V -
GND GND -
2 Tx -
3 Rx -
4 - LED

PROGRAM:
#include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); //rx,tx void setup() {
mySerial.begin(9600); Serial.begin(9600);
pinMode(4, OUTPUT);
}

void loop() { if(mySerial.available()>0)


{
char data=mySerial.read();Serial.println(data); if(data=='1'){ digitalWrite(4,HIGH);
Serial.println("LED ON");
}
else if(data=='2'){ digitalWrite(4,LOW); Serial.println("LED OFF");
27
}
}}
EXP NO:7.b ZIGBEE COMMUNICATION
DATE:

AIM:
To write a program to control an LED using a Zigbee module.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Arduino IDE 2.0 1
2 Arduino UNO Development Board 2
3 Jumper Wires Few
4 Arduino USB Cable 2

5 Zigbee Module 2

PROCEDURE:

CONNECTIONS:

TRANSMITTER:

Arduino UNO Pin Zigbee Module


VCC 5V
GND G
2 Tx
3 Rx

PROGRAM:
TRANSMITTER SIDE:

#include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); //rx,tx void setup() {


mySerial.begin(9600);Serial.begin(9600);
}
void loop() {
mySerial.write('A');Serial.println('A'); delay(100); mySerial.write('B');Serial.println('B');
delay(100);
}

28
CONNECTIONS:

RECEIVER:
Arduino UNO Pin Zigbee Module Arduino Development Board
- 5V 5V
- G GND
2 Tx -
3 Rx -
4 - LED1

RECEIVER SIDE:
#include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); //rx,tx void setup() {
mySerial.begin(9600); Serial.begin(9600); pinMode(4, OUTPUT);
}

void loop() { if(mySerial.available()>0)


{
char data=mySerial.read();Serial.println(data); if(data=='A') digitalWrite(4,HIGH); else
if(data=='B') digitalWrite(4,LOW);
}
}

RESULT:

29
EXP NO:8 INTRODUCTION TO THE RASPBERRY PI PLATFORM
DATE

Introduction to Raspberry Pi Pico W:

The Raspberry Pi Pico W is a compact and affordable microcontroller board developed by the
Raspberry Pi Foundation. Building upon the success of the Raspberry Pi Pico, the Pico W
variant brings wireless connectivity to the table, making it an even more versatile platform
for embedded projects. In this article, we will provide a comprehensive overview of the
Raspberry Pi Pico W, highlighting its key features and capabilities.
Features:
RP2040 microcontroller with 2MB of flash memory
On-board single-band 2.4GHz wireless interfaces (802.11n)
Micro USB B port for power and data (and for reprogramming the flash)
40 pins 21mmx51mm ‘DIP’ style 1mm thick PCB with 0.1″ through-hole pins also with edge
castellations
Exposes 26 multi-function 3.3V general purpose I/O (GPIO)
23 GPIO are digital-only, with three also being ADC-capable
Can be surface mounted as a module
3-pin ARM serial wire debug (SWD) port
Simple yet highly flexible power supply architecture
Various options for easily powering the unit from micro-USB, external supplies, or batteries
High quality, low cost, high availability
Comprehensive SDK, software examples, and documentation
Dual-core Cortex M0+ at up to 133MHz
On-chip PLL allows variable core frequency
264kByte multi-bank high-performance SRAM

Raspberry Pi Pico W:
The Raspberry Pi Pico W is based on the RP2040 microcontroller, which was designed by
RaspberryPi 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 Picoaccessories and add-ons.

30
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 andmanipulating 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 IoTprojects, remote monitoring and control, and real-time data
exchange.

GPIO and Peripherals:


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.

MicroPython and C/C++ Programming:


The Raspberry Pi Pico W can be programmed using MicroPython, a beginner-friendly
programminglanguage that allows for rapid prototyping and development. MicroPython
provides a simplified syntax and high-level abstractions, making it easy for newcomers to
get started. Additionally, the

31
Pico W is compatible with C/C++ programming, allowing experienced developers to leverage
the rich ecosystem of libraries and frameworks available.

Programmable Input/Output (PIO) State Machines:


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.

Open-Source and Community Support


As with all Raspberry Pi products, the Pico W benefits from the vibrant and supportive
Raspberry Picommunity. 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, shareknowledge, and collaborate on innovative
projects.

32
The Raspberry Pi Pico W brings wireless connectivity to the popular Raspberry Pi Pico
microcontroller board. With its powerful RP2040 microcontroller, built-in Wi-Fi chip,
extensive GPIO capabilities, and compatibility with MicroPython and C/C++ programming,
the Pico W offers a versatile and affordable platform for a wide range of embedded projects.
Whether you are a beginner or an experienced developer, the Raspberry Pi Pico W provides a
user-friendly and flexibleplatform to bring your ideas to life and explore the exciting world of
wireless IoT applications.

RESULT:

33
EXP NO: INTRODUCTION TO PYTHON PROGRAMMING
DATE

Getting Started with Thonny MicroPython (Python) IDE:


If you want to program your ESP32 and ESP8266 with MicroPython firmware, it’s very
handy to use an IDE. you’ll have your first LED blinking using MicroPython and Thonny
IDE.

What is MicroPython?
MicroPython is a Python 3 programming language re-implementation targeted for
microcontrollers and embedded systems. MicroPython is very similar to regular Python. Apart
from a few exceptions,the language features of Python are also available in MicroPython. The
most significant difference between Python and MicroPython is that MicroPython was
designed to work under constrained conditions.
Because of that, MicroPython does not come with the entire pack of standard libraries. It only
includes a small subset of the Python standard libraries, but it includes modules to easily
control andinteract with the GPIOs, use Wi-Fi, and other communication protocols.

34
Thonny IDE:
Thonny is an open-source IDE which is used to write and upload MicroPython programs to
differentdevelopment boards such as Raspberry Pi Pico, ESP32, and ESP8266. It is extremely
interactive andeasy to learn IDE as much as it is known as the beginner-friendly IDE for new
programmers. With the help of Thonny, it becomes very easy to code in Micropython as it
has a built-in debugger that helps to find any error in the program by debugging the script
line by line.
You can realize the popularity of Thonny IDE from this that it comes pre-installed in Raspian
OS which is an operating system for a Raspberry Pi. It is available to install on r Windows,
Linux, andMac OS.

A) Installing Thonny IDE – Windows PC


Thonny IDE comes installed by default on Raspbian OS that is used with the Raspberry Pi
board.To install Thonny on your Windows PC, follow the next instructions:
Go to https://thonny.org
Download the version for Windows and wait a few seconds while it downloads.

3. Run the .exe file.

35
Follow the installation wizard to complete the installation process. You just need to click

“Next”.

After completing the installation, open Thonny IDE. A window as shown in the following 36
figureshould open.
37
38
CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico Development


Board
GP16 LED

39
PROGRAM

LED:
from machine import Pinimport time
LED = Pin(16, Pin.OUT)
while True: LED.value(1)time.sleep(1) LED.value(0)time.sleep(1)

40
CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico Development


Board(RGB)

GP16 R
GP17 G
GP18 B
GND COM

41
RGB:
from machine import Pin
from time import sleep_ms,sleep r=Pin(16,Pin.OUT) y=Pin(17,Pin.OUT) g=Pin(18,Pin.OUT)

while True: r.value(1) sleep_ms(1000)r.value(0) sleep_ms(1000)y.value(1) sleep(1)


y.value(0) sleep(1) g.value(1) sleep(1) g.value(0) sleep(1)

42
CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico Development


Board
GP16 LED
GP15 SW1

SWITCH CONTROLLED LED:


from machine import Pinfrom time import sleep led=Pin(16,Pin.OUT) sw=Pin(15,Pin.IN)
while True: bt=sw.value()if bt== True:
print("LED ON") led.value(1) sleep(2) led.value (0) sleep(2) led.value (1) sleep(2)
led.value(0) sleep(2)
else:
print("LED OFF") sleep(0.5)

RESULT:

43
EXP NO: INTERFACING SENSORS WITH RASPBERRY PI
DATE

AIM:
To interface the IR sensor and Ultrasonic sensor with Raspberry Pico.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Jumper Wires few
4 Micro USB Cable 1

5 IR Sensor 1

6 Ultrasonic sensor 1

PROCEDURE:

CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico IR Sensor Module


Development Board
GP16 BUZZER -
GP15 - OUT
- 5V VCC
- GND GND

PROGRAM:

IR Sensor:
from machine import Pinfrom time import sleep buzzer=Pin(16,Pin.OUT) ir=Pin(15,Pin.IN)
while True: ir_value=ir.value()if ir_value== True:
print("Buzzer OFF")buzzer.value(0)
else:
print("Buzzer ON") buzzer.value (1)
sleep(0.5)
44
CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico Ultrasonic Sensor Module


Development Board
GP16 BUZZER -
GP15 - ECHO
GP14 - TRIG
- 5V VCC
- GND GND

ULTRASONIC SENSOR:
from machine import Pin, PWM import utime
trigger = Pin(14, Pin.OUT) echo = Pin(15, Pin.IN) buzzer = Pin(16, Pin.OUT)

def measure_distance():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()

timepassed = signalon - signaloff distance = (timepassed * 0.0343) / 2 return distance

while True:
dist = measure_distance() print(f"Distance : {dist} cm") if dist <= 10:
buzzer.value(1) utime.sleep(0.01)
else:
buzzer.value(0) utime.sleep(0.01)
utime.sleep(0.5)

RESULT:

45
CS3691 EMBEDDED SYSTEMS AND IOT

EXP NO: COMMUNICATE BETWEEN ARDUINO ANDRASPBERRY PI


DATE

AIM:
To write and execute the program to Communicate between Arduino and Raspberry PI
using any wireless medium (Bluetooth)

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Thonny IDE 1
2 Raspberry Pi Pico Development Board 1
3 Arduino Uno Development Board 1
4 Jumper Wires few
5 Micro USB Cable 1
6 Bluetooth Module 2

PROCEDURE:

CONNECTIONS:

Arduino UNO Pin Arduino Development Board Bluetooth Module


2 - Tx
3 - Rx
- GND GND
- 5V 5V
PROGRAM:

MASTER ARDUINO:
#include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); //rx,tx void setup() {
mySerial.begin(9600);
}

void loop() {
mySerial.write('A');delay(1000); mySerial.write('B');delay(1000);
}

46 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico Bluetooth Module


Development Board
GP16 LED -
VCC - +5V
GND - GND
GP1 - Tx
GP0 - Rx

SLAVE
RASPBERRY PI PICO
from machine import Pin, UARTuart = UART(0, 9600)
led = Pin(16, Pin.OUT)

while True:
if uart.any() > 0:
data = uart.read()print(data)
if "A" in data: led.value(1) print('LED on \n') uart.write('LED on \n')
elif "B" in data: led.value(0) print('LED off \n') uart.write('LED off \n')

RESULT:

47 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

EXP NO: CLOUD PLATFORM TO LOG THE DATA


DATE

AIM:
To set up a cloud platform to log the data from IoT devices.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No. Software Requirements Quantity


1 Blynk Platform 1

CLOUD PLATFORM-BLYNK:

Blynk is a smart platform that allows users to create their Internet of Things applications
without theneed for coding or electronics knowledge. It is based on the idea of physical
programming & providesa platform to create and control devices where users can connect
physical devices to the Internet andcontrol them using a mobile app.

Setting up Blynk 2.0 Application


To control the LED using Blynk and Raspberry Pi Pico W, you need to create a Blynk project
and set up a dashboard in the mobile or web application. Here’s how you can set up the
dashboard:

Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can
simply signin using the registered Email ID.

Step 2: Click on +New Template.

48 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Step 3: Give any name to the Template such as Raspberry Pi Pico W. Select ‘Hardware
Type’ asOther and ‘Connection Type’ as WiFi.

So a template will be created now.

49 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Step 4: Now we need to add a ‘New Device’ now.

Select a New Device from ‘Template’.

50 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Select the device from a template that you created earlier and also give any name to the device.
Clickon Create.

A new device will be created. You will find the Blynk Authentication Token Here. Copy it
as it isnecessary for the code.

51 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Step 5: Now go to the dashboard and select ‘Web Dashboard’.

From the widget box drag a switch and place it on the dashboard screen.

52 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Step 6:

On the switch board click on Settings and here you need to set up the Switch. Give any title to
it andCreate Datastream as Virtual Pin.

Configure the switch settings as per the image below and click on create.

53 | Prepared by Dr. N.Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Configure the final steps again.

With this Blynk dashboard set up, you can now proceed to program the Raspberry Pi Pico W
boardto control the LED.

Step 7:
54 | Prepared by Mr. S. BALABAKSER, ASP/ECE
www.stannescet.ac.in
CS3691 EMBEDDED SYSTEMS AND IOT

To control the LED with a mobile App or Mobile Dashboard, you also need to setup the
Mobile Phone Dashboard. The process is similarly explained above.

Install the Blynk app on your smartphone The Blynk app is available for iOS and Android.
Downloadand install the app on your smartphone. then need to set up both the Mobile App
and the Mobile Dashboard in order to control the LED with a mobile device. The process is
explained above.

Open Google Play Store App on an android phone


Open Blynk.App
Log In to your account (using the same email and password)
Switch to Developer Mode
Find the “Raspberry Pi Pico Pico W” template we created on the web and tap on it
Tap on the “Raspberry Pi Pico Pico W” template (this template automatically comes
because we created it on our dashboard).
tap on plus icon on the left-right side of the window
Add one button Switch
Now We Successfully Created an android template
it will work similarly to a web dashboard template.

RESULT:

55. Prepared by Dr.N. Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

EXP NO: Log Data using Raspberry PI and upload it to the cloudplatform
DATE

AIM:
To write and execute the program Log Data using Raspberry PI and upload it to the cloud
platform

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Thonny IDE 1
2 Raspberry Pi Pico Development Board few
3 Jumper Wires 1

4 Micro USB Cable 1

PROCEDURE:

CONNECTIONS:

Raspberry Pi PicoPin Raspberry Pi Pico LCD Module


Development Board
- 5V VCC
- GND GND
GP0 - SDA
GP1 - SCL

PROGRAM:
from machine import Pin, I2C, ADC from utime import sleep_ms
from pico_i2c_lcd import I2cLcd import time
import network import BlynkLib

adc = machine.ADC(4)
i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) I2C_ADDR=i2c.scan()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)

wlan = network.WLAN() wlan.active(True)


wlan.connect("Wifi_Username","Wifi_Password") BLYNK_AUTH = 'Your_Token'
# connect the network wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:break

56. Prepared by Dr.N. Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

wait -= 1
print('waiting for connection...') time.sleep(1)

# Handle connection errorif wlan.status() != 3:


raise RuntimeError('network connection failed')else:
print('connected') ip=wlan.ifconfig()[0]print('IP: ', ip)

"Connection to Blynk" # Initialize Blynk


blynk = BlynkLib.Blynk(BLYNK_AUTH)

lcd.clear()

57. Prepared by Dr.N. Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

while True:
ADC_voltage = adc.read_u16() * (3.3 / (65536)) temperature_celcius = 27 - (ADC_voltage -
0.706)/0.001721temp_fahrenheit=32+(1.8*temperature_celcius) print("Temperature in C:
{}".format(temperature_celcius)) print("Temperature in F: {}".format(temp_fahrenheit))

lcd.move_to(0,0) lcd.putstr("Temp:")
lcd.putstr(str(round(temperature_celcius,2))) lcd.putstr("C ")
lcd.move_to(0,1) lcd.putstr("Temp:")
lcd.putstr(str(round(temp_fahrenheit,2))) lcd.putstr("F")
time.sleep(5)

blynk.virtual_write(3, temperature_celcius) blynk.virtual_write(4, temp_fahrenheit)


blynk.log_event(temperature_celcius)

blynk.run() time.sleep(5)

RESULT:

58. Prepared by Dr.N. Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

EXP NO:12 Implementation of Home Automation system an IOT-based system


using WiFi Module.
DATE

AIM:
To design a Smart Home Automation IOT-based system

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 Thonny IDE 1
2 Raspberry Pi Pico Development Board few
3 Jumper Wires 1

4 Micro USB Cable 1

5 LED or Relay 1

PROCEDURE:

CONNECTIONS:

59. Prepared by Dr.N. Raj Kumar/IT LORDS


CS3691 EMBEDDED SYSTEMS AND IOT

Raspberry Pi PicoPin Raspberry Pi Pico Development


Board
GP16 LED 1

PROGRAM:

import time import network import BlynkLib


from machine import Pinled=Pin(16, Pin.OUT)

wlan = network.WLAN() wlan.active(True)


wlan.connect("Wifi_Username","Wifi_Password") BLYNK_AUTH = 'Your_Token'

# connect the network wait = 10


while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:break
wait -= 1
print('waiting for connection...') time.sleep(1)

# Handle connection error if wlan.status() != 3:


raise RuntimeError('network connection failed')else:
print('connected') ip=wlan.ifconfig()[0]print('IP: ', ip)

"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

# Register virtual pin handler @blynk.on("V0") #virtual pin V0


def v0_write_handler(value): #read the value if int(value[0]) == 1:
led.value(1)
#turn the led on else:
led.value(0)
#turn the led offwhile True:
blynk.run()

RESULT:

60. Prepared by Dr.N. Raj Kumar/IT LORDS


EXTRA PROGRAMS

LCD DISPLAY:

from machine import Pin, I2C from time import sleep


from pico_i2c_lcd import I2cLcd
i2c=I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) I2C_ADDR=i2c.scan()[0]
lcd=I2cLcd(i2c,I2C_ADDR,2,16)

while True: lcd.move_to(3,0) lcd.putstr("Ediylabs") sleep(5)


lcd.clear()

Raspberry Pi Pico 16X2 LCD Display


Development Board
5V VCC
GND GND
GP0 SDA
GP1 SCL
DHT 11 Sensor:

from machine import Pin, I2C import utime as time


from dht import DHT11, InvalidChecksum while True:
time.sleep(1)
pin = Pin(16, Pin.OUT, Pin.PULL_DOWN) sensor = DHT11(pin)
t = (sensor.temperature) h = (sensor.humidity)
print("Temperature: {}".format(sensor.temperature)) print("Humidity:
{}".format(sensor.humidity)) time.sleep(2)

Connection

Raspberry Pi Pico DHT11


Development Board
5V VCC
GND GND
GP16 DATA
SERVO MOTOR:

from time import sleep


from machine import Pin, PWM

pwm = PWM(Pin(1)) pwm.freq(50)

while True:
for position in range(1000,9000,50): pwm.duty_u16(position) sleep(0.01)
for position in range(9000,1000,-50): pwm.duty_u16(position) sleep(0.01)

Connection

Raspberry Pi Pico SERVOMOTOR


Development Board
GND BROWM
5V RED
GP1 ORANGE
STEPPER MOTOR:
from machine import Pin from time import sleep

IN1 = Pin(12,Pin.OUT) IN2 = Pin(13,Pin.OUT) IN3 = Pin(14,Pin.OUT) IN4 = Pin(15,Pin.OUT)

pins = [IN1, IN2, IN3, IN4]

sequence = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]

while True:
for step in sequence:
for i in range(len(pins)): pins[i].value(step[i]) sleep(0.001)
S
Connection

Raspberry Pi Pico STEPPER MOTOR


Development Board
5V + (5V)
GND - (GND)
GP12 IN1
GP13 IN2
GP14 IN3
GP15 IN4

You might also like