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

Program

The document describes 9 programs that can be run on an Arduino board. Program 1 blinks an LED by turning it on and off. Program 2 controls an LED using a switch. Program 3 measures temperature using a temperature sensor. Program 4 produces sound using a buzzer. Program 5 controls an LED using an LDR light sensor. Program 6 controls brightness of an LED using a potentiometer. Program 7 displays text on an LCD screen. Program 8 measures distance using an ultrasonic sensor. Program 9 controls a DC motor's direction using an H-bridge motor controller.

Uploaded by

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

Program

The document describes 9 programs that can be run on an Arduino board. Program 1 blinks an LED by turning it on and off. Program 2 controls an LED using a switch. Program 3 measures temperature using a temperature sensor. Program 4 produces sound using a buzzer. Program 5 controls an LED using an LDR light sensor. Program 6 controls brightness of an LED using a potentiometer. Program 7 displays text on an LCD screen. Program 8 measures distance using an ultrasonic sensor. Program 9 controls a DC motor's direction using an H-bridge motor controller.

Uploaded by

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

Program # 1: Blinking led

Equipment: Arduino UNO, Bread board, LED, Resistor, Wires.


Code:
int ledPin = 8;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000); }

Program # 2: Using switch


Equipment: Arduino, Breadboard, LED, Switch, Resistor, Wires
Code:
const int buttonPin = 7;
const int ledPin = 8;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW); }

program # 3: Finding temperature


Equipment: Arduino,Breadboard,TMP36,Wires
Code:
int temperaturePin = 0;
float adcValue;
float voltage;
float degreesC;
void setup()
{
Serial.begin(9600);
}
void loop()
{
adcValue = analogRead(temperaturePin);
voltage = (adcValue*5)/1023;
degreesC = 100*voltage - 50;
Serial.print("ADC Value: ");
Serial.print(adcValue);
Serial.print(" voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.println(degreesC);
delay(1000); }

program # 4: buzzer
Equipment: Buzzer,Arduino UNO,Breadboard,
Code:
int buzzer=7;//set buzzer’s digital pin IO in control
void setup()
{
pinMode(buzzer,OUTPUT);//set digital pin IO OUTPUT
}
void loop()
{
unsigned char i,j;//define i j
while(1)
{
for(i=0;i<80;i++)// Output a frequency of sound }

Program # 5: LDR Light sensor


Equipment: LDR, Arduino UNO, LED, Resistor, Wires
Code:
int photocellPin = 0;
int ledPin = 2;
int photocellReading;
const float limit = 100;
void setup(void)
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop(void)
{
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
if (photocellReading < limit)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
delay(1000);}

program # 6: potentiometer
Equipment: Arduino UNO, Potentiometer, Breadboard, LED, Wires
Code:
int potpin = 0 ; //define analog pin0
int ledpin = 13 ; //define analog pin13
int val = 0 ; //set val is0.
void setup()
{
pinMode(ledpin,OUTPUT);//set analog pin13 output
Serial.begin(9600);//set baud rate 9600
}
void loop()
{
digitalWrite(ledpin,HIGH);//light up led in pin13
delay(50);//delay 0.05s
digitalWrite(ledpin,LOW);//go out led in pin13
delay(50);//delay 0.05s
val = analogRead(potpin);//give the value of pin0 to val
Serial.println(val) ; //print val’s value }

Program # 7 : Lcd
Equipment: LCD1602, Arduino UNO, Breadboard, Pot, Wires
Code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

Program # 8 : distance sensor


Equipment: Distance Sensor, Arduino UNO, Breadboard, Wires
Code:
int TrigPin = 2;
int EchoPin = 3;
float cm;
void setup()
{
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
}
void loop()
{
digitalWrite(TrigPin, LOW); //Low-high-low level sent a short time pulse to TrigPin
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time converted into cm
cm = (int(cm * 100.0)) / 100.0; // retain two decimal places
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(1000);
}

Program # 9 : H-bridge & dc-motor


Equipment: Arduino UNO, H-Bridge, DC-Motor, Breadboard, Wires
Code:
void setup() {

pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(9, HIGH);
}
void loop() {

digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(6000);

digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2000);

digitalWrite(10, LOW);
digitalWrite(11, HIGH);}

You might also like