Arduino Basics NC
Arduino Basics NC
INTRODUCTION TO C PROGRAMMING
WEEK 23 (LECTURE 7)
TUTOR: DR N MANIVANNAN
1
Week 1
Introduction to the
course Week 4
Introduction to C 1. if, if-else, if-else-if
Introduction to Pelles C
2. switch-case
3. while
Week 2
SO FAR
4. do-while
Program structure
5. for
Functions
Basic flow chart
Printf and scanf instructions
Rational operators
C libraries
Week 5
Week 3 Week 6 1. Rational operators and Logical
operators
1. Data Type (char, int, float etc) 1. Bitwise operators
2. Address of a variable
2. Variables and constants 2. Data Structures 3. pointers
3. Binary numbers and 4. Arrays
conversions to Decimal numbers
2016-17 by VNM
2
EMBEDDED SYSTEM PROGRAMMING USING C
BY NUMAN CELIK
DR MANIVANNAN
DEPARTMENT OF DESIGN
Features
14 Digital I/O pins
6 Analogue inputs
6 PWM pins
USB serial
16MHz Clock speed
32KB Flash memory
2KB SRAM
1KB EEPROM
THE ARDUINO IDE
void setup()
{
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
}
FIRST SKETCH ON ARDUINO ON-
BOARD LED
int onBoardLED;
void setup()
{
//Arduinos have an on-board LED on pin 13
onBoardLED = 13;
pinMode(onBoardLED, OUTPUT);
}
void loop()
{
digitalWrite(onBoardLED, HIGH);
delay(500); //delay measured in milliseconds
digitalWrite(onBoardLED, LOW);
delay(500);
}
AN EXAMPLE OF LED
BLINKING
Task:
Construct the circuit as shown
Connect the USB form the Arduino board to
the computer
Transfer the code in next slide to Sketch and
then upload onto Arduino
Control the amount of light fall onto the LDR . It
should change the LED ON/OFF status
USB connection
to computer Change the code to set different level and
experiment it to see the change.
C-CODE (SKETCH) TO CONTROL LEDS
ACCORDING THE LIGHT (LDR)
int sensorPin = A0; // select the input pin for ldr
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(2, OUTPUT); //output pin for RED LED
pinMode(3, OUTPUT); // output pin for GREEN LED
Serial.begin(9600); //sets serial port for communication
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor:
Serial.println(sensorValue); //prints the values coming from the sensor on the screen
https://www.arduino.cc/en/Main/ArduinoBoardUno
Arduino tutorials - Youtube