Arduino

Arduino 1

4) Short answer questions:

a. [6 Points] Mention three different methods to program an Arduino processing board? 1.

2.

3.

b. [4 Points] Provide the C (not Ardiuno) program statement to set ONLY PORTB pins 1 and 7 to logic one. Use bit–manipulation techniques.

c. [4 Points] Provide the C (not Ardiuno) program statement to reset ONLY PORTB pins 1 and 7 to logic zero. Use bit–manipulation techniques.

d. [Lecture Attendance Problem: 6 Points] Given a sinusoid with 500 Hz frequency, what should be the minimum sampling frequency for an analog-to-digital converter, if we want to faithfully reconstruct the analog signal after the conversion? What is the name of the theorem that solves this problem? This was discussed in the Lecture several times.

e. [5 Points] Does the time to convert an analog input signal to a digital representation vary in a successive approximation converter relative to the magnitude of the input signal?

Circle your answer: YES NO

Explain your answer very briefly.

f. [5 Points] If an analog signal is converted by an analog-to-digital converter to a binary representation and then back to an analog voltage using a DAC, will the original analog input voltage be the same as the resulting analog output voltage?

Circle your answer: YES NO. Explain your answer very briefly.

g. [10 Points] Describe the flow of events when an interrupt occurs.

h. [Lecture Attendance Problem: 4 Points] There are two methods to doing GPIO that we discussed in Lecture. Name them. In the lecture, we had a funny unscientific name to one of them, mention it.

1.

2.

5) [15 Points] Given the code below:

a. Comment on each line of code as to what does that line of code do.

Use the comment symbols

b. Convert the Ardiuno Library functions except delay() to C code that manipulates the registers of the PORTs.

int led = 13; _______________________________________________________

void setup() { _______________________________________________________

pinMode(led, OUTPUT); ___________________________________________________

___________________________________________________________________________

} void loop() { _______________________________________________________

digitalWrite(led, HIGH); _____________________________________________________

___________________________________________________________________________

delay(1000); _________________________________________________________

digitalWrite(led, LOW); _____________________________________________________

____________________________________________________________________________

delay(1000); _________________________________________________________

Arduino 2

6) [25 Points] A Temperature sensor circuit is described in the code below.

a. [5 pts] Construct the circuit similar to the figure above i.e. draw the circuit schematic.

b. [5 pts] Modify the behavior of the circuit you have drawn in part a above and change the code below as necessary to light up a single LED for 100 milliseconds if the temperature goes above 75 degrees F.

c. [2 pts] Which of these two variables degreesC or degreesF is declared in the code below? Which one can you compare against?

d. [6 pts] Answer the questions in the comment next to each statement in the code.

e. [7 pts] Add the necessary modifications to the circuit that would cope with your changes to light up the LED when the temperature is between 75 degrees F and 85 degrees.

/*TEMPERATURE SENSOR

Use the "serial monitor" window to read a temperature sensor.

The TMP36 is an easy-to-use temperature sensor that outputs a voltage that's proportional to the ambient temperature.

Hardware connections:

The temperature sensor has a triangle logo and "TMP" in very tiny letters.

When looking at the flat side of the temperature sensor with the pins down, from left to right the pins are: 5V, SIGNAL, and GND.

Connect the 5V pin to 5 Volts (5V).

Connect the SIGNAL pin to ANALOG pin 0.

Connect the GND pin to ground (GND).

We'll use analog input 0 to measure the temperature sensor's signal pin. It analog input pin reads a value between 0 and 1024.

*/

const int temperaturePin = 0;

void setup()

{

// What does this function do? __________________________________________________

Serial.begin(9600);

}

// Why does this function return void? _______________________________________________________

void loop()

{

float voltage, degreesC, degreesF;

// What is the purpose of each of the statements below?

voltage = getVoltage(temperaturePin); //____________________________________________________

// Now we'll convert the voltage to degrees Celsius.

degreesC = (voltage - 0.5) * 100.0; //______________________________________________________

degreesF = degreesC * (9.0/5.0) + 32.0; //__________________________________________________

Serial.print("voltage: ");

Serial.print(voltage);

Serial.print(" deg C: ");

Serial.print(degreesC);

Serial.print(" deg F: ");

Serial.println(degreesF);

delay(1000);

}

float getVoltage(int pin)

{

return (analogRead(pin) * 0.004882814);____________________________________________________