0% found this document useful (0 votes)
13 views7 pages

Arduino LED and Sensor Projects Guide

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)
13 views7 pages

Arduino LED and Sensor Projects Guide

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

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);

}
}

Common questions

Powered by AI

Using a single digital pin for alcohol detection limits the resolution and accuracy of detection because it only provides a binary response (above or below threshold). This approach can lead to false positives/negatives without gradient sensitivity. More complex systems could use analog inputs to provide detailed readings, enabling better calibration and validation against environmental factors .

Brightness control using two push buttons involves reading analog signals from button inputs and adjusting the LED output accordingly. Each button can increase or decrease the brightness level within an adjustable range, usually managed by PWM (Pulse Width Modulation). This demonstrates user interaction flexibility in electronic controls, allowing intuitive interface designs in consumer electronics.

The code reflects threshold-based decision-making by reading temperature sensor outputs to determine whether the ambient temperature exceeds a predefined threshold. If the temperature is greater than or equal to 37.5°C, the fan is turned on; otherwise, it is turned off . This method ensures systems activate only when needed based on environmental conditions, optimizing energy use.

An LDR is used to detect light levels. In a 'dark switch' application, the LDR reads the ambient light intensity, and when it falls below a threshold, it triggers an action like turning on an LED. This principle is applied by using 'analogRead' to measure the LDR value and comparing it to a threshold . Applications include automated lighting systems for energy saving in buildings and streetlights.

Sensor malfunction in the fan temperature control system could result in overheating if the fan is improperly activated or remains off. Similarly, in alcohol detection, a malfunction could allow a vehicle to start when it shouldn't or prevent it when safe, compromising safety functions . Both scenarios stress the need for redundant sensors or fail-safes to ensure reliability and safety in critical systems.

A push button toggles an LED state by using digital input to read button presses, changing the LED state from HIGH to LOW or vice versa in the loop. In the setup, the push button and LED are defined as inputs and outputs respectively . Challenges include contact bounce, which can cause multiple signals from a single press, resolved through debounce code or hardware debouncing circuits.

To blink two LEDs simultaneously, you would define them as separate variables, configure them as outputs using 'pinMode', and then set both to HIGH and LOW at the same delay intervals. In the given code, '#define LED1 1' and '#define LED2 2' are used, with 'digitalWrite(LED1, HIGH)' and 'digitalWrite(LED2, HIGH)' set to blink together followed by a delay . This control is significant in applications where multiple indicators are required to reflect the same state or for visual effects.

Delay-based programming can make circuits unresponsive because it stops the Arduino from doing other operations. This issue can be mitigated by using techniques like the 'millis()' function, which allows the microcontroller to perform other tasks while waiting for the next action, allowing multiple operations to run in parallel without interfering with each other .

Logical conditions in door access systems manage entry and exit by counting how many people pass sensors (IRin, IRout) and controlling the door based on occupancy. Conditions check if the IR sensors detect entry or exit to adjust the count variable and control outputs like LED and FAN based on occupancy and ambient light . Its complexity lies in accurately tracking counts under rapid entries/exits and environmental conditions, requiring careful synchronization and calibration of sensors.

PIR sensors improve security systems by detecting motion. When combined with an LDR, they provide additional functionality, such as only activating alarms or lights in dark conditions to save energy and reduce false alarms. In the described setup, they trigger a buzzer when motion is detected and conditionally activate lights at night . This sophisticated sensor integration ensures resource-efficient and accurate security responses.

You might also like