Robotic Makers Level 2 PDF
Document Details
IECD - Bharathidasan University
Tags
Summary
Robotic Makers Level 2 is a practical guide on robotics and Raspberry Pi. It covers Raspberry Pi introduction, applications, hardware features, peripherals, operating system installation, and programming, along with practical exercises. Designed for secondary school students and beyond, it explains concepts for building robots through programming.
Full Transcript
ROBOTIC MAKERS LEVEL - 2 Tie - Up Industry IECD - Bharathidasan University The University, named after the revolutionary Tamil Poet Bharathidasan was established in the year 1982. The University got recognized by UGC under 2f and 12B on 26.11.1984.Celebrated its silver jub...
ROBOTIC MAKERS LEVEL - 2 Tie - Up Industry IECD - Bharathidasan University The University, named after the revolutionary Tamil Poet Bharathidasan was established in the year 1982. The University got recognized by UGC under 2f and 12B on 26.11.1984.Celebrated its silver jubilee in the year of 2007, this young and vibrant institution continues to make rapid strides in the fields of higher Education, Research and Extension activities. The University established Institute for Entrepreneurship and Career Development (IECD) during 2004 – 2005 as self supportive system with its outstanding expertise committed to connect the instructions, industries and organizations to reach students, employed and unemployed youth and adults for their bright future either in terms of Entrepreneurship or Career Development. For rehabilitating various types of beneficiaries, it offers many skill development Certificate / Diploma / Advances Diploma / PG Diploma programmes through on campus and off campus in Tamil Nadu. The students who successfully completes ROBOTICS programme deserve to get the University Certificate. AUTOBOTS Autobots was started with the prime vision of “Inspire learning, triggers thinking and enhances creativity to build young innovators” in the modern students community. We are a trusted provider of co-curricular and out of classroom learning to schools and colleges students. Our purpose is to enhance the lives of young students through experiences that inspire. By partnering with teachers and group leaders, from planning through to review, we help to define and target their learning objectives to become a creative designer of modern world systems. We are committed to helping schools, youth groups and individuals get the most creativity from our innovation programs, and we are raising the bar to provide the very best learning experiences. We believe that by working in partnership with schools and teachers, we can buildinnovative minds in students and helping to influence the futures of thousands of young people every year. www.autobotsindia.com | +91 9944117961 | [email protected] Copyright © 2024 by Autobots,Tamilnadu, India PREFACE “Learning gives Creativity, Creativity leads to thinking Thinking provides Knowledge, Knowledge makes you great” --A famous saying by the great leader, Dr.A.P.J.Abdul Kalam Children of today are the leaders of tomorrow and discovering innovative ideas is a very important weapon to build the future leaders. Innovation can be achieved through STEAM (Science-Technology-Engineering- Arts- Mathematics) based learning methodologies. “World is in your hands, you can control it!” Controlling the world through Robotics and its combinations will make the world pretty fantastic. Most Trustworthy thing of the world is money; we are crediting and debiting it at anytime and anywhere from the world. Think how it is possible? It is possible by technology advancements. To keep the world in your hands it is not necessary that you have to be an engineer… “Being a School Student you can control the world”. You can make it happen by using Robotics with Raspberry Pi development boards. Automation and Artificial Intelligence plays a very important role in this modern world. You can Control your Home, Office, Street, City, District from anywhere in the world through Internet. You can Access your Lights, Fans, Air conditioners at your home from anywhere in the world. You can monitor your homes using live surveillance cameras. You can get immediate intimations on mobile phones on theft or presence of strangers at your homes. You can develop Animation videos and Gaming platforms by your own. You can make the impossible things for humans as possible things by designing and developing Robots using Raspberry Pi with machine learning language python. Today a Reader, Tomorrow a Leader TABLE OF CONTENTS 1. Raspberry Pi an Introduction 1 1.1 Introduction to Raspberry pi 1 1.2 Applications of Raspberry Pi 2 1.3 Hardware features 3 2. Inbuilt peripherals of Raspberry Pi 5 2.1 System On chip 5 2.2 General Purpose Input Output pins 6 2.3 Analog to Digital Conversion 7 2.4 How Raspberry Pi differs from other boards 8 3. OS installation & Programming 10 3.1 OS Installation Process 10 3.2 Working with Linux Commands 13 3.3 Installing the IDLE in Raspberry Pi 15 3.3 Programming on Raspberry Pi 15 3.4 Python programs 17 4. Interfacing of Input and Output Devices 20 4.1 IO devices Interfacings 20 4.2 Interfacing Sensors 21 4.3 Controlling devices using Raspberry Pi 22 4.4 Raspberry Pi Communication with Real world 23 5. Internet of Things 26 5.1 Introduction to IOT 26 5.2 IP address 27 5.3 Animation and Game Development using Scratch 29 Practical - 1 1. Write a program to blink an LED 33 2. Write a program to control an LED using Switch 35 3. Write a program to control a DC motor 37 4. Write a program to change the direction of a motor 39 5. Write a program to detect object using sensor 41 6. Write a program to interface Android phone 43 7. Write a program to send SMS using GSM 45 8. Write a Program to receive SMS using GSM 47 9. Server client operation using Raspberry pi 49 10. Send Emails using Raspberry Pi 51 11. Sending Email with image attachments using Rpi 53 12. Camera Interface with Raspberry Pi 55 Practical - 2 1. Smart gas leakage intimation using Raspberry Pi 58 2. Automatic Street Light Control System 60 3. Motion detection of Animals at residence area 62 4. Smart Agri - tech using IOT 64 5. Fire Accident Detection and intimation using RPi 66 6. Home Automation using Bluetooth communication 68 7. Theft intimation of the vehicle over SMS 70 8. Automatic Door Opening System 73 9. Recording of videos using Camera 75 10. Security system using Camera Module 77 11. IOT and Raspberry Pi based E-mail/SMS alert to avoid crime 79 12. Smart Home using Raspberry Pi 82 RASPBERRY PI - UNIT 1 AN INTRODUCTION 1.1 Introduction to Raspberry Pi Raspberry Pi is a credit-card sized computer manufactured and designed in the United Kingdom by the Raspberry Pi foundation with the intention of teaching basic computer science to school students. This board can also be used to build more electronic projects. Raspberry Pi is a single board computer. It is smaller in size like a credit card, hence it is also known as Credit-Card Sized Computer. The CPU of a computer can be replaced by Raspberry Pi board, so it is also called as tiny computer. Replace your CPU by Raspberry Pi board There are different models of Raspberry Pi boards available. They are Model A, A+, B, B+. In model A there is no USB port, In model B there are 2 USB ports, and in model B+ there are 4 USB ports available. Model A Model B Model 3 B+ Pi 4 ROBOTIC MAKERS LEVEL - 2 1 REASON BEHIND THE NAME RASPBERRY – Reference to a fruit name. (Lot of our electronic gadgets are named as fruit names like Apple, Apricot, Black berry, Tangerine, etc) PI - Refers to the Python programming language. Since python is most commonly used fro programming. 1.2Applications of Raspberry Pi Raspberry Pi is a versatile board with many applications in several areas. Raspberry pi can be used by students, game developers, animation developers, electronic hobbyist etc. Some of the major uses of Raspberry pi are given below, Low cost Personal Computers Raspberry Pi boards along with Monitor, Keyboard and mouse connected, it can form Desktop personal computers with low cost. Animation and Game development Raspberry Pi board can be used to develop animation videos and gaming platforms by using simple software called as Scratch. Electronic Gadgets Raspberry Pi boards can be turned into low cost smart tablets (TABS) by interfacing compact touch screen modules with it. 2 ROBOTIC MAKERS LEVEL - 2 Robotics Many Smart Robots can be built by using raspberry Pi boards. The built robot can be controlled by programming on it. Automation Systems Automation systems can be developed by interfacing sensors, cameras, and communication devices. The automated systems can be implemented at Industries, Homes, Educational institutions, Corporate Offices, etc., 1.3 Hardware Features Out of all the different models of Raspberry Pi board, Model Pi 4 and Pi 5 are the latest models with more advanced Features. ROBOTIC MAKERS LEVEL - 2 3 Peripherals inside the Raspberry Pi This is a Broadcom BCM2835 System on a Chip (SoC) that’s made up of an ARM Central Processing Unit (CPU) ARM and Graphics processing unit (GPU). The CPU handles all the computations that make a computer work and the GPU handles graphics output. It is a standard 3.55-millimeter jack for connecting audio output devices Audio out such as headphones or speakers with raspberry pi. It is serial port which is used to connect keyboard, Mouse, Monitors, Pen drives USB with raspberry pi. 4 USB ports will be present. It is a High Definition Multimedia Interface Port. HDMI port is used to HDMI connect Monitors, Televisions, and Projectors with Raspberry Pi for display purposes. This is a 5v Type C power connector, Power using which we can give power supply to Raspberry Pi board. Ethernet port is used to connect LAN Ethernet cables, using which the Pi board can be connected to Internet. An SD card with an operating system SD card slot (OS) installed is required for booting the device 4 ROBOTIC MAKERS LEVEL - 2 INBUILT PERIPHERALS UNIT 2 OF RASPBERRY PI 2.1 System On chip (SOC) SOC is abbreviated as System On Chip. System – System refers to complex electronic circuit assembly. Chip - All the components of the system are squeezed together on a single integrated circuit. A SOC is an electronic integrated circuit that contains various electronic components designed to work together to achieve a common goal. SOC in Raspberry Pi - ARM ARM Stands for Advanced RISC Machines. ARM is a type of processor which can do multiple tasks at a time. ARM Processors are extensively used in cellular phones, computers, digital cameras, set-top boxes and also in many electronic gadgets. ARM processors have wide applications because they are Smaller in size. Consumes low power. It can do multiple tasks at a time. ROBOTIC MAKERS LEVEL - 2 5 2.2 General Purpose Input Output (GPIO): GPIO stands for GENERAL PURPOSE INPUT /OUTPUT. GPIO is set of pins present in the integrated circuits. It does not have a specific function. The user has to assign the pin state as input or output. Output devices can be controlled (turned ON/OFF) using GPIO pins. There are 40 pin outs in the raspberry pi. Out of which, 26 pins are used as GPIO pins. Raspberry Pi has 26 GPIO pins which act as switches It gives out 3.3v when set to high. It gives out 0v voltage when set to low. 6 ROBOTIC MAKERS LEVEL - 2 2.3. Analog to Digital Conversion What is Analog signal? Analog Signal is a continuous signal which varies continuously with respect to time. Example: Light Waves, Sound Waves. What is digital Signal? Digital signals are discrete time signals. It is represented as 0 or 1. Example: Digital Clocks, Digital Watches. How Analog-to-digital conversion takes place: An analog-to-digital converter (ADC) is a system that converts an analog signal, such as a sound picked up by a microphone or light, into a digital signal. An analog signal can be any physical quantity present in the real world like Light, Heat, Temperature, Pressure, Humidity, Air, Moisture, Etc. These analog signals will be converted as digital signals as either 0’s or 1’s. ROBOTIC MAKERS LEVEL - 2 7 2.4 How Raspberry pi board differs from other boards? Raspberry Pi and ARDUINO are the two Single Board Computers which are used commonly. Raspberry pi board has an inbuilt Microprocessor and the ARDUINO board has an inbuilt Microcontroller. Here is the difference between a micro processor and a micro controller. Microcontroller: Micro Controller is a small computer on a single chip. It performs specific task at a time. Some of the popular microcontrollers are 8085, ATMEGA328P, PIC. IO ports, RAM, ROM, Timers, and Counters will be present inside the single chip. A microcontroller can be called the heart of embedded system. Microcontrollers are used in traffic signals, Washing machines, Air conditioners and many more home appliances. Microprocessor: Microprocessor is a Chip on a System. It can perform multiple tasks in a given time. Some examples of microprocessor are Pentium, I3, I5 and ARM etc. In Microprocessors IO ports, RAM, ROM, Timers, Counters are needed to be connected externally to the system. Microprocessors are used in Desktop Computers, Laptops, Mobile Phones and all the electronic gadgets. The major differences between the Raspberry Pi board and an ARDUINO boards are listed below. 8 ROBOTIC MAKERS LEVEL - 2 VS FEATURE RASPBERRY PI ARDUINO CPU type Microprocessor Microcontroller Connectivity USB, Ethernet, HDMI, Audio None Multitasking Yes No GPIO pins 26 Digital pins 14 Digital / 6 Analog pins USB Four One Operating System Linux Support any kind of OS RAM Upto 8 GB 2KB Disk Depends on SD Card 32KB Speed 700 MHz 16 MHz Power consumption 3.5W 0.25W Input Voltage 5V 7-12V Minimum Current 700mA 42mA ROBOTIC MAKERS LEVEL - 2 9 OS INSTALLATION & UNIT 3 PROGRAMMING 3.1 OS Installation Process Install Raspberry Pi OS using Raspberry Pi Imager Raspberry Pi Imager is the quick and easy way to install Raspberry Pi OS and other operating systems to a microSD card, ready to use with your Raspberry Pi. Download and install Raspberry Pi Imager to a computer with an SD card reader. STEP 1: FORMATTING SD CARD 1. To format the SD card, open the Imager app on your PC. 2. Ensure that your SD card storage is minimum of 32GB. 3. This specific task can only be completed using the Imager app. 4. Upon launching the software, you will be prompted to choose the device. 5. Select the model of your Raspberry Pi, then proceed to select the operating system and click on the “Erase” option. 10 ROBOTIC MAKERS LEVEL - 2 6. Next, choose the SD card in the storage options and click “Next”. 7. Finally, confirm by selecting “Yes” to erase or format the SD card. STEP 2: DOWNLOADING OS 1. After formatting is complete, it is time to select the device. 2. Choose the model of your Raspberry Pi, then select the operating system and click on “Raspberry Pi OS (other). 3. “ You will then be prompted to choose from various OS options. 4. Choose “Raspberry Pi OS full (64-bit),” which will require 2.7GB of storage. 5. Finally, select the OS, choose the device, and press “Next” when prompted. 6. The imager will then begin writing the OS to your SD card. ROBOTIC MAKERS LEVEL - 2 11 7. Upon completion of the writing process, safely remove the SD card from the computer. 8. Now insert the SD card into the Raspberry Pi. STEP 3: BOOTING ON RASPBERRY PI BOARD 1. Connect the board with all the necessary accessories to install and run an operating system. 2. Connect the display – Connect the monitor to the raspberry pi board using HDMI to VGA converter. 3. Connect your Ethernet cable from the Router to the Ethernet port of Pi. 4. Connect your USB mouse and keyboard to one of the USB ports on the Pi 5. Connect the power adaptor to the Pi and switch ON the power supply. 6. Raspbian will run through its installation process. It will take few minutes. 7. When the installation process has completed, the Raspberry Pi configuration menu will load. 8. In the configuration menu, you are able to set the time and date, and create users, etc. 9. If you are using wifi, configure wifi connection by selecting the appropriate wifi and password. 12 ROBOTIC MAKERS LEVEL - 2 10. Select the web browser whether chromium or Firefox in the displayed option. Then restart the system. 11. Once restart is completed it will load the desktop and all other applications. 3.2 Working with Linux Commands On the Raspberry Pi GUI Workspace, Terminal window will be present. Using this Terminal Window, You can work with Linux commands to operate your system. Some of the most common data and file handling commands are listed below. COMMANDS DESCRIPTION SYNTAX date Displays the current date date Clears previous commands on the clear clear terminal window. cal Displays the current month calendar cal year sudo Gets the power of super user sudo reboot Reboots the system immediately sudo reboot poweroff Shutdowns the system immediately poweroff sudo idle Opens the python programming shell sudo idle ls Lists the contents of the file ls cd Changes the current working directory cd filename pwd Displays the address line of present pwd working directory mkdir Make directory creates a new directory mkdir filename ROBOTIC MAKERS LEVEL - 2 13 rmdir Remove directory is used to remove/ rmdir filename delete a specified directory mv Moves a file from one place to another mv ~/dir1/filename.txt ~/dir2/ cp Makes a copy of the files cp ~/dir1/filename.txt ~/dir2/ touch Touch is used to create a new file touch filename.txt cat Lists the content of the file cat filename head Displays the beginning lines of the file head filename tail Displays the ending lines of the file tail filename man Opens the guidelines of the specified man command commands info Displays the information info command about the command tree Displays the current directory and its tree sub directories raspi-config Opens the configuration setup menu sudo raspi-config ifconfig Checksthe status of wireless sudo ifconfig connections apt-get update Updates the version of Raspberry pi sudo apt-get update apt-get upgrade Upgrades the software packages sudo apt-get upgrade gcc To compile C coding gcc –o filename filename.c python To compile python coding python filename.py Note: After typing the commands press Enter to execute the command. 14 ROBOTIC MAKERS LEVEL - 2 3.3 Installing the IDLE3 in raspberry pi This OS Contain the advanced version of python3 in itself. But we need to download “IDLE 3”. To run the Python. It was a very simple one to download and run it. Using Linux commands to download. 1. Open command terminal from toolbar in desktop. 2. Now type the following command, “Sudo apt-get install Idle3”. 3. Once you finish typing press the Enter key to run the command. 4. After download it will asks permission to install. Now you need to press ‘Y’ for allow. 3.4 Programming on Raspberry pi Raspberry Pi board supports programming on C Language and Python Language. On comparing, Python consumes less programming lines than C. Python avoids using of Header files, Main functions, Curly braces and Return Functions. Therefore number of lines will be reduced and will be easier than programming on C Language. To Execute the Python Programming, Open Python programming platform Python Shell in Raspberry Pi. Python shell can be opened by two ways. 1. Go to Terminal Window and type the command sudo idle then press Enter 2. Go to Raspberry pi menu --> Programming --> Python IDE ROBOTIC MAKERS LEVEL - 2 15 In the python shell, go to File --> New File, to open a new untitled window. Type the program on this untitled window, save it. Now execute the program by choosing Run --> Run Module. Outputs will be obtained in the Python shell window. 16 ROBOTIC MAKERS LEVEL - 2 3.5 Python Programs: 1. Program to understand the IF ELSE loop: Think about Exam Results… If your mark is above the pass mark your result is pass else your result is fail. From this simple concept you can understand the working of IF ELSE loop. The if-else statement is a conditional statement, when it is satisfied, part of code will be executed. Program: mark = int(input(“ENTER THE MARK”)) Output: if(mark >=50): ENTER THE MARK: 50 print(“RESULT IS PASS”) RESULT IS PASS else: print(“RESULT is Fail”) 2. Program to understand the While loop: From the if-else conditional program, the result can be obtained for only one student. To know the results of many students you have to use while loop. While Loop continuously executes the program until the given condition is true. Output: Program: ENTER THE MARK 65 while(1): Result is PASS ENTER THE MARK 87 mark = int(input(“ENTER THE MARK “)) Result is PASS ENTER THE MARK 95 if(mark > 50): Result is PASS print(“Result is PASS”) ENTER THE MARK 35 Result is FAIL else: ENTER THE MARK print(“Result is FAIL”) (Execution Continues) ROBOTIC MAKERS LEVEL - 2 17 3. Program to understand Nested If Else loop: Nested if else Statement is used for decision making. It will run the body of code only when IF statement is true. If the statement is false, then compiler will execute the Else statement. Program: while(1): Output: ENTERCLASS 7 Class=int(input(“ENTERCLASS ”)) LEVEL 1 if(Class == 7): ENTERCLASS 8 print(“LEVEL 1”) LEVEL 2 elif(Class == 8): ENTERCLASS 9 print(“LEVEL 2”) LEVEL 3 elif(Class == 9): ENTERCLASS 10 print(“LEVEL 3”) WRONG else: ENTERCLASS print(“WRONG”) (Execution Continues) 4. Program to understand for loop: For loop is used to execute the program for given/specified number of times. Program: Output: B name=”BETA” E for i in name: T print(i) A By Understanding the operations of loops, you can develop many python codes for simple testing. Some of the basic python codes are given below for your practice. 18 ROBOTIC MAKERS LEVEL - 2 Program to find whether the given year is leap year or not. Program: year=int(input(“enter the year : ”)) Output: if(year%4==0): enter the year : 2020 print(“LEAP YEAR”) LEAP YEAR else: print(“NOT A LEAP”) Program to find the greater of two numbers Program: number1=int(input(“enter the number1: ”)) number2=int(input(“enter the number2: ”)) Output: if(number1>number2): enter the number1: 8 print(“number1 is greater”) enter the number2: 15 if(number1 Programming --> Scratch. Scratch Software Environment is given below, ROBOTIC MAKERS LEVEL - 2 29 Options to work with sprites and to develop Scripts (Dialogue) for sprites using block of codes on Scratch, Drag and drop the block codes inside the script space individually for all the sprites. 30 ROBOTIC MAKERS LEVEL - 2 Options to change the stage backgrounds, Sound effects and Costumes on scratch tool is, After making all the organization works, the animated Video can be played by pressing the start option on the stage. Now your animated video is ready. You can make animated movies and develop game platforms by using the Scratch tool present in the Raspberry Pi ROBOTIC MAKERS LEVEL - 2 31 PRACTICAL 1 32 ROBOTIC MAKERS LEVEL - 2 1. Write a program to blink an LED In this experiment we are going to develop a program code to make an LED blink. This program will allow the LED to ON and OFF continuously. The blinking time can be varied by changing the duration of delay function. Materials Required: R-Pi board LED Resistor Bread board Jumper wires import time import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) LED=13 Program: GPIO.setup(LED,GPIO.OUT) while True: GPIO.output(LED,True) print(“ON”) time.sleep(1) GPIO.output(LED,False) print(“OFF”) time.sleep(2) Procedure: In python shell click File -->New Window and type the above python coding. After typing the code click Run --> Run module option to execute the program. Connect the LEDs positive terminal to the 13th pin of Raspberry pi board. ROBOTIC MAKERS LEVEL - 2 33 Connect the negative terminal of the LED to the GND pin. Now you can see the led blinks as per the delay. Circuit : Try it: Connect two LEDs and glow it alternatively (When 1st LED is ON, 2nd LED should be turned OFF and vice versa) Which part of the program should be changed to increase the blinking time of LED? Ans:.................................................................... 34 ROBOTIC MAKERS LEVEL - 2 2. Write a program to control an LED using switch In this experiment we are going to control output device LED using an input device switch. When switch is pressed LED will be turned on and if not, LED will be turned off. Instead of LEDs you can also use Buzzers. Materials Required: R-Pi LED Resistor Bread board Switch Jumper wires import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) LED=40 SWITCH=38 Program: GPIO.setup(LED,GPIO.OUT) GPIO.setup(SWITCH,GPIO.IN) while True: if(GPIO.input(SWITCH)): GPIO.output(LED,True) else: GPIO.output(LED,False) Procedure: In python shell click File --> New file and type the above python coding. After typing the code click Run --> Run module option and execute the program Connect the LEDs positive terminal to the 40th pin of board and negative terminal to GND. Connect one end of the input device Switch to the 38th pin of RPi board ROBOTIC MAKERS LEVEL - 2 35 and other end to the ground thorugh resistor. Now if you press the switch, the LED will glow and when you release the switch the LED will get turn OFF. Circuit : Try it: Control two LEDs using one switch. Which is pressed both the LEDs should be turned ON. When Push button is pressed: LED is......(On/Off) When Push button is not pressed: LED is............(On/Off) Use SPST switch instead of push button and see the output 36 ROBOTIC MAKERS LEVEL - 2 3. Write a program to control a DC Motor In this experiment we are going to turn ON/OFF the DC motor. Turing ON the Dc motor makes the motor to rotate. Dc motor will have two terminals they are terminal 1 and terminal 2. Motor should be connected to the raspberry pi board using motor drivers. Materials Required: R-Pi board DC motor Motor Driver Wires import time import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) pin1=10 pin2=11 GPIO.setup(pin1,GPIO.OUT) Program: GPIO.setup(pin2,GPIO.OUT) while True: GPIO.output(pin1,True) GPIO.output(pin2,False) print(“Motor ON”) time.sleep(2) GPIO.output(pin2,False) GPIO.output(pin1,False) print(“Motor Off”) time.sleep(2) Procedure: In python shell click File --> New file and type the above python coding. After typing the code click Run --> Run module option to execute the program. ROBOTIC MAKERS LEVEL - 2 37 Connect the motor to the raspberry pi board using motor driver with respect to the circuit given below Connect the DC motor’s both pins to the motor driver’s output pin and the input pin IN1 of motor driver to the 10th pin of raspberry pi board, and the input pin IN2 of motor driver to the 11th pin of raspberry pi board. Also connect the battery to the Power supply pins of the motor driver boards. After giving all connections now you can see that Dc motor will be turned ON for some time and it will be turned OFF after sometime. Circuit : Try it: Turn ON the DC motor for 10seconds and turn OFF the motor for 5 seconds of delay time. Which loop can be used to turn ON/OFF the motor simultaneously for 5 times? Ans:............................................................... 38 ROBOTIC MAKERS LEVEL - 2 4. Write a program to change the direction of a motor In this experiment we are going to control the direction of rotation of the DC motor. Here we are going to make the DC Motor run in Forward and reverse direction with respect to the commands given by the user. Materials Required: R-Pi board DC motor Motor Driver Wires Program: import time def off(): import RPi.GPIO as GPIO GPIO.output(pin2,False) GPIO.setwarnings(False) GPIO.output(pin1,False) GPIO.setmode(GPIO.BOARD) time.sleep(2) pin1=10 while True: pin2=11 a=int(input(“\nFORWARD =1 GPIO.setup(pin1,GPIO.OUT) REVERSE=2 OFF=O\n”)) GPIO.setup(pin2,GPIO.OUT) if(a==1): def forward(): forward() GPIO.output(pin1,True) print(“\n Motor Forward”) GPIO.output(pin2,False) elif(a==2): time.sleep(2) reverse() def reverse(): print(“\n Motor Reverse”) GPIO.output(pin2,True) elif(a==0): GPIO.output(pin1,False) off() time.sleep(2) print(“\n Motor off”) ROBOTIC MAKERS LEVEL - 2 39 Procedure: In python shell click New --> New file and type the above python coding. After typing the code click Run --> Run module option to execute the code. Connect the DC motor’s both pins to the motor driver’s output pin and the input pin IN1 of motor driver to the 10th pin of raspberry pi board, and the input pin IN2 of motor driver to the 11th pin of raspberry pi board. Also connect the battery to the Power supply pins of motor driver board. After giving the connections, you can control the direction of the DC motor by giving commands. Circuit : Try it: Connect two motors and make both the motor to rotate in Forward and Reverse directions simultaneously. When input is F, Output is............................. When input is R, Output is............................ 40 ROBOTIC MAKERS LEVEL - 2 5. Write a program to detect object using sensor In this experiment we are going to detect the object using Sensor. Here we use the Infra red (IR) sensor to detect the object. Once the object is detected, an LED indication will be there. This object detection can be used to identify the presence of any objects or persons at prohibited areas. Materials Required: R-Pi board LED IR Sensor Wires import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) led=29 irsensor=36 GPIO.setup(led,GPIO.OUT) Program: GPIO.setup(irsensor,GPIO.IN) while True: if(GPIO.input(irsensor)==0): GPIO.output(led,True) print(“Object detected”) else: GPIO.output(led,False) print(“Object not detected”) Procedure: In python shell click New --> New file and type the above python coding. After typing the code click Run --> Run module option to execute the code. Connect the positive pin of the sensor to Pin 2 of Pi board And connect the negative pin of the sensor to the any GND pin of the Pi board. Connect the sensors digital output pin to the pin of the 36th Pi board. ROBOTIC MAKERS LEVEL - 2 41 Connect the positive terminal of LED to the 29th pin and negative terminal of LED to any GND pin of the Pi board. Now you can see whenever the senor senses any objects LED will be turned ON. Circuit : Try it: Make the object detection identification through a Buzzer instead of LED. When the sensor detects objects, indication should be given through Buzzer. When IR sensor is HIGH, LED output is.......... When IR sensor is LOW, LED output is.......... 42 ROBOTIC MAKERS LEVEL - 2 6. Write a program to Interface Android phone In this experiment we are going to control the lights (Turing ON or OFF) using android mobile phones through Raspberry pi boards and Bluetooth module. For this an android mobile based application (App) is required. Materials Required: R-Pi Bluetooth Phone LED Resistor Jumper wires Program: import time import serial import RPi.GPIO as GPIO led=12 GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(led,False) ser=serial.Serial(“/dev/ttyS0”,baudrate=9600,timeout=1) while True: time.sleep(1) x=ser.read(5).decode().strip() print(x) if (x==”on”): GPIO.output(led,True) print(“led on”) elif(x==”off”): GPIO.output(led,False) print(“led off”) Note: Enabling Serial Port: Type the command sudo raspi-config. In the configuration window enable the serial port and reboot your Raspberry Pi system using the command sudo reboot. ROBOTIC MAKERS LEVEL - 2 43 Procedure: Make the serial port enabled on your Raspberry Pi. In python shell click File --> New file and type the above python coding. Execute the program using Run --> Run module option without any errors. Now interface the Bluetooth module to the RPi by connecting the RX pin of the Bluetooth to the 8th pin of RPi, TX pin to the 10th pin of RPi, GND to any of the GND pin and finally connect the 5V to the 2nd pin of the RPi. Connect the positive terminal of the LED to the 12th pin of the R.Pi board and negative terminal to any GND pin. After making necessary connections, pair the android mobile with the R.PI. Now you can control the led by sending command from the android mobile using app. Circuit : Try it: Turn ON or Turn OFF the fan using mobile phones through Bluetooth module. What happens to the Light, when you transmit the data as “Of”? Ans:......................................................... 44 ROBOTIC MAKERS LEVEL - 2 7. Write a program to Send SMS using GSM In this experiment we are going to send message from Raspberry Pi to the mobile phone using GSM. This program will allow one to send the text message to the specified user mobile number given in the program. Materials Required: R-Pi GSM Phone Sim Jumper wires Program: import serial print(rcv.decode()) import time time.sleep(1) recipient = “82200*****” ser.write(b’AT+CMGS=”’ + content = “ROBOT WILL RULE recipient.encode() + b’”\r\n’) THE WORLD” rcv = ser.read(10) ser = serial.Serial(“/dev/serial0”, print(rcv.decode()) baudrate=9600, timeout=5) time.sleep(1) ser.write(b”AT\r”) rcv = ser.read(10) ser.write(content.encode() + b’\ print(rcv.decode()) r\n’) time.sleep(1) rcv = ser.read(10) print(rcv.decode()) ser.write(b’ATE0\r\n’) rcv = ser.read(10) ser.write(b”\x1A”) print(rcv.decode()) time.sleep(1) for i in range(10): rcv = ser.read(10) ser.write(b’AT+CMGF=1\r\n’) print(rcv.decode()) rcv = ser.read(10) ROBOTIC MAKERS LEVEL - 2 45 Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click New --> New Window and type the above python coding. After typing the code click Run --> Run module option to execute the code. Connect the RXD of the GSM to 8th pin of Pi, TXD of the GSM to 10th of Pi and finally connect GND of the GSM to any one GND of Pi. Insert the SIM card to the back side of the GSM module and connect the Vcc pin of GSM to the 5V pin of RPi After connecting you can see the message received from the Pi to your respective mobile number. Circuit : Try it: Send a message “More Traffic, Take Diversion” through GSM to any specified mobile number. How many times the message “Robot will rule the world next” will be sent to the specified mobile number? Ans:.................................... 46 ROBOTIC MAKERS LEVEL - 2 8. Write a program to Receive SMS using GSM In this experiment we are going to receive message in RPi from the mobile phone using GSM. This program will allow one to receive the text message from the mobile number in the raspberry pi board. Materials Required: R-Pi GSM Phone Sim Jumper wires Program: import serial import time def receive_sms(): ser = serial.Serial(“/dev/serial0”, baudrate=9600, timeout=5) ser.write(b”AT\r”) print(“AT Response:”, ser.read(10).decode()) time.sleep(1) ser.write(b’ATE0\r\n’) print(“ATE0 Response:”, ser.read(10).decode()) time.sleep(1) ser.write(b’AT+CMGF=1\r\n’) print(“AT+CMGF Response:”, ser.read(10).decode()) time.sleep(1) ser.write(b’AT+CNMI=2,2,0,0,0\r\n’) print(“AT+CNMI Response:”, ser.read(10).decode()) time.sleep(1) try: while True: if ser.in_waiting > 0: rcv = ser.readline() print(“Received message:”, rcv.decode().strip()) except KeyboardInterrupt: print(“Keyboard interrupt detected. Exiting...”) ser.close() receive_sms() ROBOTIC MAKERS LEVEL - 2 47 Procedure: To open python shell, go to Terminal Window -->Type sudo idle command. In python shell click New --> New Window and type the above python coding. After typing the code click Run --> Run module option to execute the code. Connect the RXD of the GSM to 8th pin of Pi, TXD of the GSM to 10th pin of Pi and finally connect GND of the GSM to any one GND of Pi. Insert SIM card to the back side of the GSM module. Connect the Vcc pin of GSM to the 5V pin of RPi. Now send any text message from the sender mobile phone. It will be received on the Raspberry Pi board. Circuit : Try it: If any message is received, produce an intimation using buzzer. Write the program to receive a message whenever someone enters in the exam zone or prohibited area (Use sensors) 48 ROBOTIC MAKERS LEVEL - 2 9. Server Client Operation using Rasperry Pi In this experiment we are going to do server client operation using Raspberry pi. Here raspberry pi act as a server and normal personal computers can act as client systems. By using one server Raspberry pi board we can have many client systems. This process can be done by using putty software. Materials Required: Procedure: On R.pi board connected system type the command sudo ifconfig and note down the internet (inet) address The inet address will be in the format of N.N.H.H for example 192.168.1.5 In the normal personal computer --> Open putty software and type the obtained IP (inet) address ROBOTIC MAKERS LEVEL - 2 49 Set the port as 22 default port number. On the category panel, select the connection type as SSH. Select X11 forwarding option -- > a dialog box opens, in that, Enable the X11 forwarding option and click Open. Now terminal window will be opened on the normal computer. Login with the user name and password to continue working with Linux commands and other functions as like Raspberry Pi system. Try it: Execute a program (which is saved in the Raspberry pi system) on a normal PC acting as a client system using Server client operation. Try with other Linux commands in the normal system and see what the output is? Which software should be used for sever client operations? 50 ROBOTIC MAKERS LEVEL - 2 10. Send E mails using Rasperry Pi In this experiment we are going to send email from R.Pi. Without using Gmail, a mail can be sent from the raspberry Pi board to any mail accounts. A simple mail Transfer protocol (SMTP) is used for this operation. Materials Required: RPi Board with Internet connection Procedure: In python shell click New --> New file and type the below python coding. import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from time import sleep # Email configuration sender_email = ‘[email protected]’ receiver_email = ‘[email protected]’ password = ‘beqh fpew ekho cadg’ # Gmail App generated Password subject = ‘Test Email from Raspberry Pi’ body = ‘This is a test email sent from a Raspberry Pi using Python.’ def send_email_with_body(num_turns): try: for i in range(num_turns): # Create a multipart message and set headers message = MIMEMultipart() message[‘From’] = sender_email message[‘To’] = receiver_email message[‘Subject’] = subject ROBOTIC MAKERS LEVEL - 2 51 # Add body to email message.attach(MIMEText(body, ‘plain’)) # Connect to the SMTP server (Gmail in this example) server = smtplib.SMTP(‘smtp.gmail.com’, 587) server.starttls() # Login to the email account server.login(sender_email, password) # Send the email server.sendmail(sender_email, receiver_email, message.as_string()) # Close the SMTP connection server.quit() print(f’Email with body text sent successfully! Turn {i+1}’) sleep(2) # Wait for 2 seconds before sending the next email except Exception as e: print(f”Error sending email: {e}”) # Get the number of turns from the user try: num_turns = int(input(“Enter the number of times you want to send the email: “)) send_email_with_body(num_turns) except ValueError: print(“Please enter a valid number.”) Important: In order to enable the Gmail server to send emails through RPi, you need to follow some steps. Please watch the video attached to this bar code for the procedure. Try with your mail id and send a test mail to your friend. 52 ROBOTIC MAKERS LEVEL - 2 11. Send E mails with image attachments In this experiment we are going to send files as attachments from Raspberry pi to the Gmail accounts. Materials Required: RPi Board with LAN connection Procedure: In python shell click New --> New file and type the below python coding. In order to enable the Gmail server to send emails through RPi, you need to follow some steps. Please watch the video attached to this bar code for the procedure. import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.application import MIMEApplication from time import sleep import os # Email configuration sender_email = ‘[email protected]’ receiver_email = ‘[email protected]’ password = ‘beqh fpew ekho cadg’ subject = ‘Test Email from Raspberry Pi’ body = ‘This is a test email sent from a Raspberry Pi using Python.’ # Directory where the file is located FILE_DIR = “/home/autobots/Pictures/ca” # File name of the file to be sent FILE_NAME = “test.txt” ROBOTIC MAKERS LEVEL - 2 53 def send_email_with_file(num_turns): try: for _ in range(1): # Create a multipart message and set headers message = MIMEMultipart() message[‘From’] = sender_email message[‘To’] = receiver_email message[‘Subject’] = subject # Add body to email message.attach(MIMEText(body, ‘plain’)) # Attach file to email file_path = os.path.join(FILE_DIR, FILE_NAME) with open(file_path, ‘rb’) as attachment: file_mime = MIMEApplication(attachment.read(), Name=os.path. basename(file_path)) message.attach(file_mime) # Connect to the SMTP server (Gmail in this example) server = smtplib.SMTP(‘smtp.gmail.com’, 587) server.starttls() # Login to the email account server.login(sender_email, password) # Send the email server.sendmail(sender_email, receiver_email, message.as_string()) # Close the SMTP connection server.quit() print(f’Email with file attachment sent successfully! Turn {_+1}’) sleep(2) # Wait for 2 seconds before sending the next email except Exception as e: print(f”Error sending email: {e}”) Try with your mail id and send a test mail with attachments to your friend. 54 ROBOTIC MAKERS LEVEL - 2 12. Camera Interface with Rasperry Pi In this experiment we are going to interface camera module with R.Pi which can be used to take pictures and videos. Raspberry Pi Board has CSI (Camera Serial Interface) interface to which we can attach Pi Camera module directly. Materials Required: R-Pi Pi camera Program: from picamera2 import Picamera2, Preview picam2 = Picamera2() picam2.start_preview(Preview.QTGL) #provide the directory to save the image picam2.start_and_capture_file(“/home/auto/capture/image.jpg”) picam2.stop_preview() picam2.close() Procedure: Make the camera interface to be enabled on the Raspberry Pi system. Go to terminal window and type the command as sudo raspi-config. A raspberry Pi configuration window will be opened. In that enable the camera interface option and reboot the system using sudo reboot command on terminal window. Connect the camera module with Raspberry Pi facing the blue side of the camera connector towards audio jack and the silver color side facing the HDMI port. Go to Terminal Window -->Type sudo idle command, python shell opens. ROBOTIC MAKERS LEVEL - 2 55 In python shell, click File --> New Window and type the above python coding. After typing the code click Run --> Run module to execute the program without any error. Now camera will be turned ON and picture will be captured. The captured image will be saved on the pictures folder. Circuit : Try it: Take 5 pictures one by one and save all the 5 images. You can make use of for loop. What is the pixel resolution of the camera we are using here? How many camera connectors are there in Raspberry Pi board? 56 ROBOTIC MAKERS LEVEL - 2 PRACTICAL 2 ROBOTIC MAKERS LEVEL - 2 57 1. Smart gas leakage intimation using Rpi In this experiment we are going to do smart gas leakage intimation system using Raspberry pi. Here gas leakage is detected using gas sensor and intimation is given using buzzer. This system can be used to avoid fire accidents at home due to gas leakage. Materials Required: R-Pi MQ2 sensor buzzer Jumper wires Program: import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) Gas_Sensor=23 Buzzer=24 GPIO.setup(Gas_Sensor,GPIO.IN) GPIO.setup(Buzzer,GPIO.OUT) while True: if not GPIO.input(Gas_Sensor): GPIO.output(Buzzer,True) else: GPIO.output(Buzzer,False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. In order to work with sensor we have to know the pins in Sensor. Generally sensors will have 4 pins in common they are positive pin (VCC), negative 58 ROBOTIC MAKERS LEVEL - 2 pin (GND), D0 and A0. Connect the VCC and GND of the sensor to the VCC and GND of the RPi board. Connect the D0 pin of the sensor to 23rd pin of the R.Pi board Connect the positive terminal of the buzzer to the 24th pin and negative terminal of the buzzer to the any one GND pin on the R.Pi board. Now whenever the sensor detects gas, it will give an intimation through buzzer. Circuit : Try it: Do the Smart alcohol detection system using MQ 3 sensor. Name the sensor used to detect Methane gas? Give an indication of gas leakage using LED instead of buzzer. ROBOTIC MAKERS LEVEL - 2 59 2. Automatic street light control system In this project we are going to make an LDR based light ON- OFF system. At night times, the lights can be turned ON automatically and turns it off during the day times. This project works on the principle of light intensities present at day and night times. This project saves power efficiently and wisely. Materials Required: R-Pi LDR LED Jumper wires Program: import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) LDR=10 LED=11 GPIO.setup(LDR,GPIO.IN) GPIO.setup(LED,GPIO.OUT) while True: if(GPIO.input(LDR)): GPIO.output(LED,True) else: GPIO.output(LED,False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. Connect the VCC and GND of the sensor to the VCC and GND of the RPi board. 60 ROBOTIC MAKERS LEVEL - 2 Connect the D0 pin of the sensor to 10th pin of the R.Pi board Connect the positive terminal of the LED to the 11th pin and negative terminal of the LED to the any one GND pin on the R.Pi board. Now you can see whenever the LDR senses or detects any light rays the LED will not glow and when there is no detection of light in the LDR module the LED will start to glow. Circuit : Try it: Do an Automatic Home light system. When human enters into the home light has to turn on, when nobody is there light has to turn off. When LDR senses light what happens to the LED? ROBOTIC MAKERS LEVEL - 2 61 3. Motion detection of animals at residence area In this experiment we are going to detect movement of animals using Raspberry pi. Here motion detection of animal is done by using PIR sensor. When PIR sensor detects the animals at the boundary between forest and residential area, intimation is given by using buzzer. Materials Required: R-Pi PIR buzzer Jumper wires Program: import RPi.GPIO as GPIO GPIO.setwarnings(False) import time GPIO.setmode(GPIO.BOARD) Buzzer=24 PIRSensor=23 GPIO.setup(Buzzer,GPIO.OUT) GPIO.setup(PIRSensor,GPIO.IN) while True: if(GPIO.input(PIRSensor)): GPIO.output(Buzzer,True) time.sleep(1) else: GPIO.output(Buzzer,False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. 62 ROBOTIC MAKERS LEVEL - 2 Connect the VCC and GND of the sensor to the VCC and GND of the RPi board. Connect the D0 pin of the sensor to 23rd pin of the R.Pi board Connect the positive terminal of the buzzer to the 24th pin and negative terminal of the buzzer to the any one GND pin on the R.Pi board. Whenever animal crosses the forest boundary, intimation will be given through buzzer. Circuit : Try it: Design a Motion Detection of human system. Whenever any human enters into the prohibited area give an indication using buzzer. Use IR sensor instead of PIR and detect the presence of animals PIR sensor senses which parameter? ROBOTIC MAKERS LEVEL - 2 63 4. Smart Agri Tech Using IoT In this experiment we are going to detect wetness of agricultural land using Raspberry pi. Here wetness of farmland is detected using soil moisture sensor.When the water content of the soil is less, the motor automatically turn on and waters the plant. Similarly, when the water content is more the motor remains in off state. Materials Required: R-Pi Soil moisture Pump motor Motor Driver Jumper wires Program: import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) Soil_Sensor=16 motor_pin1=10 motor_pin2=11 GPIO.setup(Soil_Sensor,GPIO.IN) GPIO.setup(motor_pin1,GPIO.OUT) GPIO.setup(motor_pin2,GPIO.OUT) while True: if(GPIO.input(Soil_Sensor)): GPIO.output(motor_pin1,True) GPIO.output(motor_pin2,False) else: GPIO.output(motor_pin1,False) GPIO.output(motor_pin2,False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. 64 ROBOTIC MAKERS LEVEL - 2 After typing the code click Run --> Run module option and execute the program. Connect the VCC and GND of the sensor to the VCC and GND of the R.Pi Connect the DO pin of the sensor to 16th pin, Positive pin to the 2nd pin, and negative pin to any GND pin of the raspberry pi board. Connect the water pump motor’s two terminals to the motor driver boards output pins. Connect the motor drivers input pins 1 & 2 to the 10th and 11th pin of the raspberry pi. Give external power supply to the motor driver board. Whenever the soil is dry, the water pump will be turned ON automatically, and on wetness it will be turned OFF automatically. Circuit : Try it: Print the status of the motor whether it is turned ON/OFF on the Raspberry Pi connected PC. What does the soil moisture sensor sense? When the motor will be turned on? ROBOTIC MAKERS LEVEL - 2 65 5. Fire accident detection and intimation using RPi In this experiment we are going to detect fire using raspberry pi. Fire is detected using Flame sensor. When sensor senses the fire it gives intimation using buzzer. This project can be used to avoid the accidents happening due to, the fire and many resource wastages can be prevented due to fire. Materials Required: R-Pi Flame sensor buzzer Jumper wires Program: import RPi.GPIO as GPIO GPIO.setwarnings(False) import time GPIO.setmode(GPIO.BOARD) Flame=10 Buzzer=3 GPIO.setup(Flame,GPIO.IN) GPIO.setup(Buzzer,GPIO.OUT) while True: if(GPIO.input(Flame)): GPIO.output(Buzzer,True) else: GPIO.output(Buzzer,False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. Connect the VCC and GND of the sensor to the VCC and GND of the RPi. 66 ROBOTIC MAKERS LEVEL - 2 Connect the D0 pin of the sensor to 10th pin of the R.Pi board Connect the positive terminal of the buzzer to the 3th pin and negative terminal of the buzzer to the any one GND pin on the R.Pi board. Now you can see how the sensor detects the fire and give intimation using buzzer. Circuit : Try it: Whenever fire is detected, pour the water on the fired place using water pump motor. When Flame sensor is HIGH, Buzzer output is=... When Flame sensor is LOW, Buzzer output is=..... How to print the message, that flame is detected? ROBOTIC MAKERS LEVEL - 2 67 6. Home Automation using Bluetooth communication In this experiment we are going to control (ON/OFF) the home appliances using android mobile phones. This can be done with the help of Bluetooth module and a Relay module. The controlling data will be sent by using some Bluetooth based Mobile applications (Apps). Materials Required: R-Pi Bluetooth Mobile Phone Bulb Relay Jumper wires Program: import time import serial import RPi.GPIO as GPIO led=12 GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(led,False) ser=serial.Serial(“/dev/ ttyS0”,baudrate=9600,timeout=1) while True: time.sleep(1) x=ser.read(5).decode().strip() #read 5 because that the “/dev/ttyS0” serial port is connecting pin print(x) if (x==”on”): GPIO.output(led,True) print(“led on”) elif(x==”off”): GPIO.output(led,False) print(“led off”) 68 ROBOTIC MAKERS LEVEL - 2 Procedure: After typing the code in the python shell and click Run --> Run module option and execute the program. Now interface the Bluetooth module to the RPi by connecting the RX pin of the Bluetooth to the 8th pin of RPi, TX pin of Bluetooth to the 10th pin of RPi, GND to any of the GND pin and finally connect the 5V to the 2nd pin of the RPi. Connect the bulb to the Raspberry Pi board through a relay module. 2 way relay has 4 pins Vcc, GND, R1 (relay 1) and R2 (relay 2). Make the relay and bulb connections with respect to the circuit diagram given below. After making necessary connections pair the android mobile with the RPI. Now you can control the bulb by sending command from the android mobile using app. Circuit : Try it: Control the Fans at your home using android mobile phones using Bluetooth module. Try with other home appliances and see the output What is the data transmission speed we use here? ROBOTIC MAKERS LEVEL - 2 69 7. Theft intimation of the vehicle over SMS In this experiment, we are going to make a project which will be very helpful in our daily lives. Nowadays we can hear or see much news related to theft of vehicles. So this project will help to reduce theft of vehicles. Whenever someone is trying to start your vehicle, message intimation will be given to your mobile phones. Materials Required: R-Pi GSM Phone Sim Key set Jumper wires Program: import serial import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(40, GPIO.IN) recipient = “82200*****” content = “ALERT TAKING VEHICLE” ser = serial.Serial(“/dev/serial0”, baudrate=9600, timeout=5) while True: if GPIO.input(40) == True: ser.write(b”AT\r”) rcv = ser.read(10) print(rcv.decode()) time.sleep(0.11) 70 ROBOTIC MAKERS LEVEL - 2 ser.write(b’ATE0\r\n’) rcv = ser.read(10) print(rcv.decode()) time.sleep(0.11) ser.write(b’AT+CMGF=1\r\n’) rcv = ser.read(10) print(rcv.decode()) time.sleep(0.11) ser.write(b’AT+CMGS=”’ + recipient.encode() + b’”\r\n’) rcv = ser.read(10) print(rcv.decode()) time.sleep(0.11) ser.write(content.encode() + b’\r\n’) rcv = ser.read(10) print(rcv.decode()) ser.write(b”\x1A”) for i in range(10): rcv = ser.read(10) print(rcv.decode()) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. Insert the SIM card on the SIM slot of GSM module. Connect the GSM’s Tx to the R.Pi’s 10th pin and GSM’s Rx pin to 8th pin of R.Pi. Also connect the GND pin of GSM to any ground pin of R.Pi. ROBOTIC MAKERS LEVEL - 2 71 Now connect the 5V pin of Rpi with Vcc of GSM. Connect the Key set voltage pin to 40th pin of R.Pi. Ensure the connection and switch ON the device. Once you switch ON, one Green colour light will blink on the GSM module on ring mode you have to change that mode to network mode by long pressing on power button. Dump the code and execute it, now whenever the sensor which you have fixed to your vehicle detects anything, it will start sending you message. By this project you can secure your vehicle from any theft. Circuit : Try it: When the vehicle is under theft, along with the message indication produce an alarm using buzzer. Do you get continuous message intimation during the theft of vehicles? 72 ROBOTIC MAKERS LEVEL - 2 8. Automatic Door Opening System In this project we are going to open the door automatically when there is any human near to the door. Through this project, we can make our works even simple. We can even implement this project in our homes or schools or corporate offices, etc. Materials Required: R-Pi IR sensor Stepper Jumper motor wires Program: import RPi.GPIO as GPIO import time step_pins = [11, 15, 19, 23] # Define GPIO pins ir_sensor_pin = 26 GPIO.setwarnings(False) # Setup GPIO GPIO.setmode(GPIO.BOARD) for pin in step_pins: GPIO.setup(pin, GPIO.OUT) GPIO.setup(ir_sensor_pin, GPIO.IN) clockwise_sequence = [ [1, 0, 0, 1], [1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1] ] def clockwise_rotation(): for i in range(70): for step in clockwise_sequence: for j in range(len(step_pins)): GPIO.output(step_pins[j], step[j]) time.sleep(0.01) print(“Door is opening”) try: while True: ir_sensor_state = GPIO.input(ir_sensor_pin) print(“Waiting for detection...”) ROBOTIC MAKERS LEVEL - 2 73 if ir_sensor_state == GPIO.LOW: print(“Sensor detected...”) clockwise_rotation() # Wait for the sensor to return to initial state while GPIO.input(ir_sensor_pin) == GPIO.LOW: time.sleep(0.1) except KeyboardInterrupt: print(“Exiting program...”) finally: GPIO.cleanup() Procedure: Connect the raspberry pi board as previous experiments, and now connect the IR sensor’s D0 pin to 26th pin of raspberry pi board. And the positive and GND pins to their corresponding Pins in the RPi. board. Now connect the stepper motor’s input pins to the following pins:11,15,19,23. Now run the program and view the output how the project works. Circuit : Connect two IR sensors with Raspberry Pi. Open the door when 1st sensor is detected and close the door when 2nd sensor is detected. 74 ROBOTIC MAKERS LEVEL - 2 9. Recording of videos using Camera In this project we are going to telecast the live captured videos, using Raspberry pi board and a camera module. With this concept you can able to make live surveillance cameras for security purposes. Materials Required: R-Pi Pi camera Program: from picamera2 import Picamera2, Preview picam2 = Picamera2() picam2.start_preview(Preview.QTGL) picam2.start_and_record_video(“/home/auto/capture/test.mp4” ,duration=20) picam2.stop_preview() picam2.close() Procedure: Connect the camera module to the R.Pi board placing the blue side towards the audio jack. To open python shell, go to Terminal Window --> Type sudo idle command. In python shell click File --> New Window and type the above python coding. After typing the code click Run --> Run module option and execute the program. Once you execute the program, you can see the red light indication on the module indicating that it is ready to capture your video. ROBOTIC MAKERS LEVEL - 2 75 Circuit : Try it: Display the video captured, on a projector screen instead of a monitor. Using what device we record the video? Camera module connectors blue side should face where? 76 ROBOTIC MAKERS LEVEL - 2 10. Security system using Camera Module In this project we are going to capture a photo continuously using surveillance camera.This project can be made easily using R.Pi Camera module. Materials Required: R-Pi Pi camera PIR Program: from picamera2 import Picamera2 import RPi.GPIO as GPIO from time import sleep, strftime, localtime import os # Setup GPIO for PIR sensor GPIO.setmode(GPIO.BOARD) PIR_PIN = 12 GPIO.setup(PIR_PIN, GPIO.IN) # Initialize Picamera2 picam2 = Picamera2() i=0 # Specify the directory to save images IMAGE_DIR = “/home/autobots/capture” while True: if GPIO.input(PIR_PIN): print(“Motion detected! Capturing image...”) i=i+1 # Generate the full file path filename = os.path.join(IMAGE_DIR, f”test_{i}.jpg”) picam2.start_and_capture_file(filename) print(f”Image captured: {filename}”) sleep(5) # Delay to prevent rapid capturing due to sensor sensitivity else: print(“No motion detected.”) sleep(1) # Delay to reduce CPU usage ROBOTIC MAKERS LEVEL - 2 77 Procedure: Connect the camera module to the R.Pi board placing the blue side towards the audio jack port. Type the program in python shell and execute the program, you can see the red light indication on the module indicating that it is ready to capture your video. Once the sensor detects presence of animals, It will keep on taking the photos and will save the captured photo on a certain file. Circuit : Try it: Do a Fire Accident monitoring system. Using Flame sensors detect the fire accidents, capture the fired place and display it in monitor. Try to mail the captured picture to a particular mail id 78 ROBOTIC MAKERS LEVEL - 2 11. IOT and RPi based E-mail/SMS alert to avoid crime In this project we are going to capture a place (Classroom/Working area/ Supermarket/Shops) continuously and the captured images will be sent to the specified persons E-mail Id’s. This project is very useful for security based applications. Materials Required: R-Pi Pi camera Program: import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage from picamera2 import Picamera2, Preview from time import localtime, strftime, sleep import os # Email configuration sender_email = ‘[email protected]’ receiver_email = ‘[email protected]’ password = ‘hlfh pjgr koxb ihls’ subject = ‘Test Email from Raspberry Pi’ body = ‘The security image capture file sent from a Raspberry Pi using Python through email’ # Specify the directory to save images IMAGE_DIR = “/home/autobots/Pictures” def capture_and_send_image(): try: picam2 = Picamera2() picam2.start_preview(Preview.QTGL) local_time = localtime() timestamp = strftime(“%d-%m-%Y_%H-%M-%S”, local_time) filename = os.path.join(IMAGE_DIR, f”test_{timestamp}.jpg”) ROBOTIC MAKERS LEVEL - 2 79 # Capture a photo picam2.start_and_capture_file(filename) print(f”Image captured: {filename}”) picam2.stop_preview() picam2.close() # Create a multipart message and set headers message = MIMEMultipart() message[‘From’] = sender_email message[‘To’] = receiver_email message[‘Subject’] = subject # Add body to email message.attach(MIMEText(body, ‘plain’)) # Attach photo to email with open(filename, ‘rb’) as attachment: image = MIMEImage(attachment.read()) attachment.close() message.attach(image) # Connect to the SMTP server (Gmail in this example) server = smtplib.SMTP(‘smtp.gmail.com’, 587) server.starttls() # Login to the email account server.login(sender_email, password) server.sendmail(sender_email, receiver_email, message.as_ string()) # Send the email server.quit() # Close the SMTP connection print(‘Email with photo attachment sent successfully!’) except Exception as e: print(f”Error capturing image or sending email: {e}”) # Main loop to capture and send image try: while True: capture_and_send_image() sleep(5) # Wait for 5 seconds except KeyboardInterrupt: print(“Program terminated by user.”) 80 ROBOTIC MAKERS LEVEL - 2 Procedure: Connect the camera module as said in previous experiments. In order to enable the Gmail server to send emails through RPi, you need to follow some steps. Please watch the video attached to this bar code for the procedure. Type the code click Run --> Run module option and execute the program. Connect the LAN cable with R.Pi board or Connect Wifi. Now as you execute the code the camera will start sending the photo to the particular mail address which was specified in the code. By this we can get notify of any theft happening in our household. Circuit : Try it: Do a Smart Prohibited area Monitoring system using IR sensor and camera. When the sensor senses anyone, the camera module should capture a picture and mail the captured picture. Which protocol is used to send the mail through Raspberry Pi board? ROBOTIC MAKERS LEVEL - 2 81 12. Smart Home using Raspberry Pi In this experiment we are going to make our home as automated smart home. Various sensors are interfaced with Raspberry Pi in order to automatically turn on/off the lights or fans, produces alert when there is any gas leakages and fire accidents at home. Materials Required: R-Pi Flame sensor IR sensor Gas sensor LDR sensor LED Bread board buzzer Jumper wires Program: import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) LED1 = 3 LED2 = 5 Buzzer1 = 7 Buzzer2 = 11 IR_Sensor = 8 LDR_Sensor = 19 Gas_Sensor = 38 Flame_Sensor = 24 GPIO.setup(LED1, GPIO.OUT) GPIO.setup(LED2, GPIO.OUT) GPIO.setup(Buzzer1, GPIO.OUT) GPIO.setup(Buzzer2, GPIO.OUT) GPIO.setup(IR_Sensor, GPIO.IN) GPIO.setup(LDR_Sensor, GPIO.IN) 82 ROBOTIC MAKERS LEVEL - 2 GPIO.setup(Gas_Sensor, GPIO.IN) GPIO.setup(Flame_Sensor, GPIO.IN) while True: if GPIO.input(IR_Sensor): GPIO.output(LED1, True) print(“Somebody is Waiting near the Door”) else: GPIO.output(LED1, False) if GPIO.input(LDR_Sensor): GPIO.output(LED2, True) print(“It’s Darker outside”) else: GPIO.output(LED2, False) if not GPIO.input(Gas_Sensor): GPIO.output(Buzzer1, True) print(“Gas is leaking”) else: GPIO.output(Buzzer1, False) if GPIO.input(Flame_Sensor): GPIO.output(Buzzer2, True) print(“Fire accident occurred!!!”) else: GPIO.output(Buzzer2, False) Procedure: To open python shell, go to Terminal Window --> Type sudo idle command, python shell opens. In python shell click File --> New Window and type the above python coding. Type the code click Run--> Run module option and execute the program Connect the Positive terminal of all the sensors to the 2nd pin of R.Pi board using Breadboard. Similarly connect GND pins of the sensors, LED’s and ROBOTIC MAKERS LEVEL - 2 83 buzzer’s to the 6th pin of the R.Pi board using bread board. Connect the IR sensor’s D0 pinto 8th pin, LDR sensor’s DO pin to 19th pin, Gas sensor’s DO pin to 38th pin, Flame sensor’s DO pin to 24th pin of the R.Pi board Connect the positive terminal of LED 1 to 3rd pin, LED 2 to 5th pin of R.Pi board. Similarly connect the positive terminal of the Buzzer1 to 7th pin and Buzzer2 to 11th pin of R.Pi. Now if, any sensor senses the corresponding physical parameter, we will get intimation through output devices also an intimation message will be printed on the system. Circuit : Try it: Do the same experiment by interfacing relay to ON/OFF the real time appliances. Design a SMART SCHOOL system using Raspberry Pi by interfacing various sensors. 84 ROBOTIC MAKERS LEVEL - 2