(Arduino) Pranav Computer Branch - B
(Arduino) Pranav Computer Branch - B
Introduction &
Programming
STUDENT NAME : VAYS PRANAV RAJENDRABHAI
BRANCH : COMPUTER – B
ENROLLMENT NO : 219860307113
What is an Arduino ?
Arduino IDE is a special software running on your system that allows you to write
sketches (synonym for program in Arduino language) for different Arduino
boards. The Arduino programming language is based on a very simple hardware
programming language called processing, which is similar to the C language.
After the sketch is written in the Arduino IDE, it should be uploaded on the
Arduino board for execution.
Advantages
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Bare minimum code
loop : The loop functions runs continuously till the device is powered off. The
main logic of the code goes here. Similar to while (1) for micro-controller
programming.
PinMode
What is analog ?
It is continuous range of voltage values (not just 0 or 5V)
This means that it will map input voltages between 0 and 5 volts into integer
values between 0 and 1023
Reading/Writing Analog Values
analogWrite(2,128);
ADC Example
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);