Lecture 02
Lecture 02
PinMode
A pin on arduino can be set as input or output by using pinMode function.
• pinMode(ledPin, OUTPUT); // sets pin 13 as output pin
• pinMode(ledPin, INPUT); // sets pin 13 as input pin
Reading/writing digital values
digitalWrite(ledPin, LOW); // Makes the output voltage on pin 13 , 0V
digitalWrite(ledPin, HIGH); // Makes the output voltage on pin 13 , 5V
Arduino Specific Functions
Arduino Specific Functions
Analog I/O
1. analogRead()
• Description: Read the value from the specific analog pin. Arduino boards contain a multichannel, 10-bit analog
to digital converter.
• This means that it will map input voltages between 0 and the operating voltage (5V or 3.3V) into integer values
between 0 and 1023.
• Syntax: analogRead(pin)
• Parameter:the name of the analog input pin to read from (A0 to A5)
2. analoglWrite()
• Description: Write an analog value to a pin. Can be used to light a LED at varying brightness or drive a motor at
various speeds.
• Syntax: analogWrite(pin , value)
• pin: the Arduino pin to write to : Allowed data type : int
• value : the duty cycle between 0 and 255 : Allowed data type : int
3. analogReference()
• Description: Configures the reference voltage used for analog input. The options are
• DEFAULT : the default analog reference of 5 volts or 3.3 volts
• EXTERNAL : the voltage applied to the AREFpin (o to 5V only) is used as the reference
• Syntax: analogReference(type)
Arduino Specific Functions
Arduino Specific Functions
Time
1. delay()
• Description:Pauses the program for the amount of time(in milliseconds) specified as parameter.
• Syntax: delay(time)
• ms: the number of milliseconds to pause. Allowed data type : unsigned long
• Communication
Serial
• Description : Used for communication between the Arduino board and a computer or other
devices. All Arduino boards have at least
• one serial port and some have several.
1. Serial.available()
• Description: get the number of bytes available for reading form the serial port.
• Syntax: Serial.available()
2. Serial.begin()
• Description : Sets the data rate in bits per second for serial data transmission.
• Syntax : Serial.begin(speed)
Arduino Specific Functions
3. Serial.println()
• Description : prints data to the serial port as huma-redable ASCII text followed by
a carriage return character and a new line character.
• Syntax : Serial.println(val)
• Serial : serial port object.
• val : the value to print. Allowed data type : any data type
4. Serial.read()
• Description : Reads incoming serial data
• Syntax : Serial.read()
5. Serial.write()
• Description : Writes binary data to the serial port .
• Syntax : Serial.write(val)
• Serial.write(str)
Arduino Specific Functions
Arduino Data Types
Arduino Data Types