Arduino Based Experiments- input/output
Arduino is an open-source electronics platform based on easy-to-use hardware
and software.
Arduino consists of:
1. A circuit board, which can be programed (referred to as a microcontroller)
2. Arduino IDE (Integrated Development Environment), which is used to write
and upload the computer code to the physical board.
Arduino
Key features:
❖ The Arduino board functions can be controlled by sending
a set of instructions to the microcontroller on the board
via Arduino IDE.
❖ Arduino boards are able to read analog or digital input
signals from different sensors and turn it into an output
such as activating a motor, turning LED on/off, connect to
the cloud and many other actions. Arduino
UNO board
❖ Additionally, the Arduino IDE uses a simplified version of C++, making it
easier to learn to program.
Anatomy of an Arduino Board
1. Microcontroller - this is the brain of an Arduino, and
is the component that we load programs into.
2. USB port - used to connect your Arduino board to a
computer.
3. USB to Serial chip - the USB to Serial is an important
component, as it helps translating data that comes
from e.g. a computer to the on-board microcontroller.
This is what makes it possible to program the Arduino
board from your computer.
4. Digital pins - pins that use digital logic (0,1 or
LOW/HIGH). Commonly used for switches and to turn
on/off an LED.
Anatomy of an Arduino Board
5. Analog pins - pins that can read analog values in
a 10 bit resolution (0-1023).
6. 5V / 3.3V pins- these pins are used to power
external components.
7. GND - also known as ground, negative or simply -
, is used to complete a circuit, where the electrical
level is at 0 volt.
8. VIN - stands for Voltage In, where you can
connect external power supplies.
Circuit Basics
Circuits consist of at least one active electronic
component, and a conductive material, such as wires,
so that current can pass through.
LED circuit
An LED circuit with an
❖ A wire is connected from a pin on the Arduino, Arduino.
to an LED via a resistor, and finally to the
ground pin (GND).
❖ When the pin is set to a HIGH state, the
microcontroller on the Arduino board will
allow an electric current to flow through
the circuit, which turns on the LED.
❖ When the pin is set to a LOW state, the LED
will turn off, as an electric current is not flowing
through the circuit.
Schematics of a circuit.
Electronic Signals
There are two main types of electronic signals: analog & digital.
Analog Signal
An analog signal is generally bound to a range.
In an Arduino, that range is typically 0-5V, or
0-3.3V.
Digital Signal
A digital signal represents two binary states (0 or 1)
that are read as high or low states in the program.
Sensors & Actuators
Sensor
A sensor, is used to sense its environment, meaning it records a physical
parameter, for example temperature, and converts it into an electronic signal.
Sensors can also take the form of just a simple button: when a state changes (we
pressed a button), the electronic signal is switched from low to high (0 to 1).
Actuator
An actuator, is used to actuate or change a physical state. Some examples are:
❖ A light (such as an LED)
❖ A motor
❖ A switch
Actuators converts electric signals into e.g. radiant energy (light) or mechanical
energy (movement).
Arduino Tasks to be conducted in the lab
• 1. Blinking of inbuilt LED
• 2. Lighting and blinking of External LED
• 3. Making of Traffic Light Sequence
• 4. Sensing and measuring the Battery Voltage- Analog Input
• 5. Control of an Alarm based on Analog Input from a Sensor
• 6. Circuits for testing of Logic gates - AND Gate, OR gate, XOR Gate, NAND Gate etc.
• 7. Optional - Think of any fun cirucit using LEDs and/or Switches and/or sensors and make and
demonstrate it. You can also use Audrino Board to run a DC motor, or stepper motor or an
actuator. You can refer to you tube for any DIY projects which are Arduino based.
• For each of the six practicals. When you make it. Demonstrate to your TA who will mark it.
• Write the code on your notebook. (not print)
Example Program 1- Lighting of internal LED
// the setup function runs once when you press reset or
power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Example Program 2- Lighting of external LED
// the setup function runs once when you press reset or
power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(9, OUTPUT); //Here you input the digital number of the channel
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Example Program 3- Reading an Analog Signal
• void setup()
• {
• // initialize serial communication at 9600 bits per second:
• [Link](9600);
• }
•
// the loop routine runs over and over again forever:
• void loop() {
• // read the input on analog pin 0:
• int sensorValue = analogRead(A0);
• // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
• float voltage = sensorValue * (5.0 / 1023.0);
• // print out the value you read:
• [Link](voltage);
• }
•