SlideShare a Scribd company logo
1 of 4
Download to read offline
Connect a motor, two push buttons and two LEDS to the Arduino as shown below. The fan
should operate as listed.
Begin with
int buttonPin1 = 2;
int buttonPin2 = 4;
int ledPinGreen = 11;
int ledPinRed = 6;
int motorPin = 9;
Please program in Arduino as the following:
1. Fan is started or stopped by pressing push button 1
When starting the fan, ramp up using 110ms delay from 0 to 4 volts (levels 0 to 200), fan
remains running at 4 volts.
When stopping the fan, slow down using the same values (110ms delay and level 200 to 0).
2. When operator presses the overload switch (button 2), fan starts working at full speed (255)
and the overload alarm is lit (red LED).
3. When the overload switch (button 2) is pressed again, fan returns to normal operation at 4
volts (level 200).
4. Pressing the overload button when the fan is not operating has no effect.
5. Anytime the fan is on, on/off indictor is lit, otherwise it is off.
Solution
const int buttonPin1 = 2;
const int buttonPin2 = 4;
const int ledPinGreen = 11;
const int ledPinRed = 6;
const int motorPin = 9
//state varibles
boolean B1_state = false; //button 1 state
boolean B2_state = false; //button 2 state
// function declaration
void motorRun_Stop(boolean);
void overload(boolean,boolean);
void setup()
{
Serial.begin(9600); // for debugging
pinMode(buttonPin1,INPUT); // declaring as input
digitalWrite(buttonPin1,HIGH); // activating the pullup resistor
pinMode(buttonPin2,INPUT); // declaring as input
digitalWrite(buttonPin1,HIGH); // activating the pullup resistor
pinMode(ledPinGreen,OUTPUT);
pinMode(ledPinRed,OUTPUT);
pinMode(motorPin, OUTPUT);
}
void loop()
{
if(digitalRead(buttonPin1)== 1)
{
B1_state != B1_state;
motorRun_Stop(B1_state);
}
else if(digitalRead(buttonPin2)== 1)
{
B2_state != B2_state;
overload();
}
else
{
}
}
void motorRun_Stop(boolean x)
{
byte wait = 0;
if(x == true )
{
Serial.println("Motor has Overloaded");
digitalWrite(ledPinGreen,HIGH);
for (int i = 0; i<200;i++)
{
analogWrite(motorPin,i);
wait = micros();
while((micros()-wait)>550);
}
}
else if(x == false)
{
for (int i = 200; i>0;i--)
{
analogWrite(motorPin,i);
wait = micros();
while((micros()-wait)>550);
}
Serial.println("Motor has Stoped");
digitalWrite(ledPinGreen,LOW);
}
else
{
}
}
void overload(boolean x,boolean y)
{
byte wait = 0;
if(x == true && y == true)
{
analogWrite(motorPin,255);
Serial.println("Motor has overloaded");
digitalWrite(ledPinRed,HIGH);
}
else if(x == true && y==false)
{
analogWrite(motorPin,200);
Serial.println("Motor has stopped Overloading");
digitalWrite(ledPinRed,LOW);
}
else
{
}
}

More Related Content

Similar to Connect a motor, two push buttons and two LEDS to the Arduino as sho.pdf

Tlk43 Controller
Tlk43 ControllerTlk43 Controller
Tlk43 ControllerJoseph
 
Anole Hot Runner Controller
Anole Hot Runner ControllerAnole Hot Runner Controller
Anole Hot Runner ControllerAnole Hot Runner
 
LED Lighting Product Attachment
LED Lighting Product AttachmentLED Lighting Product Attachment
LED Lighting Product AttachmentUltra LEDs
 
Aeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualAeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualDomotica daVinci
 
Air condition remote controller
Air condition remote controllerAir condition remote controller
Air condition remote controllerNeo Hsieh
 
Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)German Nava
 
