lecture-4 (Analog Input Output)
lecture-4 (Analog Input Output)
FUNCTIONS
Analog I/O
analogRead()
Reads the value from the specified analog pin. Arduino
boards contain a multichannel, 10-bit analog to digital
converter.
Syntax
analogRead(pin);
Example
FUNCTIONS
Analog I/O
analogWrite()
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at
varying brightness's or drive a motor at various speeds.
Syntax
analogRead(pin, value);
Example
FUNCTIONS
Comunication
Serial.begin()
Sets the data rate in bits per second (baud) for serial data transmission.
In Arduino you can use 300, 600, 1200, 2400, 4800, 9600, 14400, 19200,
28800, 38400, 57600, or 115200. However 9600 is the standard baud
rate usually used.
Syntax
Serial.begin(speed);
Example
FUNCTIONS
Comunication
Serial.print():
Prints data to the serial port as human-readable ASCII text.
Example
Serial.print(value);
Serial.print(“Hello World”);
Serial.println():
Prints data to the serial port as human-readable ASCII text
followed by a carriage return character and a newline character.
Example
Serial.print(“value:”);
Serial.println(val);
Example 1 (Analog Read)
Example 2 (Analog Read)
Pulse Width
PWM Modulation
Pulse Width Modulation, or PWM, is
a technique for getting analog results
with digital means.