You are on page 1of 41

BIO F111 :P

What is Arduino?

Arduino is a tool for


controlling the physical
world around us.

Its an open-source platform.

Arduino can be connected to


software on your computer.
Why Arduino?

The Arduino environment has been


designed for beginners who have no
software or electronics experience.
Still, Arduinos underlying hardware
works at the same level of
sophistication.
Digital vs Analog

Total Digital I/O Pins : 14 (of which 6 are PWM


pins) . These pins are called GPIO pins.
DC Current per I/O Pin : 40mA
Analog Inputs

Many states, not just two (High/Low) as in case of digital inputs

No of states (or values, or bins) is called resolution

Common computer resolutions

8-bit = 28 values

16-bit = 216 values

32-bit = 232 values


Arduino UNO Pin functions
Pins 1-13 : Digital pins , can take Digital inputs, can give Digital
outputs.

Pins 3,5,6,9,10,11 : Can give PWM(Technique to get analog Output


from digital pins) outputs.

Pins A0-A5 : Analog pins, can take Analog inputs only. Controlled by
ADC (10-bit resolution)

ADC- Analog to digital convertor


The Micro-controller ATMEGA 328P

When GPIO pins are configured


to an input state, they are used
to read external signals. (eg.
sensors)
Configured to the output state,
GPIO pins can drive external
devices such as LEDs or motors.
Analog Inputs

Arduino(ATmega328) has 6 ADC inputs (A0-A5)


Arduino has 6 ADC inputs which means it will measure
voltages on 6 pins independently so 6 analog sensors
can be connected.
Arduino can read voltages between 0-5 Volts
Resolution is 10 bit ( 2^10 = 1024 values)
Hence, 0-5 V corresponds to values from 0 to 1023
Power up!
The most common way to
power the Arduino is to plug
one end of the USB cable into
the Arduino and the other end
into a computer.
Make sure the Power Jumper is
set correctly. Which is next to
the USB jack.
As soon as you
connect the Arduino to
the computer, you
should get a light on
the board.
It confirms that your
Arduino is working
correctly.
Installing the Arduino IDE

Get the Arduino software and


unzip it.
Plug in the Arduino board.
Install the drivers.
Run the Arduino program
arduino.exe.
Select the appropriate port and
the suitable board.
Go to Tools and select the
board name Arduino UNO

Select the port as COM 3 or


COM 4 (as per Device
Manager).

COM port is also known as


Serial port.
Blinking LED Code

File-> Examples->
Basics->Blink

Upload the code by


clicking the arrow
button.

LED beside pin 13


should blink in intervals
of 1 second.
Activity #1 Blinking LED

In most programming languages, the first


program you write prints "hello world" to
the screen. Since an Arduino board doesn't
have a screen, we blink an LED instead.
Making the Connections

Negative terminal of LED


(shorter end) to GND
(ground of Arduino)

Postive terminal of LED to


one end of 220E resistor.

Pin 9 of Arduino to other


end of resistor.

20/09/14 Pre-ATMOS Workshop Series 21


SET PIN NINE AS AN OUTPUT
PIN

WE SEND 5V TO THAT
PIN

WE SEND 0V TO
THE PIN
/*
Turns on an LED on for one second, then off for one
second, repeatedly.
*/

void setup() {

// initialize the digital pin as an output.


// Pin 9 has an LED connected on most Arduino boards:
pinMode(9, OUTPUT);
}

void loop() {
digitalWrite(9, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(9, LOW); // set the LED off
delay(1000); // wait for a second
}
VARIABLES AND DATA TYPES
A variable is nothing but a name given to a storage area
that our programs can manipulate. Each variable in C has
a specific type, which determines the size and layout of
the variable's memory; the range of values that can be
stored within that memory; and the set of operations
that can be applied to the variable.

There are six basic data types associated with variables:


int - integer: a whole number.
float - floating point value: ie a number with a fractional part.
double - a double-precision floating point value.
char - a single character.
void - valueless special purpose type which we will examine closely in later
sections.
Boolean-TRUE or FALSE
What are functions loops
A function is a group of statements that together perform a task.
Every Arduino program has at least one function, which is main(), and
all the most trivial programs can define additional functions. You can
divide up your code into separate functions.
The things you write inside () are the inputs to the function.
Loops are functions which keep running over and over till you say
stop.
Varying intensity using pwm
void setup() {
// initialize the digital pin as an output.
// Pin 9 has an LED connected on most Arduino boards:
pinMode(9, OUTPUT);
}

void loop() {
analogWrite(9,(your wish between 0-255)); // set the LED on a certain intesity
delay(1000); // wait for a second
digitalWrite(9, (your wish)); // set the LED on a different intesnity
delay(1000); // wait for a second
}
What is PWM?
Pulse width modulation (PWM) is a fancy term for describing a type of digital signal.
This is for an 8bit resolution.
Potentiometer:
A potentiometer, informally
a pot, is a three-terminal
resistor with a sliding or
rotating contact that forms
an adjustable voltage
divider.

Moving the knob is like moving the point where the arrow taps the voltage on the resistor
Connections
void setup()
{
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(9, OUTPUT);}

void loop() {
// put your main code here, to run repeatedly:
int potval = analogRead(A0); //potval ranges from 0-5v
Serial.println(potval);
delay(1000);
}
SET PIN 9 AS AN OUTUT PIN

ACCEPT VALUES FROM


POTENIOMETER

PRINT THE VALUES


void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(9, OUTPUT);}

void loop() {
// put your main code here, to run repeatedly:
double potval = analogRead(A3);
Serial.println(potval);
double norm=5.0/255; //what is norm?
analogWrite(9,(int)(potval*norm));
delay(1); - Try and change the value, and see what happens.
}
Activity #2 - AUTOMATIC LAMP

Turn on/off an LED by sensing the amount of light in the surrounding.


How can we do that?

These babies
Brighter light = lower resistance
Connections
IF condition
The ability to control the flow of your program, letting it make decisions on what code to execute,
is valuable to the programmer.
The if statement allows you to control if a program enters a section of code or not based on whether a
given
condition is true or false.
One of the important functions of the if statement is that it allows the program to select an action
based upon
the user's input.
For example, by using an if statement to check a user-entered password, your program can decide
whether a
user is allowed access to the program.

If(statement is true)
{
run this;
}
SET PIN 9 AS AN
Code: OUTPUT PIN

void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);}
TAKE VALUES
void loop() { FROM LDR
int ldr = analogRead(A2); \\values from 0-5
Serial.println (ldr);
int thresh=enter;
if (ldr > thresh) IF VALUE>
TRUE
MAKE BULB
{ THRESHOL
D GLOW
digitalWrite(9,HIGH);
}
if (ldr < thresh)
{ TURN BULB
digitalWrite(9,LOW); OFF
}
delay(1);
}
ACTIVITY 3- PUSH BUTTONS

CONTROLLING THE LIGHT VIA A


PUSH BUTTON.
Push buttons
CONNECTIONS
CODE

void setup() {

pinMode(7, INPUT); //pinMode (push, INPUT);


pinMode(13, OUTPUT); //pinMode (led, OUTPUT);
}

void loop() {
if (digitalRead(7) == HIGH) //if (digitalRead(push) == HIGH)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
}

You might also like