Tlk94 Controller
Tlk94 ControllerTlk94 Controller
Tlk94 ControllerJoseph
 
Adafruit arduino-lesson-15-dc-motor-reversing
Adafruit arduino-lesson-15-dc-motor-reversingAdafruit arduino-lesson-15-dc-motor-reversing
Adafruit arduino-lesson-15-dc-motor-reversingziwhanda
 
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manualWall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manualDomotica daVinci
 
Siemens room stat instructions
Siemens room stat instructionsSiemens room stat instructions
Siemens room stat instructionsMaria Isabel
 
Siemens room stat instructions
Siemens room stat instructionsSiemens room stat instructions
Siemens room stat instructionsMaria Isabel
 
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME Domotica daVinci
 
Mural Remote Z-Wave Plus Philio PSR04 Manual
Mural Remote Z-Wave Plus Philio PSR04 ManualMural Remote Z-Wave Plus Philio PSR04 Manual
Mural Remote Z-Wave Plus Philio PSR04 ManualDomotica daVinci
 

Similar to Connect a motor, two push buttons and two LEDS to the Arduino as sho.pdf (20)

Mh7 eu um v.02
Mh7 eu um v.02Mh7 eu um v.02
Mh7 eu um v.02
 
Tlk43 Controller
Tlk43 ControllerTlk43 Controller
Tlk43 Controller
 
85 0067-b5 outdoor-installation insert_web
85 0067-b5 outdoor-installation insert_web85 0067-b5 outdoor-installation insert_web
85 0067-b5 outdoor-installation insert_web
 
Anole Hot Runner Controller
Anole Hot Runner ControllerAnole Hot Runner Controller
Anole Hot Runner Controller
 
Cti troublshooting
Cti troublshootingCti troublshooting
Cti troublshooting
 
Kpnp pss user guide20170330
Kpnp pss user guide20170330Kpnp pss user guide20170330
Kpnp pss user guide20170330
 
LED Lighting Product Attachment
LED Lighting Product AttachmentLED Lighting Product Attachment
LED Lighting Product Attachment
 
Aeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualAeotec Multisensor 7 Manual
Aeotec Multisensor 7 Manual
 
85 0066-e ultimate-installation insert_web
85 0066-e ultimate-installation insert_web85 0066-e ultimate-installation insert_web
85 0066-e ultimate-installation insert_web
 
Air condition remote controller
Air condition remote controllerAir condition remote controller
Air condition remote controller
 
Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)
 
Tlk94 Controller
Tlk94 ControllerTlk94 Controller
Tlk94 Controller
 
Adafruit arduino-lesson-15-dc-motor-reversing
Adafruit arduino-lesson-15-dc-motor-reversingAdafruit arduino-lesson-15-dc-motor-reversing
Adafruit arduino-lesson-15-dc-motor-reversing
 
LaunchPad MSP 430
LaunchPad MSP 430LaunchPad MSP 430
LaunchPad MSP 430
 
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manualWall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
 
Siemens room stat instructions
Siemens room stat instructionsSiemens room stat instructions
Siemens room stat instructions
 
Siemens room stat instructions
Siemens room stat instructionsSiemens room stat instructions
Siemens room stat instructions
 
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME
Manual of Thermostat Fan Coil 4Pipes MH8 series - MCO HOME
 
Philio_pan06_User manual
Philio_pan06_User manualPhilio_pan06_User manual
Philio_pan06_User manual
 
Mural Remote Z-Wave Plus Philio PSR04 Manual
Mural Remote Z-Wave Plus Philio PSR04 ManualMural Remote Z-Wave Plus Philio PSR04 Manual
Mural Remote Z-Wave Plus Philio PSR04 Manual
 

More from amrishinda

JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
 
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdf
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdfLet f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdf
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdfamrishinda
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
If a cells contents are greatly hypo-osmotic to the surrounding env.pdf
If a cells contents are greatly hypo-osmotic to the surrounding env.pdfIf a cells contents are greatly hypo-osmotic to the surrounding env.pdf
If a cells contents are greatly hypo-osmotic to the surrounding env.pdfamrishinda
 
How are the forelimbs of humans, the wings of birds, the wings of ba.pdf
How are the forelimbs of humans, the wings of birds, the wings of ba.pdfHow are the forelimbs of humans, the wings of birds, the wings of ba.pdf
How are the forelimbs of humans, the wings of birds, the wings of ba.pdfamrishinda
 
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdf
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdfFom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdf
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdfamrishinda
 
Germ cells are set aside during animal development and give rise to .pdf
Germ cells are set aside during animal development and give rise to .pdfGerm cells are set aside during animal development and give rise to .pdf
Germ cells are set aside during animal development and give rise to .pdfamrishinda
 
Determine the missing amounts. (Hint For example, to solve for (a), .pdf
Determine the missing amounts. (Hint For example, to solve for (a), .pdfDetermine the missing amounts. (Hint For example, to solve for (a), .pdf
Determine the missing amounts. (Hint For example, to solve for (a), .pdfamrishinda
 
Discuss the various methods of intellectual property protection avai.pdf
Discuss the various methods of intellectual property protection avai.pdfDiscuss the various methods of intellectual property protection avai.pdf
Discuss the various methods of intellectual property protection avai.pdfamrishinda
 
devise a hypothesis that explains the geographical distribution of m.pdf
devise a hypothesis that explains the geographical distribution of m.pdfdevise a hypothesis that explains the geographical distribution of m.pdf
devise a hypothesis that explains the geographical distribution of m.pdfamrishinda
 
Describe a diode array detector and CCD camera. Differentiate betwee.pdf
Describe a diode array detector and CCD camera. Differentiate betwee.pdfDescribe a diode array detector and CCD camera. Differentiate betwee.pdf
Describe a diode array detector and CCD camera. Differentiate betwee.pdfamrishinda
 
Consider managers (supervisors) that you have worked for in the past.pdf
Consider managers (supervisors) that you have worked for in the past.pdfConsider managers (supervisors) that you have worked for in the past.pdf
Consider managers (supervisors) that you have worked for in the past.pdfamrishinda
 
Caterpillar is one of the Americas major exporters. The company sell.pdf
Caterpillar is one of the Americas major exporters. The company sell.pdfCaterpillar is one of the Americas major exporters. The company sell.pdf
Caterpillar is one of the Americas major exporters. The company sell.pdfamrishinda
 
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdf
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdfwhat numbers go with these descriptions.1. Uses ATP hydrolysis2..pdf
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdfamrishinda
 
What are the three forms of Business Organizations Answer the follow.pdf
What are the three forms of Business Organizations Answer the follow.pdfWhat are the three forms of Business Organizations Answer the follow.pdf
What are the three forms of Business Organizations Answer the follow.pdfamrishinda
 
Anatomy Question Use your own words.A girl with a defective heart.pdf
Anatomy Question Use your own words.A girl with a defective heart.pdfAnatomy Question Use your own words.A girl with a defective heart.pdf
Anatomy Question Use your own words.A girl with a defective heart.pdfamrishinda
 
Why parkinsons disease is special among the different neurological.pdf
Why parkinsons disease is special among the different neurological.pdfWhy parkinsons disease is special among the different neurological.pdf
Why parkinsons disease is special among the different neurological.pdfamrishinda
 
Which statement is not true promoters are transcribed the Pribnow .pdf
Which statement is not true  promoters are transcribed  the Pribnow .pdfWhich statement is not true  promoters are transcribed  the Pribnow .pdf
Which statement is not true promoters are transcribed the Pribnow .pdfamrishinda
 
When extracting DNA of an fruit how does the environemnt (how hot or.pdf
When extracting DNA of an fruit how does the environemnt (how hot or.pdfWhen extracting DNA of an fruit how does the environemnt (how hot or.pdf
When extracting DNA of an fruit how does the environemnt (how hot or.pdfamrishinda
 
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdf
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdfWhich ANN do you prefer amidst of the variety of ANNs Justify the r.pdf
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdfamrishinda
 

More from amrishinda (20)

JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdf
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdfLet f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdf
Let f(z) be an entire function such that fn+1(z) equivalent 0, Prove.pdf
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
If a cells contents are greatly hypo-osmotic to the surrounding env.pdf
If a cells contents are greatly hypo-osmotic to the surrounding env.pdfIf a cells contents are greatly hypo-osmotic to the surrounding env.pdf
If a cells contents are greatly hypo-osmotic to the surrounding env.pdf
 
How are the forelimbs of humans, the wings of birds, the wings of ba.pdf
How are the forelimbs of humans, the wings of birds, the wings of ba.pdfHow are the forelimbs of humans, the wings of birds, the wings of ba.pdf
How are the forelimbs of humans, the wings of birds, the wings of ba.pdf
 
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdf
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdfFom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdf
Fom 1120, Sched Mark for follow up Question 15 of 105. A corporat.pdf
 
Germ cells are set aside during animal development and give rise to .pdf
Germ cells are set aside during animal development and give rise to .pdfGerm cells are set aside during animal development and give rise to .pdf
Germ cells are set aside during animal development and give rise to .pdf
 
Determine the missing amounts. (Hint For example, to solve for (a), .pdf
Determine the missing amounts. (Hint For example, to solve for (a), .pdfDetermine the missing amounts. (Hint For example, to solve for (a), .pdf
Determine the missing amounts. (Hint For example, to solve for (a), .pdf
 
Discuss the various methods of intellectual property protection avai.pdf
Discuss the various methods of intellectual property protection avai.pdfDiscuss the various methods of intellectual property protection avai.pdf
Discuss the various methods of intellectual property protection avai.pdf
 
devise a hypothesis that explains the geographical distribution of m.pdf
devise a hypothesis that explains the geographical distribution of m.pdfdevise a hypothesis that explains the geographical distribution of m.pdf
devise a hypothesis that explains the geographical distribution of m.pdf
 
Describe a diode array detector and CCD camera. Differentiate betwee.pdf
Describe a diode array detector and CCD camera. Differentiate betwee.pdfDescribe a diode array detector and CCD camera. Differentiate betwee.pdf
Describe a diode array detector and CCD camera. Differentiate betwee.pdf
 
Consider managers (supervisors) that you have worked for in the past.pdf
Consider managers (supervisors) that you have worked for in the past.pdfConsider managers (supervisors) that you have worked for in the past.pdf
Consider managers (supervisors) that you have worked for in the past.pdf
 
Caterpillar is one of the Americas major exporters. The company sell.pdf
Caterpillar is one of the Americas major exporters. The company sell.pdfCaterpillar is one of the Americas major exporters. The company sell.pdf
Caterpillar is one of the Americas major exporters. The company sell.pdf
 
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdf
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdfwhat numbers go with these descriptions.1. Uses ATP hydrolysis2..pdf
what numbers go with these descriptions.1. Uses ATP hydrolysis2..pdf
 
What are the three forms of Business Organizations Answer the follow.pdf
What are the three forms of Business Organizations Answer the follow.pdfWhat are the three forms of Business Organizations Answer the follow.pdf
What are the three forms of Business Organizations Answer the follow.pdf
 
Anatomy Question Use your own words.A girl with a defective heart.pdf
Anatomy Question Use your own words.A girl with a defective heart.pdfAnatomy Question Use your own words.A girl with a defective heart.pdf
Anatomy Question Use your own words.A girl with a defective heart.pdf
 
Why parkinsons disease is special among the different neurological.pdf
Why parkinsons disease is special among the different neurological.pdfWhy parkinsons disease is special among the different neurological.pdf
Why parkinsons disease is special among the different neurological.pdf
 
Which statement is not true promoters are transcribed the Pribnow .pdf
Which statement is not true  promoters are transcribed  the Pribnow .pdfWhich statement is not true  promoters are transcribed  the Pribnow .pdf
Which statement is not true promoters are transcribed the Pribnow .pdf
 
When extracting DNA of an fruit how does the environemnt (how hot or.pdf
When extracting DNA of an fruit how does the environemnt (how hot or.pdfWhen extracting DNA of an fruit how does the environemnt (how hot or.pdf
When extracting DNA of an fruit how does the environemnt (how hot or.pdf
 
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdf
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdfWhich ANN do you prefer amidst of the variety of ANNs Justify the r.pdf
Which ANN do you prefer amidst of the variety of ANNs Justify the r.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 

Recently uploaded (20)

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 

Connect a motor, two push buttons and two LEDS to the Arduino as sho.pdf

  • 1. Connect a motor, two push buttons and two LEDS to the Arduino as shown below. The fan should operate as listed. Begin with int buttonPin1 = 2; int buttonPin2 = 4; int ledPinGreen = 11; int ledPinRed = 6; int motorPin = 9; Please program in Arduino as the following: 1. Fan is started or stopped by pressing push button 1 When starting the fan, ramp up using 110ms delay from 0 to 4 volts (levels 0 to 200), fan remains running at 4 volts. When stopping the fan, slow down using the same values (110ms delay and level 200 to 0). 2. When operator presses the overload switch (button 2), fan starts working at full speed (255) and the overload alarm is lit (red LED). 3. When the overload switch (button 2) is pressed again, fan returns to normal operation at 4 volts (level 200). 4. Pressing the overload button when the fan is not operating has no effect. 5. Anytime the fan is on, on/off indictor is lit, otherwise it is off. Solution const int buttonPin1 = 2; const int buttonPin2 = 4; const int ledPinGreen = 11; const int ledPinRed = 6; const int motorPin = 9 //state varibles boolean B1_state = false; //button 1 state boolean B2_state = false; //button 2 state // function declaration void motorRun_Stop(boolean); void overload(boolean,boolean); void setup()
  • 2. { Serial.begin(9600); // for debugging pinMode(buttonPin1,INPUT); // declaring as input digitalWrite(buttonPin1,HIGH); // activating the pullup resistor pinMode(buttonPin2,INPUT); // declaring as input digitalWrite(buttonPin1,HIGH); // activating the pullup resistor pinMode(ledPinGreen,OUTPUT); pinMode(ledPinRed,OUTPUT); pinMode(motorPin, OUTPUT); } void loop() { if(digitalRead(buttonPin1)== 1) { B1_state != B1_state; motorRun_Stop(B1_state); } else if(digitalRead(buttonPin2)== 1) { B2_state != B2_state; overload(); } else { } } void motorRun_Stop(boolean x) { byte wait = 0; if(x == true ) { Serial.println("Motor has Overloaded"); digitalWrite(ledPinGreen,HIGH); for (int i = 0; i<200;i++) { analogWrite(motorPin,i);
  • 3. wait = micros(); while((micros()-wait)>550); } } else if(x == false) { for (int i = 200; i>0;i--) { analogWrite(motorPin,i); wait = micros(); while((micros()-wait)>550); } Serial.println("Motor has Stoped"); digitalWrite(ledPinGreen,LOW); } else { } } void overload(boolean x,boolean y) { byte wait = 0; if(x == true && y == true) { analogWrite(motorPin,255); Serial.println("Motor has overloaded"); digitalWrite(ledPinRed,HIGH); } else if(x == true && y==false) { analogWrite(motorPin,200); Serial.println("Motor has stopped Overloading"); digitalWrite(ledPinRed,LOW); }