ESD_expt2
ESD_expt2
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:
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.
To configure the board, access the Tools menu and then Board. For Arduino Uno,
you should select Arduino/Genuino Uno:
After you select the board, you have to set the appropriate port. Access
the Tools menu again, and this time select 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:
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.
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:
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:
After the installation finishes, you can run an equivalent Blink application using
Python and Firmata:
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:
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.