0% found this document useful (0 votes)
9 views7 pages

ESD_expt2

Uploaded by

Saniya Pinjari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

ESD_expt2

Uploaded by

Saniya Pinjari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E.

(2019Pattern), Electronic System Design

Roll No. Date:


Experiment No. 2
Name:

Title: Introduction and applications using Arduino and micro python.

Aim: To build and test simple application circuit on bread board.

Apparatus: bread board, connecting wires, resistor, LED, Arduino board, Arduino board
serial cable, computer system, Arduino IDE, Python3.6, etc.

Prior Concept:
1. Knowledge of basic electronic components
2. Implementing circuit on bread board
3. Fundamentals of programming in C/C++
4. Fundamentals of programming in python

Learning Objectives:

Intellectual Skills
1. To understand the construction of Arduino board and its use
2. To understand programming in python for Arduino boards.

Motor Skills
1. Set up electronic circuits
2. Set up the Firmata protocol on Arduino
3. Write basic applications for Arduino in Python

Theory:
Arduino is an open-source platform composed of hardware and software that allows
for the rapid development of interactive electronics projects. The emergence of Arduino drew
the attention of professionals from many different industries, contributing to the start of
the Maker Movement.
Arduino uses its own programming language, which is similar to C++. However, it’s
possible to use Arduino with Python or another high-level programming language. In fact,
platforms like Arduino work well with Python, especially for applications that require
integration with sensors and other physical devices.
All in all, Arduino and Python can facilitate an effective learning environment that
encourages developers to get into electronics design. If you already know the basics of
Python, then you’ll be able to get started with Arduino by using Python to control it.

Arduino Hardware
To run the examples, you’ll need to assemble the circuits by hooking up electronic
components. You can generally find these items at electronic component stores or in good
Arduino starter kits. You’ll need:

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

1. An Arduino Uno or other compatible board


2. A standard LED of any color
3. A push button
4. A 10 KOhm potentiometer
5. A 470 Ohm resistor
6. A 10 KOhm resistor
7. A breadboard
8. Jumper wires of various colors and sizes

Fig.1 Arduino board with LED circuit on bread board

After you finish the connection, plug the Arduino back into the PC
Uploading the Blink Example Sketch
To get started, connect the Arduino board to your PC using a USB cable and start the
Arduino IDE. To open the Blink example sketch, access the File menu and select Examples,
then 01.Basics and, finally, Blink:

The Blink example code will be loaded into a new IDE window. But before you can upload
the sketch to the board, you’ll need to configure the IDE by selecting your board and its
connected port.

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

Fig.2 selecting blink program from Arduino IDE

To configure the board, access the Tools menu and then Board. For Arduino Uno,
you should select Arduino/Genuino Uno:

Fig.3 Selecting board

After you select the board, you have to set the appropriate port. Access
the Tools menu again, and this time select Port:

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

Fig.4 selecting port

After you’ve configured the board and port, you’re all set to upload the sketch to
your Arduino. To do that, you just have to press the Upload button in the IDE
toolbar:

Fig.5 verify and upload sketch icons of Arduino IDE

Arduino and Python


there are some approaches you can take to use Arduino with Python or other
languages. One idea is to run the main program on a PC and use the serial
connection to communicate with Arduino through the USB cable. The sketch
would be responsible for reading the inputs, sending the information to the PC, and
getting updates from the PC to update the Arduino outputs.
With the protocol defined, you could write an Arduino sketch to send messages to
the PC and update the states of the pins according to the protocol. On the PC, you
could write a program to control the Arduino through a serial connection, based on
the protocol you’ve designed. For this, you can use whatever language and
libraries you prefer, such as Python and the PySerial library.

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

Fortunately, there are standard protocols to do all this! Firmata is one of them.
This protocol establishes a serial communication format that allows you to read
digital and analog inputs, as well as send information to digital and analog outputs.

Uploading the Firmata Sketch


Before you write your Python program to drive Arduino, you have to upload the
Firmata sketch so that you can use that protocol to control the board. The sketch is
available in the Arduino IDE’s built-in examples. To open it, access the File menu,
then Examples, followed by Firmata, and finally StandardFirmata:

Fig.6 upload fermata sketch to Arduino board

The sketch will be loaded into a new IDE window. To upload it to the Arduino,
you can follow the same steps you did before:

1. Plug the USB cable into the PC.


2. Select the appropriate board and port on the IDE.
3. Press Upload.

After the upload is finished, you won’t notice any activity on the Arduino. To
control it, you still need a program that can communicate with the board through
the serial connection. To work with the Firmata protocol in Python, you’ll need
the pyFirmata package, which you can install with pip:

$ pip install pyfirmata

After the installation finishes, you can run an equivalent Blink application using
Python and Firmata:

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

importpyfirmata
2importtime
3
4board=pyfirmata.Arduino('/dev/ttyACM0')
5
6whileTrue:
7board.digital[13].write(1)
8time.sleep(1)
9board.digital[13].write(0)
10time.sleep(1

Here’s how this program works. You import pyfirmata and use it to establish a serial
connection with the Arduino board, which is represented by the board object in line 4. You
also configure the port in this line by passing an argument to pyfirmata.Arduino(). You can
use the Arduino IDE to find the port.
board.digital is a list whose elements represent the digital pins of the Arduino. These
elements have the methods read() and write(), which will read and write the state of the pins.
Like most embedded device programs, this program mainly consists of an infinite loop:

 In line 7, digital pin 13 is turned on, which turns the LED on for one second.
 In line 9, this pin is turned off, which turns the LED off for one second.
Now that you know the basics of how to control an Arduino with Python, you can build some
applications to interact with its inputs and outputs.

References:
1. https://www.arduino.cc/
2. https://docs.arduino.cc/learn/programming/arduino-and-python
3. https://realpython.com/arduino-python/

Conclusions:________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

Checked By:

Name of Subject Teacher Sign with Date

Department of Electronics & Telecommunication Engineering


R. H. Sapat College of Engineering, Mgmt. Studies & Research, Nashik S.E. (2019Pattern), Electronic System Design

Assignments/ Questions:
1. Remembering:
 Question: What are the main components of an Arduino board?
2. Understanding:
 Question: Can you explain how the digitalWrite() function controls an output pin in Arduino?
3. Applying:
 Question: How would you use a potentiometer to control the brightness of an LED with an
Arduino?
4. Analyzing:
 Question: Analyze the code required to control multiple sensors and actuators with an
Arduino. How would you optimize it for efficiency?
5. Evaluating:
 Question: After building a temperature monitoring system with Arduino, evaluate its accuracy
and response time. How could it be improved?
6. Creating:
 Question: Design a complete home automation system using Arduino that controls lights,
temperature, and security based on sensor inputs.

Department of Electronics & Telecommunication Engineering

You might also like