18 Ec 036

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Mansi Jesani 18ec036

SEVEN SEGMENT INTERFACING:

I. Display 0 to 9 on segment

CODE:
void setup()
{for(int i=0;i<8;i++)
{
pinMode(i,OUTPUT);
}
}
int seg_code[10]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
void loop()
{
for(int i=0;i<10;i++)
{
PORTD=seg_code[i];
delay(1000);
}
}
Mansi Jesani 18ec036

II. Display 00 to 99 on segment

Code:
#define e1 8
#define e2 9

void setup()
{
for(int i=0;i&lt;=9;i++)
{
pinMode(i,OUTPUT);
}
}
int
seg_code[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0
x7F,0x6F};
void loop()
{
Mansi Jesani 18ec036

for(int j=0;j&lt;=9;j++)
{
for(int k=0;k&lt;=9;k++)
{
digitalWrite(e2,LOW);
PORTD=seg_code[j];
delay(100);
digitalWrite(e2,HIGH);

digitalWrite(e1,LOW);
PORTD=seg_code[k];
delay(100);
digitalWrite(e1,HIGH);
}
}
}

III. Display 000 to 999on segment

Code:-
#define e1 8
#define e2 9
Mansi Jesani 18ec036

#define e3 10

void setup()
{
for(int i=0;i&lt;=10;i++)
{
pinMode(i,OUTPUT);
}
}

int
seg_code[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void loop()
{
for(int j=0;j&lt;=9;j++)
{
for(int k=0;k&lt;=9;k++)
{

for(int l=0;l&lt;=9;l++)
{
digitalWrite(e2,LOW);
PORTD=seg_code[j];
delay(100);
digitalWrite(e2,HIGH);

digitalWrite(e1,LOW);
PORTD=seg_code[k];
delay(100);
digitalWrite(e1,HIGH);

digitalWrite(e3,LOW);
PORTD=seg_code[l];
delay(100);
Mansi Jesani 18ec036

digitalWrite(e3,HIGH);
}
}
}
}

IV. Display 0000 to 9999 on segment

Code:-

#define e1 8
#define e2 9
#define e3 10
#define e4 11

void setup()
{
for(int i=0;i<=11;i++)
{
pinMode(i,OUTPUT);
}
}

int seg_code[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
Mansi Jesani 18ec036

void loop()
{
for(int j=0;j<=9;j++)
{
for(int k=0;k<=9;k++)
{
for(int l=0;l<=9;l++)
{
for(int m=0;m<=9;m++)
{
digitalWrite(e2,LOW);
PORTD=seg_code[j];
delay(100);
digitalWrite(e2,HIGH);
digitalWrite(e1,LOW);
PORTD=seg_code[k];
delay(100);
digitalWrite(e1,HIGH);

digitalWrite(e3,LOW);
PORTD=seg_code[l];
delay(100);
digitalWrite(e3,HIGH);
digitalWrite(e4,LOW);
PORTD=seg_code[m];
delay(100);
digitalWrite(e4,HIGH);
}
}
}
}
}
Mansi Jesani 18ec036

RELAY INTERFACING

1. Led flash using Relay.

Code:
void setup() {
pinMode(3, OUTPUT);
}
void loop() {
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(1000);
}
Mansi Jesani 18ec036

DC MOTOR INTERFACING
1) Rotate motor clockwise and anticlockwise for 1second.

Code:
#define mp 2
#define mn 3
void setup() {
pinMode(mp, OUTPUT);
pinMode(mn, OUTPUT);
}
void loop() {
digitalWrite(mp, HIGH);
digitalWrite(mn, LOW);
delay(1000);
digitalWrite(mp, LOW);
digitalWrite(mn, HIGH);
delay(1000);
}
Mansi Jesani 18ec036

2) Rotate motor clockwise and anticlockwise using switch


 If SW open, rotate clockwise
 If SW close, rotate anticlockwise

CODE :-
void setup()
{
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
pinMode(6, INPUT);
}
void loop()
{
digitalRead(6);
if (digitalRead(6)==0)
{
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
}
else
{
digitalWrite(8, LOW);
digitalWrite(12, HIGH);
Mansi Jesani 18ec036

}
delay(100); // Delay a little bit to improve simulation performance
}

3) Enter password
 if password right then door open(motor rotate clockwise); otherwise close

Code:
#define mp 9
#define mn 10
void setup()
{
Serial.begin(9600);
pinMode(mp,OUTPUT);
pinMode(mn,OUTPUT);
}
char trx=0;
void loop()
{
// if(Serial.available()>0)
//{
trx=Serial.read();
Mansi Jesani 18ec036

// }
if(trx=='A')
{
digitalWrite(mp,HIGH);
digitalWrite(mn,LOW);
delay(1000);
Serial.println("unlocked");
digitalWrite(mp,LOW);
}
else
{
digitalWrite(mp,LOW);
Serial.println("Password incorrect");
}

You might also like