0% found this document useful (0 votes)
4 views

Arduino UNO

The document describes examples of using an Arduino UNO board to blink an LED, blink an LED array, use a push button to control an LED, and use a light dependent resistor to control an LED based on light levels.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino UNO

The document describes examples of using an Arduino UNO board to blink an LED, blink an LED array, use a push button to control an LED, and use a light dependent resistor to control an LED based on light levels.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1

Arduino UNO

Bread Board

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
2

LED LDR

Example 1: - Blink LED

int led = 13;

void setup() {

// put your setup code here, to run once:

pinMode(led,OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(led,HIGH);

delay(500);

digitalWrite(led,LOW);

delay(500);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
3

Example 2: - Blink LED Array


int led1 = 13;

int led2 = 12;

int led3 = 11;

int led4 = 10;

int led5 = 9;

int led6 = 8;

void setup() {

// put your setup code here, to run once:

pinMode(led1,OUTPUT);

pinMode(led2,OUTPUT);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
4

pinMode(led3,OUTPUT);

pinMode(led4,OUTPUT);

pinMode(led5,OUTPUT);

pinMode(led6,OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(led1,HIGH);

delay(500);

digitalWrite(led1,LOW);

digitalWrite(led2,HIGH);

delay(500);

digitalWrite(led2,LOW);

digitalWrite(led3,HIGH);

delay(500);

digitalWrite(led3,LOW);

digitalWrite(led4,HIGH);

delay(500);

digitalWrite(led4,LOW);

digitalWrite(led5,HIGH);

delay(500);

digitalWrite(led5,LOW);

digitalWrite(led6,HIGH);

delay(500);

digitalWrite(led6,LOW);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
5

Example 3: - Push Button


// constants won't change. They're used here to set pin numbers:

const int buttonPin = 2; // the number of the pushbutton pin

const int ledPin = 13; // the number of the LED pin

// variables will change:

int buttonState = 0; // variable for reading the pushbutton status

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
6

void loop() {

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is


HIGH:

if (buttonState == HIGH) {

// turn LED on:

digitalWrite(ledPin, HIGH);

} else {

// turn LED off:

digitalWrite(ledPin, LOW);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
7

Example 4: - Working with LDR (Part 1)

int sensorPin = A0; // select the input pin for the LRD

int sensorValue = 0; //variable to store the value coming from the sensor

void setup() {

Serial.begin(9600);

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

Serial.println(sensorValue);

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
8

Example 5: - Working with LDR (Part 2)

int sensorPin = A0; // select the input pin for the potentiometer

int ledPin = 13; // select the pin for the LED

int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {

// declare the ledPin as an OUTPUT:

pinMode(ledPin, OUTPUT);

Serial.begin(9600);

void loop() {

// read the value from the sensor:

sensorValue = analogRead(sensorPin);

//Serial.println(sensorValue);

if (sensorValue<500){

digitalWrite(ledPin,HIGH);

Serial.println("LED ON...");

else{

digitalWrite(ledPin,LOW);

Serial.println("LED OFF...");

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
9

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science
10

Pubudu Wijekoon
B.Sc. Sp. (Hons) in IT, M.Sc. in Computer Science

You might also like