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

Arduino Uno Based Programming Examples - To Be Shared To Students

Uploaded by

mrunalpadmakar67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Arduino Uno Based Programming Examples - To Be Shared To Students

Uploaded by

mrunalpadmakar67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

YEAR : 2024 :: ARDUINO UNO BASED PROGRAMMING EXAMPLES :

[1] Flashing Single LED ( On-Board LED ) :

int ledPin = 13;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
[2] Flashing 3 LEDs for Traffic Light Signal Control :

const int LEDR = 9;


const int LEDY = 8;
const int LEDG = 7;

void setup()
{
pinMode(LEDR,OUTPUT);
pinMode(LEDY,OUTPUT);
pinMode(LEDG,OUTPUT);
}

void loop()
{
digitalWrite(LEDR,HIGH);
digitalWrite(LEDY,LOW);
digitalWrite(LEDG,LOW);
delay(8000);

digitalWrite(LEDR,LOW);
digitalWrite(LEDY,HIGH);
digitalWrite(LEDG,LOW);
delay(300);
digitalWrite(LEDR,LOW);
digitalWrite(LEDY,LOW);
digitalWrite(LEDG,HIGH);
delay(2000);

digitalWrite(LEDR,LOW);
digitalWrite(LEDY,HIGH);
digitalWrite(LEDG,LOW);
delay(300);
}
[3] Flashing 4 -BIT LEDs :

int ledPins[] = {2, 3, 4, 5};

void setup()
{
for (int i = 0; i < 4; i++)
{
pinMode(ledPins[i], OUTPUT);
}
}

void loop()
{
for (int i = 0; i < 4; i++)
{
digitalWrite(ledPins[i], HIGH);
delay(250);
digitalWrite(ledPins[i], LOW);
}
}
[4] Operating On Board LED based on Switch Input :

int switchPin = 2;
int ledPin = 13;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop()
{
if (digitalRead(switchPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
[5] Operating OFF Board LED based on Switch Input :

int switchPin = 7;
int ledPin = 8;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop()
{
if (digitalRead(switchPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
[6] 16x2 LCD Display with I2C: TO Display GOOD MORNING :

( We need to install LiquidCrystal_I2C library)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("GOOD MORNING");
}

void loop()
{
}
[7] TWO IR Sensors with Object Counting Logic : To Display on
Computer using USB Serial PORT
int sensor1Pin = 2;
int sensor2Pin = 3;
int count = 0;

void setup()
{
pinMode(sensor1Pin, INPUT);
pinMode(sensor2Pin, INPUT);
Serial.begin(9600);
}

void loop()
{
if (digitalRead(sensor1Pin) == LOW && digitalRead(sensor2Pin) == HIGH)
{
count++;
Serial.print("Count: ");
Serial.println(count);

delay(1000); // Adjust delay

}
}
[8] Displaying "GOOD MORNING" on USB Serial Port:

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println("GOOD MORNING");
delay(1000);
}
[9] TWO IR Sensors with Object Counting Logic : To Display on
LCD Display :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int sensorPin1 = 2; // IR Sensor 1 pin


const int sensorPin2 = 3; // IR Sensor 2 pin

int objectCount = 0; // Counter for objects passing by

void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Objects: 0");
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(sensorPin1) == LOW && digitalRead(sensorPin2) == HIGH)
{
delay(100); // Debounce delay
if (digitalRead(sensorPin1) == LOW && digitalRead(sensorPin2) ==
HIGH)
{
objectCount++;
lcd.setCursor(9, 0);
lcd.print(objectCount);
Serial.print("Object detected. Total count: ");
Serial.println(objectCount);
delay(500); // Adjust delay as needed
}
}
}

You might also like