IoT Manual
IoT Manual
Introduction :-
This Multi MCU Development platform is related to The Internet of Things (IoT) which is an
environment in which objects, people & other human beings are provided with unique identifiers and the
ability to transfer data over a network without requiring Human-to-Human or Human-to Computer interaction.
IoT with Multi MCUs has evolved from the convergence of wireless technologies, Micro-ElectroMechanical
Systems (MEMS) and the Internet. More than just smart homes and connected appliances. Multi MCU IoT is
about connecting devices over the Internet and other wireless technologies, letting them talk to us, to
applications, and each other.
This Multi MCU A is a unique solution which allows user to Learn &explore Architecture, Working, and
Applications of Internet of Things. Using a variety of included and optional sensors and actuators, this solution
provides in-depth learning for a vast range of applications.
Features:-
SDRAM 4 GB LPDDR4-2400
Wireless LAN 2.4 GHz and 5.0 GHz IEEE 802.11b/g/n/ac, Bluetooth 5.0, BLE
Slot for Micro SD card, for operating system and data storage
Specifications:-
SRAM: 2 KB (ATmega328).
EEPROM: 1 KB (ATmega328).
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual
Cores Microcontroller. The ESP32 is integrated with Antenna switches, RF Balun, power amplifiers,
low-noise amplifiers, filters, and management modules, and the entire solution occupies the least area
of PCB. 2.4 GHz Wi-Fi plus Bluetooth dual-mode chip, with TSMC Ultra-low power consumption 40nm
technology, power dissipation performance, and RF performance is the best, safe and reliable, easy to
extend to a variety of applications.
1. High performance-price ratio
2. Small volume, easily embedded to other products
3. Strong function with support LWIP protocol, Freertos
4. Supporting three modes: AP, STA, and AP+STA
5. Supporting Lua program, easily to develop
DS18B20 Temperature Sensor : 1 no. Vibration Switch Module : 1 no. (Shock Sensor Module) Hall
Magnetic Sensor Module : 1 no. Key Switch Module(Button) : 1 no. Infrared Emission Sensor Module :
1 no. Laser Sensor Module : 1 no. Small Passive Buzzer Module : 1 no. 3-Color LED Module : 1 no. RGB
SMD Module : 1 no. Photo Interrupter Module : 1 no. (Light Blocking Module) 2-Color LED Module : 1
no. Active Buzzer Module : 1 no. NTC Thermistor Sensor : 1 no. (Digital Temperature Sensor) DHT11
Temperature and Humidity Sensor : 1 no. Photo Resistor Module : 1 no. 5V Relay Module : 1 no. Tilt
Switch Module : 1 no. Mini Magnetic Reed Sensor : 1 no. Tracking Module : 1 no. Obstacle Avoidance
Sensor : 1 no. IR Receiver Module : 1 no. XY-axis Joystick Module : 1 no. 11 Linear Magnetic Hall
Sensors : 1 no. Reed Switch Module : 1 no. Flame Sensor Module : 1 no. Magic Light Cup Module : 1 no.
5mm Red and Green LED module : 1 no.(Common Cathode) Knock Sensor Module : 1 no. (Tap Module)
Automatic Flashing Colorful LED Module : 1 no. (7 Colour Flash LED Module) Analog Hall Magnetic
Sensor Module : 1 no. Metal Touch Sensor Module : 1 no. Sensitive Small Microphone Sensor Module :
1 no. Sensitive Big Microphone Sensor Module : 1 no. Finger Measuring Heartbeat Module : 1 no.
Rotary Encoder Module : 1 no. Ball Switch Module : 1 no. Analog Temperature Module : 1 no
ULTRASONIC SENSOR
I2CLCD DISPLAY
PIR MOTION SENSOR
Introduction to Arduino Platform
& Programming
Arduino Uno Hardware Pin Details
What is Arduino?
An Arduino is an open source hardware platform with built in programming support. No
additional hardware or software (e.g. Hex burner) is required to transfer your programs (i.e. hex file)
to the Arduin0. There are all the necessary peripherals attached for the basic operation. It is based on
simple AVR microcontrollers.
Why to choose Arduino?
1) Arduino has it’s built in programmer to burn the Hex file in it, for most of the beginners, it is
very irritating to buy Microcontroller and Burner separately and sometimes it is very annoying
, when poor hardware has a little hidden broken wire and you will waste plenty of precious
hours.
2) Its open source so the whole word developer constantly working on its upgrade and fixing its
bugs, so its support is readily available worldwide.
3) The largest number of libraries is freely available so person does not need to write a lot of
basic code to make the things run.
4) Arduino support many different shields, which can be attached to the basic Arduino board with
male to female Headers. It reduces the traditional wiring and chances of errors are less. It is
also space and power efficient.
Types of Arduino :
Arduino has many boards it starts from basic Arduino UNO and goes to Arduino mega, ArduinoFio, lily
pad so on and so forth.
Arduino UNO
Arduino Mega
Arduino Duemilanove
Arduino FIo
Lily Pad Arduino
Aurdino Extreme V2
And many other boards.
Arduino Programming – Step by Step
Programming Arduino (First program):
Let’s start with Arduino UNO its simple enough to start with, it is based on Atmega 328
Microcontroller. In this Multi MCU kit, Arduino Uno Was pre installed in Raspberry Pi ,We will be
using Raspberry Pi a as our Computer , which is connected to a computer Monitor. Any how Before
connecting Arduino to your computer/Raspberrypi, We have to install Arduino IDE in our computer
/RPI System.
How to Install Arduino IDE?
Installing Arduino IDE is pretty straightforward. Go to Arduino IDE to download the recent version
of Arduino IDE. There are multiple versions available for different operating systems such as
Windows, Mac, and Linux. Not only that, nowadays Arduino IDE comes in two variants Arduino IDE
1.x and Arduino IDE 2.x. For this tutorial, we will be talking about the Classic 1.X variant. Basically,
both have almost same functionality with a different GUI plus some additional features such as auto
code completion.
Download the installer for your operating system from the above-given link.
Once the download is done open the .exe file.
Agree to the licence agreement and select if the IDE should be installed to all users or not and
click on “Next” to continue.
Select the location in which you want the IDE to install if you want to change the location or
keep it default and click on “Install”
Wait for the installer to finish installation, and click on “Close”.
It’s also important to select the proper serial port to which the Arduino board is connected.
Otherwise, you won’t be able to upload the code to the board. To do that click on “Tools” -> “Port” And
select the correct COM port. If there are multiple COM ports and you are not sure which one to select,
disconnect the Arduino board from the USB port and reopen the menu. The COM port entry that
disappeared will be the correct COM port. Reconnect the Board to the same USB port and select that
port.
To start with we will be using the LED Blink example that is already provided with the Arduino
IDE. To open the Blink example, go to Files -> Examples -> Basics -> Blink.
Blinking LED
Steps in building a Raspberry Pi IOT Kitconnection:
Step-1: Connect the Arduino to the Windows /Raspberry Pi via a USB cable
Step-2: Connect the 13th digital pin of Arduino to the positive of the LED and GND to the negative in
Arduino
If you connect in a Breadboard, plz find below the diagram
int LED =13; // The digital pin to which the LED is connected
void setup ( )
{
pinMode (LED, OUTPUT); //Declaring pin 13 as output pin
}
void loop( ) // The loop function runs again and again
{
digitalWrite (LED, HIGH); //Turn ON the LED
delay(1000); //Wait for 1sec
digitalRead (LED, LOW); // Turn off the LED
delay(1000); // Wait for 1sec
}
Arduino program for LED blink (Version-2)
void setup ( )
{
pinMode (13, OUTPUT); //pin 13 is set as output pin
}
void loop( ) // The loop function runs again and again
{
digitalWrite (13,HIGH); // Turn ON the LED on pin 13
delay (1000); //Wait for 1sec
digitalWrite (13, LOW); //Turn OFF the LED on pin 13
}
In version-1 of the LED blink program LED is declared globally and is set to pin number 13.
This will reduce the number of iterations required to update the pin number in the program when you
connect the LED to the other digital pin. Whereas, the pin number has to be changed in 3 different
statements in version-2.
The magic happens when you click the upload icon in the Arduino IDE. The program will be
uploaded into the microcontroller of Arduino board and LED in the circuit starts blinking.
Fade-in and fade-out the LED
The step for the LED bling experiment are the same as those followed for building the
breadboard circuit except that in step-2, you connect the 9th digital pin to the positive power rail of
the breadboard.
In both the versions of the LED fade-in and fade-out programs, the analogWrite statement is
used for a led connected to a digital pin. The reason for this is that, digital pin 10 is a PWM pin.
Arduino UNO board, has PWM pin which is capable of generating Analog output. In both the programs
pin 10 is used as analog output pin.
Expt. No.
Turn ON/OFF LED using microcontroller/SBC through internet.
Date:
Aim :-
To make LED BLINK with Arduino Uno using IOT Trainer Kit
Apparatus Required:
Raspberry PI IOT Trainer Kit
Arduino Uno
A to B USB Cable
Arduino Uno IDE & Patch Cords
Procedure :-
1. Switch On the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/ARDUINO/1_led_blink/Blink
3. Double click the Blink.ino folder
4. The Program code automatically gets open in Arduino ide
5. Now connect D13 of UNO to LED ( any one out of 4) or loop all leds
6. Now select sketch & upload the Program (After uploading you can see a message done
uploading At the bottom of the Arduino ide software)
7. After successful uploading you can see the LED Starts blinking.
PROGRAM:
int LED =13; // The digital pin to which the LED is connected
void setup ( )
{
pinMode (LED, OUTPUT); //Declaring pin 13 as output pin
}
void loop( ) // The loop function runs again and again
{
digitalWrite (LED, HIGH); //Turn ON the LED
delay(1000); //Wait for 1sec
digitalRead (LED, LOW); // Turn off the LED
delay(1000); // Wait for 1sec
}
Circuit Connection Diagram:
Result:
Thus the LED BLINK with Arduino Uno using IOT Trainer Kit was executed successfully.
Expt. No. Communication methods using microcontroller/SBC through
Date: internet.
Aim :-
To make Communication with Android Mobile with Arduino using Bluetooth Module ( HC-05)
to control LED/Relay using IOT Trainer Kit.
Apparatus Required:
Raspberry PI IOT Trainer Kit
Arduino Uno
A to B USB Cable ,
Arduino Uno IDE &Patch Cords
Procedure :-
After starting the hardware and connecting keyboard, mouse, and monitor. Connect Arduino UNO via
USB to IOT Kit. Make the connections as follows:
1. VCC – to VCC of Arduino. &GND – to GND of Arduino.
2. RX of Blue tooth Module – to digital pin 0(TX pin) of Arduino.
3. TX of Bluetooth Module – to digital pin 1(RX pin) of Arduino.
4. LED /Relay to – Positive terminal – to pin 8 of Arduino.
5. LED/Relay to -Negative terminal – GND of Arduino.
i. (Note :- connect RX & TX pin after uploading the code)
1. Copy the code given below (or) select the folder /home/pi/MI/Arduino
codes/BLESWITCH/BLESWITCH.ino
2. Double click BLESWITCH.ino and it automatically opens the code in Arduino ide
3. Download the Mobile app called Arduino Blue Control (It’s free).
4. Open the app Blue control (It will automatically turn on the device’s Bluetooth). Go
to options. Click on “Connect to Robot”. Choose device – HC 05.
5. When you are connecting to the Bluetooth module for the first time, it will ask you
the password. Enter 0000 OR 1234.
6. When the device gets successfully paired with the sensor, the LED /Relay will be
on sensor will start blinking/chattering at a slower rate than usual.
Progrram:-
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT); // put your setup code here, to run once:
}
void loop() { // put your main code here, to run repeatedly:
if(Serial.available()>0)
{
char data= Serial.read(); // reading the data received from the bluetooth module
switch(data)
{
case 'a': digitalWrite(8, HIGH);break; // when a is pressed on the app on your
smart phone
case 'd': digitalWrite(8, LOW);break; // when d is pressed on the app on your
smart phone
default : break;
}
Serial.println(data);
}
delay(50);
}
Result :-
Thus the Communication with Android Mobile with Arduino using Bluetooth Module ( HC-05)
to control LED/Relay using IOT Trainer Kit was executed successfully.
Expt. No. Communication methods (GSM 800L )using microcontroller/SBC
Date: through internet.
Aim :-
To make Communication with Mobile with Arduino using GSM 800L Module to control
LED/Relay using Raspberry Pi IOT Trainer Kit.
Apparatus Required:
IOT Trainer Kit
Arduino Uno
GSM Module with Micro SIM
A to B USB Cable , Arduino Uno IDE & Connecting Wires
Procedure :-
After starting the hardware and connecting keyboard, mouse, and monitor. Connect Arduino
UNO via USB to IOT Trainer Kit. Make the connections as follows:
Pin Details:
Connection Procedure :-
Connect Arduino RX Pin to GSM TX Pin
Connect Arduino TX Pin to GSM RX Pin
Connect Arduino GND to GSM GND Pin
Most important part of the module is the Chip made by SIMCom. Its operating voltage in
which it works fine ranges from 3.7 V to 4.4 V (recommended), but you can use 5 V with some
nominal current.
(Note :- connect RX & TX pin after uploading the code)
Before Uploading Code or making Connections. Insert Microsim Card ( Except Jio) as shown in
the Diagram. Once the SIM Card is Inserted , GSM800L will Search for Network & Once the
Network is detected, You can see the LED in the GSM 800L will Start Glowing Slowly every 3
seconds.
Now select the folder /home/pi/MI/Arduino codes/GSM Relay/gsm_parsxe_ok2
Double click gsm_parsex-e_ok2.ino and the program will automatically open in Arduino ide
Now add the Mobile No ( Inserted SIM Card) in the code. connect TX and RX on GSM to Arduino
uno Pins of D7 to TX and D8 to RX of GSM 800L connect relay pin to D4.
Circuit Diagram:-
Once you Upload the Code, open serial monitors and check for AT Commands. The
Relay will get energize & Now Dial the Mob number from another Mobil e Number it will
identify the number and confirm Ok and disconnect and relay will Get Deenergized. We
have also given AT Commands and Dial Programs code also .
Result:-
Thud the Communication with Mobile with Arduino using GSM 800L Module to control
LED/Relay using Raspberry Pi IOT Trainer Kit was completed successfully.
Expt. No. Communication methods (ZigBee)using microcontroller/SBC
Date: through internet.
Aim:-
To make wireless communication with Arduino using ZigBee Module to control LED/Relay
using Raspberry Pi IOT Trainer Kit
Apparatus Required:
IOT Trainer Kit
Arduino Uno
ZigBee with ZigBee breakout shield &ZigBee with USB Adaptor
A to B USB Cable, Arduino Uno IDE & Connecting Wires
Procedure: -
After starting the hardware and connecting keyboard, mouse, and monitor.
Connect Arduino UNO via USB to IOT Trainer Kit. Make the connections as follows:
Before connection, we have to configure ZigBee using XCTU Software making one Zigbee as
End-user or router & another ZigBee as co-ordinator.
The link shown below will make you understand how to configure ZigBee using XCTU
https://robu.in/how-to-configure-zigbee-xbee-pro-s2c-802-15-4-module/
plyfinds below the diagram. Connect the ZigBee to Arduino using ZigBee shield
Connections: -
1. Tx (pin2) ofBee -> Tx of Arduino board
2. Rx(pin3) of Bee -> Rx of Arduino board
3. God(pin10) of Bee -> GND of Arduino board
4. Vic (Pin1) of Bee -> 3.3v of Arduino board
Receiver Zigbee Connection: -
Connect another ZigBee to Zigbee adaptor and connect it to a PC using USB. Ensure that you
Have installed XCTU in the PC to Communicate with another ZigBee. Here we will use raspberry pi
as co-ordinator with Arduino connected withZigbee as the PC connected with Zigbee with adaptor as
End User.
Procedures: -
Make Connections as per the Below Image
Now upload the Program., after uploading connect the TX and RX of Bee to Arduino
Open XCTU in PC (Enduser) of Bee.check the com port that you have connected to the PC and in
XCTU Software click the Test /Query. After testing open the HyperTerminal in XCTU From
HyperTerminal Type A, Now the LED/Relay should actuate 1 time. If you Type B the LED/Relay
Should actuate 5 Times with some Delay.
If error persists, check that, you have configured the ZigBee properly by connecting both
In PC and check with XCTU by opening the hyperterminal and check the communication by
Typing letter, it should get repeated on another hyperterminal.
Result:-
Thus the wireless communication with Arduino using ZigBee Module to control LED/Relay
using Raspberry Pi IOT Trainer Kit was completed successfully.
Introduction to RASPBERRY Pi Platform
&
Python Programming
Raspberry Pi Introduction: -
OS for Raspberry Pi
Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they provide
NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS like Ubuntu, Arch Linux,
RISC OS, Windows 10 IOT Core, etc.
Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for Browsing, Python
programming, office, games, etc.
Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e. GPIOs for
developing an application. By accessing GPIO, we can connect devices like LED, motors, sensors, etc
and can control them too.
Raspberry Pi processor
It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics Processing Unit).
The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also, it has on-board SDRAM that
ranges from 256 MB to 1 GB.Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.
1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero
Out of the above versions of Raspberry Pi, more prominently use Raspberry Pi and their features are as follows:
For More Details about Raspberry pi 4 B ply visit the below website
https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/
Introduction to Python with Raspberry Pi
The Raspberry Pi made physical computing and programming accessible to many -- it is relatively
inexpensive, and almost anyone could simply connect a monitor, keyboard, and mouse to get started. Python is
an easy to start with high-level language, and it is an integral part of the Raspberry Pi's operating system.
In this guide, we'll show you how to get started with the Thonny IDE, learn about basic data types and
control flow statements that are readily used when working with sensors and actuators on the Raspberry Pi.
The Raspberry Pi was created so that computing could be more accessible for everyone -- it is
relatively inexpensive, and anyone could simply connect a monitor, keyboard, and mouse to get
started. As sensors, actuators and other devices can be easily attached to it via its handy General-
purpose Input Output (GPIO) connector, it also serves as a gentle introduction into physical
computing. The other impetus was to make programming more accessible, especially for beginners
and kids. That's why Python is an integral part of the Raspberry Pi's operating system!
In this guide, we'll show you how to get started with programming in Python on the Pi. We'll
also briefly talk about the commonly used data types.
What is a programming language?
Machine language or machine code is a lower-level form that is read and executed by the
computer. This language is comprised of binary, 0's and 1's. In this machine code, all instructions,
memory locations, numbers, and characters are represented in 0's and 1's.
Assembly language implements a symbolic representation of machine code, that is to say, it
replaces the 0's and 1's with alphanumeric symbols in order to make it easier to remember and work
with.
While they can run and execute fast, the main disadvantage is that it is tedious for humans to
use, maintain, or debug. Enter high-level languages, these are languages that seem a lot more like our
human language, enabling us to focus on problem-solving.
Still, programming languages such as Java or C++ require the use of a compiler, which is a
program that converts human-readable instructions or code, into machine code, and is then executed
and run.
On the other hand, a programming language such as Python is executed directly using
an interpreter, rather than needing to go through a compiler. The code is read one at a time, where
each statement is translated into machine language and then executed.
While a compiler scans the entire program and translates it as a whole into machine code, an
interpreter translates the program one statement at a time.
Starting Python for the First Time: -
One of the challenges when beginning to use Python is the need to install Python and other
related software. Thankfully, all this is already set up for you in the latest version of Raspbian with
PIXEL desktop, specifically Raspbian Buster at this time of writing.
The easiest way to get started is to use Thonny, a new IDE (integrated development
environment) that can be easily accessed by navigating to Raspberry Pi icon (menu) > Programming >
Thonny Python IDE.
You will see a script editor and a shell; you enter a program in the script editor and run it in the
shell. Let's write our first program!
Save and execute sample code: -
https://learn.littlebirdelectronics.com.au/guides/introduction-to-python-with-raspberry-pi
Now we can try some practical Python programs using Raspberry Pi IOT Kit
Expt. No.
Simple LED Blink Python Program using Raspberry Pi
Date:
Aim:-
To make LEDBLINK using Raspberry Pi using IOT Trainer Kit.
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi
A to B USB Cable, Tonnid& Patch Cords
Procedure: -
1. Switch on the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/RPI_IOT_PRGM/Rippled
3. Right click the Blink.py folder and open it in Thonny
4. Make connections are per the below image
5. connect GP12 from Raspberry Pi to LED (any one out of 4) or loop all lids
6. Now to run the Program click the RUN Image as shown (Run Current script)
7. After successful uploading you can see the LED Starts blinking
Circuit Connection Diagram: -
Result:-
Thus the LEDBLINKING using Raspberry Pi using IOT Trainer Kit was executed successfully.
Expt. No.
Sensor Interfacing Python Program using Raspberry Pi
Date:
Aim: -
To connect DHT 11 Sensor using Raspberry Pi and the output to be displayed in I2C LCD using
IOT Trainer Kit.
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi I2C LCD, DHT11 Sensor
Thonny IDE &Patch Cords
Procedure: -
1. Switch on the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/RPI_IOT_PRGM/DHTI2CLCD/DHT_I2C_LCD
3. Right click the dht_lcd.py folder and open it in Thonny
4. Make connections are per the below image
5. Switch on LCD and Connect SDA of LCD to SDA1 of Raspberry Pi using Patch cord
6. Connect SCL of LCD to SCL1 of Raspberry Pi using Patch cord
7. connect GP23 from Raspberry Pi to DHT11 Sensor
8. Now Click RUN on the Thonny IDE
9. After successful uploading you can see Temperature and humidity values on the
LCD Display& also at the bottom of the Thonny IDE.
By Using Heater or Hair Dryer, if you heat up the DHT11 Sensor you Can see the changes
in the Temperature & Humidity
Connection Diagram: -
Result: -
Thus the DHT 11 Sensor using Raspberry Pi using IOT Trainer Kit was connected and the
output is also be displayed in I2C LCD successfully.
Expt. No. Ultrasonic Sensor Interfacing Python Program using
Date: Raspberry Pi
Aim:-
To connect Ultrasonic Sensor to measure distance using Raspberry Pi using IOT Trainer Kit
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi Ultrasonic Sensor HC SR04
Thonny IDE &Patch Cords
Procedure: -
1. Switch on the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/RPI_IOT_PRGM/Ultrasonic Sensor
3. Right click the Raspberry_Pi_Ultrasonic_Sensor.py folder and open it in Thonny
4. Make connections are per the below image
5. Connect ECHO of Ultrasonic Sensor to GP12 of Raspberry Pi using Patch
6. Connect TRIG of Ultrasonic Sensor toGP16 of Raspberry Pi using Patch cord
7. Now Click RUN on the Thonny IDE
8. After successful uploading you can see message at the bottom of the Thonny IDE.
9. A message appears Calibrating wait… and Place the object to measure the Distance …….
10. Now place a small sheet (Cardboard) in front & near to the Ultrasonic Sensor
11. Now it shows the distance from the sensor, move the sheet slowly & you can observe the
Different measurement shown at the bottom of the Thonny IDE.
Connection Diagram: -
Program:
Result:-
Thus the Ultrasonic Sensor using Raspberry Pi using IOT Trainer Kit was connected and also
the distance is measured successfully
Expt. No. Flame Sensor Interfacing Python Program using
Date: Raspberry Pi
Aim:-
To connect Flame Sensor to detect fire and make alarm using Buzzer With RaspberryPi using
IOT Trainer Kit
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi Flame Sensor & Match box/Lighter
Buzzer,Thonny IDE &Patch Cords
Procedure :-
1. Switch On the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/RPI_IOT_PRGM/Flame_sensor
3. Right click the flame_Sensor.py folder and open it in Thonny
4. Make connections are per the below image
5. Connect DO of Flame Sensor to GP7 of Raspberry Pi using Patch cord
6. Connect Buzzer Pin to GP8 of Raspberry Pi using Patch cord
7. Now Click RUN on the Thonny IDE
8. After successful uploading you can see message at the bottom of the Thonny IDE.
9. A message appears No Flame No Fire Detected.
10. Now Make fire using Match Box or using Lighter and take it near the Flame Sensor
11. Now the buzzer sounds and you can see the message at the bottom of Thonny Ide which
shows Flame Present ----Fire Detected
Connection Diagagram:-
Result:-
Expt. No.
IR Sensor Interfacing Python Program using Raspberry Pi
Date:
Aim:-
To connect IR Sensor to detect objectand make alarm using Buzzer with Raspberry Pi using
IOT Trainer Kit
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi IR Sensor&Buzzer
Thonny IDE &Patch Cords
Procedure :-
1. Switch On the Kit & Make Connections as shown below
2. Go to /home/pi/SASRPIIOT/RPI_IOT_PRGM/IR_sensor
3. Right click the IR_Sensor.py folder and open it in Thonny
4. Make connections are per the below image
5. Connect IR Sensor to GP16 of Raspberry Pi using Patch cord
6. Connect Buzzer Pin to GP12 of Raspberry Pi using Patch cord
7. Now Click RUN on the Thonny IDE &After successful uploading you can see message
at the bottom of the Thonny IDE.
8. A message appears IR Sensor Ready ----
9. Take a Cardboard & take it near the IR LED, the sensor will sense it and a message appears,
Object Detected & Buzzer sounds. When you remove the card Board near from IR LED , the
Buzzer stops & Another Message appears…NO Object Detected.
Connection Diagram:
Result:
Expt. No. To Communicate between Arduino and Raspberry Pi using any
Date: wireless Medium
To Start & to Understand basically, with very simple way to communicate with Arduino
And Raspberry pi is Serial Communication. Wireless Communication is nothing but,it
Is similar form Like Serial communication, where we communicate with TX/RX Wires
Connected in interchange to Transmit & Receive.
But in wireless, we do the same of Transmitting Data or information from Arduino to
Raspberry Pi or Vise versa..,by RF,Cellular,Infrared,wifi,Bluetooth,Lifi,and by zigbee etc.,
Serial communication is simply a way to transfer data. The data will be sent sequentially, one
bit at a time (1 byte = 8 bits), contrary to parallel communication, where many bits are sent at
the same time.
UART protocol
More specifically, when you use Serial with Arduino and Raspberry Pi, you’re using the UART
protocol. UART means “Universal Asynchronous Reception and Transmission”.
You’ve certainly already used Serial communication many times. I’m sure you already know
the Arduino Serial library, which allows you to log what’s happening in your code and get user
input. When you use the Serial monitor, well, basically your Arduino IDE initiates a Serial
communication with your Arduino. You can receive and send data directly from the Serial
monitor.
What we’ll do here is almost the same, except that instead of your Arduino IDE, the other side
of the Serial communication will be a Raspberry Pi board. We’ll have to do some setup and
write some code to make it work. Then, both Raspberry Pi and Arduino will be able to send
messages to each other.
Let’s now see how to physically connect the 2 boards together.
There are 2 ways to connect your Raspberry Pi and Arduino for Serial communication.
On the Raspberry Pi side, a simple USB connector is all you need. You can choose any of the 4
USB ports available on the board.
For Arduino, you will use the USB port that you use to upload code from your computer (with
the Arduino IDE) to your board. Here the USB connector will depend on which version you
have. For boards like Arduino Uno and Mega, the connector will be different from Arduino
Nano, and from Arduino Zero.
As you can see, it’s the simplest hardware connection you can make between Raspberry Pi and
Arduino.
Note: you will first need to connect your Arduino to your computer, so you can upload the code
into the board. After that, connect the USB cable to the Raspberry Pi. The Raspberry Pi will
power the Arduino via this cable.
To make a Serial connection you can also use plain wires between the Raspberry Pi GPIOs and
the Arduino pins.
Serial connection:-
Depending on your Arduino board you might need to use a voltage level-shifter. The Raspberry
Pi is operating at 3.3V. For Arduino boards like Due, 101, it will be fine because they also use
3.3V.
But, for many Arduino, such as Uno, Mega, Leonardo, Nano, and many more, the board is
operating at 5V. Thus, you need a 3.3V/5V level-shifter to protect the Raspberry Pi when
connecting RX and TX (more info on Raspberry Pi pins and Arduino Uno pins).
For the rest of this tutorial we’ll use the setup with the USB cable. This will be easier to manage
and unless you have a good reason not too, you should prefer using the USB cable instead of
plain gpios for Serial communication.
Raspberry Pi Software setup
You don’t need any special setup for Arduino. Just make sure you have downloaded and
installed the Arduino IDE.
Now, on your Raspberry Pi, a few things are required to make the communication work.
Connect to your Raspberry Pi, either via ssh, or by plugin a screen+mouse+keyboard, and open
a terminal. If you haven’t installed an OS on your Pi yet, you can
install Raspbian or Ubuntu very easily on a SD card.
Simply run
ls /dev/tty*
and you should see it. At this point if you’re not sure which device is the Arduino board, simply
disconnect the board (remove the USB cable), and run
ls /dev/tty*
again. This way you will easily spot the serial device name of your Arduino.
Also, you may want to add your user to the dialout group, to avoid errors such as:
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyACM0: [Errno 13]
Permission denied: ‘/dev/ttyACM0’.
$ sudoadduseryour_usernamedialout
This will make sure you have access to Serial devices (/dev/ttyACMx, /dev/ttyUSBx, …).
After you’ve added yourself to the dialout group, you need to reboot your Pi (or at least
logout/login) to apply the change – learn more about Raspberry Pi hardware permissions.
Install Python Serial library on Raspberry Pi
You need to install a library to be able to use the Serial interface with Python.
For this tutorial we’ll use the pySerial library (documentation for Python 3). To install it:
python3 -m pip install pyserial
When installing, if you get an error such as “/usr/bin/python3: No module named pip”, then
you need to install pip first with
Raspberry Pi and Arduino serial communication is a simple way for sharing data between
computers and microcontrollers. Serial communication enables two devices to exchange data
using a simple single-wire interface or Serial via GPIOs pins.
To send data from Arduino to Raspberry Pi, you will need to use a shape of communication
learned as serial communication. Serial communication authorises you to send data one bit at
a time, which is excellent for sending data from a microcontroller like an Arduino to a more
extensive computer like a Raspberry Pi.
In order for serial communication to take place, both the Raspberry Pi and the Arduino will
need to have their serial ports configured. The Raspberry Pi has two serial ports, that can be
used for serial communication. The most common way to do this is to use a USB cable. Once the
Raspberry Pi and Arduino are connected, they can start exchanging data. Raspberry Pi 4
Pinout, Specifications, Pin Configuration & Programming
Set up serial communication from Arduino to Raspberry Pi connected via USB to the socket.
Now we like to do a short example of serial communication from Arduino to Raspberry Pi. We
want to send the temperature and humidity of the DHT11 sensor from the Arduino Uno to
the Raspberry Pi via the USB connection. The Raspberry Pi should print the temperature and
humidity on its terminal.
We plan to start with the configuration of the Arduino. First, we need to connect the DHT11
sensor to digital pin 7 of the Arduino Uno, as well as power and ground. the script is quite easy.
Arduino
1 #diyprojectslab,com
2 #include "DHT.h"
3 #define DHTPIN 7 // define the digital I/O pin
4 #define DHT11TYPE DHT11 // DHT 11
5 DHTdht11(DHTPIN,DHT11TYPE);
6
7 voidsetup(){
8 Serial.begin(9600);
9 dht11.begin();
10}
11
12voidloop(){
13 floath11 = dht11.readHumidity();
14 floatt11 = dht11.readTemperature();
15 Serial.print("Temperature = ");
16 Serial.print(t11 + 273.15);
17 Serial.println(" Kelvin");
18
19 Serial.print("Humidity = ");
20 Serial.print(h11);
21 Serial.println(" %");
22 delay(1000);
23}
It is necessary that the message that we like to transmit to the Raspberry Pi is printed on the
serial number because if it is printed on the serial number it is also sent via USB to the
raspberry pi. The Arduino IDE serial monitor shows the output. Everything is going well.
In the following detail, we set up Raspberry Pi to receive temperature and humanity from the
Arduino board as well.
Now everything is prepared and we can go to the programming factor of the Raspberry Pi.
Since we want to make the code with python and also want to display the code using a python
script, we require to install two libraries. Run the following commands in the raspberry pi
terminal:
1sudoapt-get install python-serial
2sudo pip install pyserial
Since there are different USB ports on the Raspberry Pi, we must know which serial address
the Arduino is attached to a raspberry pi.
Must connect Arduino USB Plug to Raspberry PI with a USB cable and check the connection
between Arduino and Raspberry pi by typing “ls /dev/tty*” in the Raspberry Pi terminal, the
result should be scope”/dev/ttyACM0” and you are right to go.
In my issue, I located the serial connection with the name /dev/ttyACM0. copy or type your
name for the serial connection, as we are using the name in the next python program code.
Directly we want to make the code. the code is so short, we created the python file directly on
the Raspberry Pi. Create the file with nano serial_communication.py.
The nano text editor now opens an empty python file called serial _communication.
serial_communication.py
Python
1importserial
2import RPi.GPIO as GPIO
3ser = serial.Serial('/dev/ttyUSB0',9600, timeout=.5)
4whileTrue:
5 read_serial=ser.readline()
print(read_serial)
Click Ctrl + X then Y to assure the save and push the Enter button to save to the current file.
Start the python script from the terminal with python serial_communication.py. You should see
the temperature and humidity from the DHT11 transferred through USB and Arduino serial
communication.
Expt. No. Wireless communication from Arduino to Raspberry Pi
Date: Using X-bee
Aim:-
To send DHT11 Sensor Data from Arduino wirelessly & to Receive DHT11 Sensor Data in
Raspberry pi Using Zigbee( X-Bee)
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi ,Arduino Uno
Zigbee with Sheild,zigbee adaptor(S2C,S2,S2CPro)
Thonny IDE &Berg Strips &Patch Cords
Procedure :-
1. Connect Xbee with shield as shown with Arduino as shown below
2. Also Connect DHT11 (D1) Sensor Pin to Digital Pin 7 of Arduino
3. Connect another zigbee with Zigbee adaptor with USB Cable to Raspberry Pi
4. Connect small USB Cable of Arduino to Raspberry Pi
Result:-
STUDY OF SETUP A CLOUD PLATFORM TO LOG
THE DATA
Setup a Cloud Platform Using to Thing- Speak to send Data
ThingSpeakisanopenIoTplatformformonitoringyourdataonline.InThingSpeakchanne
lyoucanset the data as private or public according to your choice. ThingSpeak takes
minimum of 15 seconds to update your readings. Its a great and very easy to use
platform for building IOT projects.
Therearealsosomeotherplatformsavailableformonitoringyourdataonlinewhichwewillc
overin
laterarticlesbuttherearesomeadvantagesofThingSpeakoverotherplatformslikeitisvery
easytoset up and it also has many options to plot graph.
we will use ThingSpeak (https://thingspeak.com/) as cloud server to store the data.
Here with Raspberry Pi we can use any sensor data to Monitor it will send it to
ThingSpeak, and it can be monitored from anywhere in the world using internet. This
will be useful if you are running the Pi for long time for some application at some
remote place and need monitor its CPU temperature.
Steps for building Raspberry-Pi Data Logger on Cloud Platform:-
Step1:SignupforThingSpeak
ForcreatingyourchannelonThingSpeakyoufirstneedtosignuponThingSpeak.Incaseifyo
ualready have account on ThingSpeak just sign in using your id and password.
Forcreatingyouraccountgotowww.thinspeak.com (http://www.thinspeak.com)
Clickonsignupifyoudon’thaveaccountandifyoualreadyhaveaccountclickonsig
nin. After clicking on signup fill your details.
AfterthisverifyyourE-mailidandclickoncontinue.
Step2:CreateaChannelforYourData
OnceyouSigninafteryouraccountverification,Createanewchannelbyclicking“NewChannel”
button
After clicking on “New Channel”, enter the Name and Description of the data you want to
upload on this
channel.ForexampleIamsendingmyCPUdata(temperature),soInameditasCPUdata.
Now enter the name of your data (like Temperature or pressure) in Field1. If you want
to use more than one Field you can check the box next to Field option and enter the
name and description of your data.
Afterthisclickonsavechannelbuttontosaveyourdetails.
Step3:GettingAPIKeyinThingSpeak
To send data to ThingSpeak, we need an unique API key, which we will use later in our
python code to upload our CPU data to ThingSpeak Website.
Clickon“APIKeys”buttontogetyouruniqueAPIkeyforuploadingyourCPUdata.
Nowcopyyour“WriteAPIKey”.WewillusethisAPIkeyinourcode.
Step4:PythonCodeforRaspberryPi
Complete code is given at the end of this tutorial, just make a file with any name and
.py extension and copy-paste the code and save the file. Don’t forget to replace the API
key with yours. You can run the python file any time using below command:
python/path/filename.py
sudoapt-getinstallpython
AssumingyoualreadyinstalledpythoninRaspberrypiusingthiscommand
IfthecoderunsproperlyyouwillseesomeCPUtemperaturevaluesasshowninbelowimage.
IfthecoderunsproperlyyouwillseesomeCPUtemperaturevaluesasshowninbelowimage.
If there are anyerrors uploading the data,you will receive “connectionfailed” message.
Case2:Ifyouareusing“Putty”thenyoushouldfollowthesecomma
nds: First update your pi using:
sudoapt-getupdate
nanocpu.py
Afterthismakeafilecpu.pyusing:
AftercreatingthisfilecopyyourcodetothisfileandsaveitusingCTRL+Xandthen‘y’andEn
ter. After this install all libraries using:
sudo apt-get install httplibsudo apt-get install
urllib
pythoncpu.py
Afterinstallinglibrariesrunyourpythoncodeusing:
IfthecoderunsproperlyyouwillseesomeCPUtemperaturevaluesasshowninaboveimage.
Step6:CheckThingSpeaksiteforDataLogging
After completing these steps open your channel and you will see the CPU temperature
data is updating into ThingSpeak website.
LikethisyoucansendanysensordataconnectedwithRaspberrypitotheThingSpeakClo
ud. Now ,You are familiar to Create a Cloud data. wewillconnect DHT11
temperaturesensorwith
RaspberryPiandsendthetemperaturedatato
ThingSpeak,whichcanbemonitoredfromanywhere.CompletePythoncodeforthisRaspbe
rryPiCloudServerisgiveni n the next page Codeiseasyandself-
explanatorytounderstand.
Sample PythoncodeforRaspberryPiCloudServer
Code
importhttplib
importurllib
importtime
whileTrue:
#Calculate CPUtemperatureofRaspberryPiinDegreesC
temp=int(open('/sys/class/thermal/thermal_zone0/temp').read())/1e3#GetRaspberryPiCPUtemp params =
urllib.urlencode({'field1': temp, 'key':key })
headers={"Content-typZZe":"application/x-www-form-urlencoded","Accept":"text/plain"} conn =
httplib.HTTPConnection("api.thingspeak.com:80")
try:
print temp
conn.close()
except:print"connectionfailed"
break
if name== "main":
while True:
thermometer()
Expt. No. Log Data using Raspberry PI & Upload to the cloud
Date: platform
Aim :-
To send /Log DHT11 Sensor Data Using Raspberry Pi & Upload to Cloud Platform using
ThingSpeak
Hardware Required:
Raspberry PI IOT Trainer Kit
Raspberry Pi & DHT 11 Sensor
Internet Connection
Thonny IDE &Patch Cords
Procedure :-
1. Switch On the Kit & Make Connections as shown below
2. Go to /home/pi/MI/pythonprograms/thingspeak/thingspeakdhtworking.py
3. Right click the thingspeakdhtworking.py folder and open it in Thonny
4. Make connections are per the below image
5. Connect DHT11 Sensor to GP4 of Raspberry Pi using Patch cord
6. You have to enter channel ID ( Channel Created in Thingspeak) and Writekey for
DHT11 Sensor ( to be Created in Things speak)
Visit www.thingspeak.com and log in your email & Password ( If Already Created an Account)
After successful Login , Go to Channels & Select my channel
Now Create a New Channel and Name it Temp & Hum & Fill the Description
Enter Fields & Name it Field 1 as Temperature & Field 2 as Humidity
After Entering the Related Fields save the settings.
Now you will be having the channel ID with you.
Now go to API Key and Select or Regenerate Fresh or New APIWrite API Key
Now After generating a New API Key , you have to enter the Channel ID and API Key
In the Program .
After Entering the API Key & Channel ID , Save the Python code ( thingspeakdhtworking.py)
Check you have made All connections
Now Run thingspeakdhtworking.py Program in Thonny IDE
You can see the Temperature & Humidity readings at the bottom of Thonny
Now you Log On to Thingspeak website by Entering your email id and password
Select my channel and open the Temp & Hum
Now you can see the Graph of Temp and Humidity
Note : If you enter any Old API ID , you can see the Temperature and Humidity at the
Bottom of Thonny IDE , and also shows “Connection Failure”
Result : -