HW 6 – Sssssservo Ssssspeaker Sssssequence

Foreword:

When life gives you lemons, make lemonade. When life gives you buttons, wires, resistors, a small speaker, a servo, a microcontroller and a breadboard, make this thing. You push the button and a sequence involving servo motors and tones plays out, but only once you release the button. 

P.S. – CircuitLab saw through my tactics and now I can’t just use it and screenshot my work when I’m done. Unfortunately they didn’t hit me with that popup until I was already done editing my schematic and just needed to screenshot it… So now I’ll be using DigiKey, woo.

Code: 

Schematic:

HW 5 – Serving Up Fun With Servos :)

Foreword:

This simple program takes analog input from a LDR and maps it to a number in the range [0, 180]. Then, that value is written to the servo and it turns to that given angle. 

Code:

Schematic:

 

HW 4 – Fade vs Fade, Blinking Without Delay, Values

Fade vs. Fade

The fade we looked at previously and the fading sample sketch in Arduino achieve the same thing. The main difference is the fact that the previous example uses global variables and the loop function to manipulate the values while the example provided by Arduino uses two for loops to manipulate the values for the PWM.

 

Blinking Without Delay

To observe the behaviour of this program I printed the difference of currentMillis and previousMillis. I also printed after the condition was met that the difference of the two was greater than the value set as the interval. This way you can watch the value increase up to the condition is met and then reset back to zero and start again. 

Code:

 

Values

 

HW3 – Testing analogWrite() with LEDs

Foreword: 

The purpose of this assignment was to experiment with the setup function and loop function and also manipulating the brightness of a LED using analogWrite to vary the amount of voltage in the circuit. The circuit itself was simple to set up, only requiring two resistors, two LEDs and four wires connecting it all.

Basically, the results of the circuit indicated that the setup function runs once before everything else and then the loop function runs repeatedly indefinitely afterwards. The analogWrite varies the voltage in the circuit which allows for variable brightness in the LED.

Code:

/*Author: Russell Coke
* Testing analogWrite on LEDs
*/

int setupLED = 12, loopLED = 11;

void setup() {
//setting up serial connection
Serial.begin(9600);

//setting the pins as outputs
pinMode(setupLED, OUTPUT);
pinMode(loopLED, OUTPUT);

//turning on the setupLED
digitalWrite(setupLED, HIGH);
delay(4000);
//turning it back off
digitalWrite(setupLED, LOW);
}

void loop() {
//setting initial voltage value for the analog output
//and time of the delay
int voltage = 255, delayTime = 250;

analogWrite(loopLED, voltage);
Serial.println(voltage);
//decreasing the voltage value so brightness changes
voltage = voltage – 50;
delay(delayTime);

analogWrite(loopLED, voltage);
Serial.println(voltage);
//decreasing the voltage value so brightness changes again
voltage = voltage – 50;
delay(delayTime);

analogWrite(loopLED, voltage);
Serial.println(voltage);
//decreasing the voltage value so brightness changes again
voltage = voltage – 50;
delay(delayTime);

analogWrite(loopLED, voltage);
Serial.println(voltage);
//decreasing the voltage value so brightness changes again
voltage = voltage – 50;
delay(delayTime);

analogWrite(loopLED, voltage);
Serial.println(voltage);
//decreasing the voltage value so brightness changes one more time
voltage = voltage – 50;
delay(delayTime);

analogWrite(loopLED, voltage);
Serial.println(voltage);
delay(delayTime);
}

Circuit Schematic:

HW2 – LDR Input Circuit

Foreword

This is a replica of the circuit we made in class so building the circuit itself was not hard. The code was also similar to the one done in class so it was fairly easy to adapt it to control three LEDs. However, there were a few problems. The output received from the microcontroller was always 1023 (the max the LDR can output) for some reason. After trying other microcontrollers I determined mine was at fault somehow. In a panic, I pushed the reset button on my microcontroller and… it worked, THANKFULLY. With that out of the way, the next issue was apparently my breadboard, which had some connection issues. After some jiggling the wires eventually connected and everything was up and running. 

Things I learned:

  • I may need another new breadboard
  • The reset button is your friend if somehow analog input is not working

Code

void setup() {
    /*setting the pins that the LEDs will be connected to for digital
    output and also set up the serial connection between the computer and
    the microcontroller*/
    Serial.begin(9600);
    pinMode(12, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(10, OUTPUT);
}

void loop() {
    //store the value from the microcontroller in an integer variable
    int sensorValue = analogRead(A0);

    Serial.println(sensorValue);

    //if the value is greater than 300 only pin 12 gets a HIGH signal
    //the other two pins receive LOW
    if(sensorValue >= 300){
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    }

    //if the value is less than 300 but higher than or equal to 250
    //only pin 11 gets a HIGH signal, the other two pins receive LOW
    if(sensorValue < 300 && sensorValue >= 250){
    digitalWrite(11, HIGH);
    digitalWrite(12, LOW);
    digitalWrite(10, LOW);
    }

    //if the value is less than 250 only pin 10 gets a HIGH signal
    //the other two pins receive LOW
    if(sensorValue < 250){
    digitalWrite(10, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    }

    //delay to not mess with the serial communication
    delay(1);
}

Circuit Schematic

Assignment 1: The Bay Lights and Homemade Switch Idea

http://thebaylights.org/

The Bay Lights is an installation done by Leo Villareal. He fitted thousands of LEDs to the Golden Gate Bridge in San Francisco, California and created a dazzling light show. If I am not mistaken, I believe he left the possibility for the lighting effects and patterns to be controllable from his laptop but I am sure the option of running a preset loop is there as well by default.

—————————————————————————————————

Inspired by The Wizard of Oz, my switch idea involves clicking your heels together to close the circuit. The 5v wire coming from the microcontroller would be fixed to one heel, while the wire going to the resistor in the breadboard is fixed to the other heel. Connecting the two heels will close the circuit and light up the LED.

Here is a schematic showing the design of my switch: