Arduino Programming and Power Interfacing: Chanh Le 3/1/2018 011048232
Arduino Programming and Power Interfacing: Chanh Le 3/1/2018 011048232
SID: 011048232
Summary
What was learned in the assignment:
This homework was more difficult than all the previous ones. I learned to construct a schematic diagram for a
custom LED and make an interface for it connecting to the Arduino Pin 12. There are many free circuit schematic
makers on internet that’s beyond helpful for students. I used https://easyeda.com/editor to draw my schematic.
While doing question 1, I realized how important is the transistor in controlling the current through my LED. By
turning a small input current into a large output current, the transistor acts like an amplifier. But it also acts like
a switch at the same time. When there is no current to the base, little or no current flows between the collector
and the emitter.
Problem 2 was interested enough that kept my brain fried for the past two days. I got the LED 2 and 9 flashed
after multiple tries from last homework. However, I can’t turn verify whether pin 12 Is working properly. I don’t
have the LED in given problem.
1. (10 pts) Design an interface between the Arduino pin 12 and a Fairchild QED233 IR LED. Assume that
you have a 12 V power supply available to power the LED, and that you need to supply at least 80
mA to drive the LED for a particular application. Document your interface with a schematic diagram
that shows all the components involved in the interface, their specific values, and all the
connections including the Arduino. You are welcome to draw your schematic by hand, but you might
find it helpful to get practice using some software tools that facilitate drawing schematics. There are
a host of readily available tools to draw schematics. On the ‘just graphics’ end of the spectrum, you
can use Microsoft Office drawing tools, or Microsoft Visio (which has Electrical Engineering
symbols). There are more specific schematic capture programs such as Multisim (available in the
Mechatronics lab or from ni.com), DipTrace, Eagle, etc. that you might want to explore. One simple
freeware system is Circuit Maker, which you can download from:
Spec 3N3904
𝑉𝑏𝑒 = 0.7𝑉
ℎ𝑓𝑒 = 30
𝐼𝑐 = 200𝑚𝐴
𝑖𝑐 = ℎ𝑓𝑒 ∗ 𝑖𝑏
100𝑒 3
𝑖𝑏 = = 3.3𝑚𝐴
30
𝑉𝐴𝑟𝑑𝑢𝑖𝑛𝑜 − 𝑉𝑁𝑃𝑁
𝑅𝐵 =
𝑖𝐵
(5-0.7)/3.3𝑒 3 =1303 Ω
2. (10 pts) Revisit Problem 2 from HW 4 (Cylon Eyes with buttons), but revise it in the following ways:
a. Blink the IR LED from Problem 1 above instead of blinking the LED segments 2 and 9 when
both buttons SW11 and SW10 are pressed.
b. Write your revised Cylon Eyes with buttons program using a state machine approach as
outlined in lecture. Conceptualize your state machine with at least three states:
1) ‘Cylon-ing’ 2) Blinking the IR LED on 3) Blinking the IR LED off. Your state machine should
respond to events of the button presses and a millis()-based ‘timer’ expiration to blink the IR
LED on and off at 2 Hz.
You can add more states or modify the suggested conceptualization of the state machine if
another configuration makes more sense to you. For example, maybe you prefer to
conceptualize the single state, ‘Cylon-ing’ as two states: Cylon-ing_RIGHT and Cylon-
ing_LEFT where transition between these two states occur on reaching the max or min value
of a counter for the LED segments. The state machine and Events-Services approach is a way
to help you organize, design, and test your software before you even start typing it in. There
is no single, right way to conceptualize your software using this approach.
Include in your submission a figure showing your state diagram with events labeled. Make
sure you also comment your Arduino code.
#define SW10 10
#define PIN9 9
#define PIN8 8
#define PIN7 7
#define PIN6 6
#define PIN5 5
#define PIN4 4
#define PIN3 3
#define PIN2 2
#define PIN1 1
#define PIN0 0
int dir = 1; // dir = direction, variable used to control direction of LED lights
int BUTTON_STATUS = 0; // to be used to control the switch statement of the button reading
int TIME_STATUS = 0;
return digitalRead(currentSwitch);
digitalWrite(LED_current,!digitalRead(LED_current));
digitalWrite(LED_current,HIGH); //turn on
digitalWrite(LED_current,LOW);
void both_led_pushed() // if both switches are pushed, blink the IR LED at the desired ra
te
int switchTime = 0;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
digitalWrite(PIN12,ledState);
digitalWrite(PIN12,ledState);
// find out if the time that has passed has reached the threshold
void setup()
//Serial.begin(9600);
byte i;
pinMode(SW10,INPUT); //
pinMode(SW10,INPUT_PULLUP);
void loop() {
switch (BUTTON_STATUS)
case (switchState_4):
break;
break;
break;
break;}
switch (TIME_STATUS)
case (switchTime_1):{
LED_current = LED_current+dir; // make the next led in series the current led
break;
break;
#define SW11 11
#define SW10 10
#define PIN12 12
#define PIN9 9
#define PIN8 8
#define PIN7 7
#define PIN6 6
#define PIN5 5
#define PIN4 4
#define PIN3 3
#define PIN2 2
#define PIN1 1
#define PIN0 0
int dir = 1; // dir = direction, variable used to control direction of LED lights
int BUTTON_STATUS = 0; // to be used to control the switch statement of the button reading
int TIME_STATUS = 0;
return digitalRead(currentSwitch);
digitalWrite(LED_current,!digitalRead(LED_current));
digitalWrite(LED_current,HIGH); //turn on
digitalWrite(LED_current,LOW);
void both_led_pushed() // if both switches are pushed, blink the IR LED at the desired ra
te
int switchTime = 0;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
digitalWrite(PIN12,ledState);
digitalWrite(PIN12,ledState);
// find out if the time that has passed has reached the threshold
void setup()
//Serial.begin(9600);
byte i;
pinMode(SW10,INPUT); //
pinMode(SW10,INPUT_PULLUP);
void loop() {
switch (BUTTON_STATUS)
case (switchState_4):
break;
break;
break;
break;}
switch (TIME_STATUS)
case (switchTime_1):{
LED_current = LED_current+dir; // make the next led in series the current led
break;
break;