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

group 4 code

Uploaded by

Wilson
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)
32 views

group 4 code

Uploaded by

Wilson
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/ 7

1.

Led blinking
#define LED 1
void setup() {
pinMode(LED,OUTPUT);

void loop() {
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);

}
2. 2led blinking simultaneously
#define LED1 1
#define LED2 2
void setup() {
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

void loop() {
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
delay(1000);

}
3. 2led blinking alternatively
#define LED1 2
#define LED2 13
void setup() {
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

void loop() {
if(LED1==HIGH,LED2==LOW){
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
delay(2000);
}
if(LED2==HIGH,LED1==LOW){
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
delay(2000);
}

}
4. Led blinking on the push button press
#define PUSHBUTTON 4
#define LED 1
void setup() {
pinMode(PUSHBUTTON,INPUT);
pinMode(LED,OUTPUT);

void loop() {
digitalRead(4);
if(digitalRead(PUSHBUTTON)
==HIGH){
digitalWrite(LED,HIGH);
}
else{
PUSHBUTTON==LOW;
digitalWrite(LED,LOW);
}

}
5. Beep buzzer 5times, led blinking
#define BUZZER 2
#define LED 5
void setup() {
pinMode(BUZZER,OUTPUT);
pinMode(LED,OUTPUT);
digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);
delay(1000);
digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);
delay(1000);
digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);
delay(1000);
digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);
delay(1000);
digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);

void loop() {
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);

}
6. Toggle switch using push button and led
#define PUSHBUTTON 12
#define LED 13
int currentstate=1;
int oldstate=0;
void setup() {
// put your setup code here, to run once:
pinMode(PUSHBUTTON,INPUT);
pinMode(LED,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int currentstate=digitalRead(PUSHBUTTON);
int oldstate=digitalRead(PUSHBUTTON);
if(currentstate==1){
digitalWrite(LED,HIGH);
}
if(oldstate==0){
digitalWrite(LED,LOW);
}

}
7. Led brightness control using single push button
#define PUSHBUTTON A1
#define LED 4
void setup() {
// put your setup code here, to run once:
pinMode(PUSHBUTTON,INPUT);
pinMode(LED,HIGH);
}

void loop() {
// put your main code here, to run repeatedly:
float signal=analogRead(PUSHBUTTON)*5/1023;
if(signal>3.6){
digitalWrite(LED,HIGH);
if(signal<3.6){
digitalWrite(LED,LOW);
}
}
delay(1000);
}
8. Led brightness control using two push buttons
#define PUSHBUTTON1 A2
#define PUSHBUTTON2 A1
#define LED 4
void setup() {
// put your setup code here, to run once:
pinMode(PUSHBUTTON1,INPUT);
pinMode(PUSHBUTTON2,INPUT);
pinMode(LED,HIGH);
}

void loop() {
// put your main code here, to run repeatedly:
float signal=digitalRead(PUSHBUTTON1)*5/1023;
float signal=digitalRead(PUSHBUTTON2)*5/1023;
if(signal>3.6){
digitalWrite(LED,HIGH);
if(signal<3.6){
digitalWrite(LED,LOW);
}
}
delay(1000);
}
9. Dark switch
#define LDR A2
#define LED 4
void setup() {
// put your setup code here, to run once:
pinMode(LDR,INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
float Sensordata=analogRead(LDR)*5/1023;
if(Sensordata>3.5){
digitalWrite(LED,HIGH);
}
else{
digitalWrite(LED,LOW);
}
}
10. Fan temperature control, sensor specs 20mv/C
#define FAN 5
#define TEMPSENSOR A3
void setup() {
// put your setup code here, to run once:
pinMode(TEMPSENSOR,INPUT);
pinMode(FAN,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
float temperature=analogRead(TEMPSENSOR)*5/1023*1000/20;
if(temperature>=37.5){
digitalWrite(FAN,HIGH);
}
else{
digitalWrite(FAN,LOW);
}
}
11. Car control based on alcohol detection; including buzzer, and engine control
#define MQ3 A0
#define BUZZER 5
#define ENGINE 6
void setup() {
// put your setup code here, to run once:
pinMode(MQ3,INPUT);
pinMode(BUZZER,OUTPUT);
pinMode(ENGINE,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int alcohol=analogRead(MQ3)*5/1023;
if(alcohol>=40){
digitalWrite(BUZZER,HIGH);
digitalWrite(ENGINE,LOW);
}
else{
digitalWrite(BUZZER,LOW);
digitalWrite(ENGINE,HIGH);
}
}
12. PIR based security system with light control
#define PIR 6
#define LDR A1
#define BUZZER 7
#define LED 4
void setup() {
// put your setup code here, to run once:
pinMode(PIR,INPUT);
pinMode(LDR,INPUT);
pinMode(BUZZER,OUTPUT);
pinMode(LED,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
int motion=digitalRead(PIR);
float light=analogRead(LDR)*5/1023;
//noon;
if (motion==1){
digitalWrite(BUZZER,HIGH);
}
else{
digitalWrite(BUZZER,LOW);
}
//night;
if(motion==1&&light>3.7);{
digitalWrite(BUZZER,HIGH);
digitalWrite(LED,HIGH);
}
if (motion==0&&light<3.7);{
digitalWrite(BUZZER,LOW);
digitalWrite(LED,LOW);
}
}
13. Door access control based on people counter
#define IRin 4
#define IRout 13
#define LDR A3
#define LCD (5,6,7,8,9)
#define LED 5
#define FAN 11
int count;
void setup() {
// put your setup code here, to run once:
pinMode(IRin,INPUT);
pinMode(IRout,INPUT);
pinMode(LDR,INPUT);
pinMode(LCD,OUTPUT);
pinMode(LED,OUTPUT);
pinMode(FAN,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int infrared=digitalRead(IRin);
float lampdetector=analogRead(LDR)*5/1023;
if(digitalRead(IRin)==LOW){
count++;
}
else if(digitalRead(IRout)==LOW){
count--;
}
else if (count>0&&LDR>3.5){
digitalWrite(FAN&&LED,HIGH);
}
else if (count<=0&&LDR<3.5){
digitalWrite(FAN&&LED,LOW);

}
}

You might also like