Week Outline

  1. Wednesday: Global Class on Input Devices.
  2. Friday: Local Classes on Input Devices.
  3. Monday: Recitation on Machine Building.
  4. Wednesday: Global Review.

Global Class

Local Classes

Our local class this week consisted of experimenting with multiple input devices:

Button LED Circuit

We started with the above pictured simple circuit with a button and an LED.

Then, we moved onto a more complex version of it. We wanted to digitally read if the button was being pressed, so we hooked up the button to our Barduino:

Button Signal Circuit

So after we set the circuit up, we wrote the following code:

#define PIN 17

void setup () {
pinMode(PIN, INPUT);

Serial.begin(15200);
}

void loop () {
int reading = digitalRead(PIN);

Serial.println(reading);

delay(20);

}

We then sent the code to our Barduino using the Arduino IDE, and as you can see below, we could see when the button was being pushed via the serial monitor.

Then we wanted to see the effect of a resistor on the circuit, so we set up the following circuit:

Transistor Circuit

And we used the following code to see the effect on the serial monitor:

I got bored while Josep and Dani explained things to other people so I incorporated an LED light into the system to regulate its luminosiity:

Then, using the same code as for the transistor, we put a phototransistor into the circuit to see how the voltage reading on it was affected with more or less light exposure:

Phototransistor Circuit

Josep and Dani had to stop again to explain things for others so I did the same thing as with the resistor:

Once we got going, we paired up into teams of two and tested differrent input devices. Ed and I decided to test the KY-027 Magic Light Cup modules:

Magic Light Cup Modules Circuit

We used the following code:

int ledPinA = 15;
int switchPinA = 13;
int switchStateA = 0;
int ledPinB = 8;
int switchPinB = 10;
int switchStateB = 0;
int brightness = 0;

void setup()
{
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);

pinMode(switchPinA, INPUT);
pinMode(switchPinB, INPUT);
}

void loop()
{
switchStateA = digitalRead(switchPinA);
if (switchStateA == HIGH && brightness != 255)
{
brightness ++;
}
switchStateB = digitalRead(switchPinB);
if (switchStateB == HIGH && brightness != 0)
{
brightness --;
}
analogWrite(ledPinA, brightness); // A slow fade out
analogWrite(ledPinB, 255 - brightness); // B slow bright up
delay(20);
}

and we got the following result:

Assignments

1. Probe an input device(s)'s analog levels and digital signals as a group.

The documentation of the work we did can be found here.

2. Measure something: add a sensor to a microcontroller board that you have designed and read it.

Basic Board Soldered

Pictured above, is first version of my final project's granddaughterboard (which is a magnetic hall effect sensor), connected to the first version of my final project's daughterboard, which is connected to the programmer I use for connecting the daughterboard to the computer.

Using the following code:

#define sensorPin = PIN_PA7; // interface pin with magnetic sensor
int val; // variable to store read values

void setup() {
pinMode(PIN_PA7, INPUT); // set analog pin as input
Serial.begin(115200); // initialize serial interface
}

void loop() {
val = analogRead(sensorPin); // read sensor value
Serial.println(val); // print value to serial

delay(10000);
}