Sunday, April 29, 2012

Week 16 - Photo Resistor with Arduino!

This week I connected a Photo Resistor to the Arduino. After following the kit and controlling an LED to fade on and off, I decided to connect it to a Servo. Using the Knob example in the Arduino Library, the photo resister just worked. Very Cool. Seeing how the mapping was set differently for the LED vs the SERVO was good to see. It makes sense to.



Also this week we had a drive at work to donate or old computer hardware. I've been wanting to give a bunch of computers to those who can find use for it, but instead I kept piling more computers up in the house. Ugh!

Well, with this oportunity to have it right at work, I dove into different places I stacked old computers and moitors up and brought it all on in. I was able to find and give 6 desktops, 1 17inch monitor, and a 2 printers for the cause. Happy to help out knowing they will be put to use again, and glad to see some room back in storage. WOOT!

Sunday, April 22, 2012

Week 15 - Fix Computer and Clean

So this week was fairly uneventful due to a time sync of fixing a family member's computer. Ugh I hate doing these. I only do it now for friends and family, but I don't think anyone who doesn't do this realizes just how much time goes into this.

I could have done an Arduino thing this week as well, but the weekend and spring cleaning got the better of me when I wasn't working on this laptop. Also there was an emergency dog sitting tonight as our neighbor was rushed to the hospital, and that kinda of diverted my time here where I am finding myself type this up as fast as I can. Just hoping everything is alright with neighbor.

So yes the laptop, basically I have been putting this task off for a few weeks now. Family/friend Larry had his laptop's hard drive go down. I went to install a new drive and realized the potential hell of going through finding and installing drivers for it was going to be a real pain. I started the install and found the Ethernet even after the drivers not working ... great I saw this project getting worse.

I then remembered I happen to have a much better laptop I was no longer using anymore. It was just lying around collecting dust. Another friend claimed dibs on it 2 months ago and never called back, and after leaving many messages, I figured it was time to pass it on to someone who was going to really appreciate it. The nice thing was, that all the OS was installed, but it needed driver and OS updates. It also needed a major cleaning as Larry was not going to need half the stuff I had on it.

So I started initial clean on Monday. The week went and I picked up the work again on Friday night, most of the day Saturday and Sunday afternoon. Let's just say there were issues and the Microsoft updates took forever as well as updating the antivirus and cleaning out my files.

Happy to say in the end - this XPS laptop beast is running very smooth and has everything Larry needs to enjoy his new system.

Other than that - got more cleaning done around the house, and hopefully next weekend I'll get a chance to work on the backyard and maybe even the boat.

Sunday, April 15, 2012

Week 14 - Arduino Potentiometer

This week I connected a Potentiometer to the Arduino. After following the kit and controlling an LED to fade on and off, I decided to connect it to a Servo. I had some basic info to hook it up sine I already connected a Servo in a previous project. Once I had it working, I then used the button project from last week to activate and deactivate the potentiometer and servo from working.

This worked as I hoped it would. I already had the buttons still connected on the breadboard from last week so all I had to do was add its code to this weeks code and add an on/off state again to handle whether the servo and knob should respond or not.

It was also cool to see many elements working together as well.



Also this week I've been really wanting to make it to the Albright Knox Gallery to see the works of Joan Miro, which was ending this Sunday. I was able to make it the last day with friends and really enjoyed it. there wasn't as much as I had hoped, but was happy to fit this in with my busy schedule.

Doh! sorry here's the code for the Arduino if anyone is interested...


// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
// modfied by naiJenn
/* servo vars*/

#include

Servo myservo; // create servo object to control a servo

int potpin = A0; // analog pin used to connect the potentiometer
int knobval; // variable to read the value from the analog pin

/*set button info*/
const int buttonPin1 = 2; // the number of the ON pushbutton pin
const int buttonPin2 = 3; // the number of the OFF pushbutton pin
const int ledPin = 9; // the number of the LED pin
boolean onOff = false; // button state

void setup()
{
myservo.attach(11); // attaches the servo on pin 9 to the servo object
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop()
{
knobval = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
knobval = map(knobval, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)

if (digitalRead(buttonPin1) == LOW) { // button presed state = LOW
digitalWrite(ledPin, HIGH);
onOff = true;
} else if (digitalRead(buttonPin2) == LOW) { // button presed state = LOW
digitalWrite(ledPin, LOW);
onOff = false;
}
if (onOff) {
myservo.write(knobval); // sets the servo position according to the scaled value
delay(15);
}
}

Sunday, April 8, 2012

Week 13 - Arduino Buttons!

Hey this week had lots of fun playing around with push buttons on the Arduino. The original program was written differently and needed to be corrected as the LED was on from the start and pushing the button turned it off.

After fixing this I continued with the kit's notes and updated it to use two buttons - one to turn it on and one to turn it off. Then there was an addition to make the LED fade on and off, which was cool.

Then I wanted to change it to get more acquainted with both the programming and the elements involved. After playing around with the kit's final updates, I realized that you had to hold either button down for the LED to fade through it entire range on or off. So for starters, I changed the program to no longer hold the button down to fade through its entirety. One click and the LED faded through the whole range on or off. Clicking throughout the fade was controlled so that no button click was allowed until the fade was done.

Then I realized I could keep clicking the same button over and over again and it would repeat the the fade routine. So I modified it again to have an onOff state where it detected whether it was already on or off and that clicking the same button again would have no effect on the LED.






Here's the code with different stages commented out:
/*
Button
This example code is in the public domain.
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 3; // the number of the pushbutton pin
const int buttonPin2 = 2; // the number of the pushbutton pin
const int ledPin = 9; // the number of the LED pin
int value = 0;
boolean onOff = false; // button state
boolean fadeIt = false; // button state

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop(){
// fixed original example - naiJenn - used ARDX code to fix original
/*
if (digitalRead(buttonPin2) == HIGH) { // button unpresed state = HIGH
digitalWrite(ledPin, LOW);
} else if (digitalRead(buttonPin2) == LOW) { // button presed state = LOW
digitalWrite(ledPin, HIGH);
}
*/
// Use one button to turn on and one to turn off - ARDX
/*
if (digitalRead(buttonPin1) == LOW) { // button presed state = LOW
digitalWrite(ledPin, LOW);
} else if (digitalRead(buttonPin2) == LOW) { // button presed state = LOW
digitalWrite(ledPin, HIGH);
}
*/

//Now fade on/off while button pressed - ARDX
/*
if (digitalRead(buttonPin1) == LOW) { // button presed state = LOW
value--;
} else if (digitalRead(buttonPin2) == LOW) { // button presed state = LOW
value++;
}
value = constrain(value, 0 , 255);
analogWrite(ledPin, value);
delay(10);
}
*/

// naiJenn update -Fade on/off with only clicking button once - light will fade on/off through entire range
// also don't interrupt - once button is clicked - buttons won't respond till the LED is done fading through range
// also cant repeat the same button repetitively - it now holds an onOff state so once LED is on only the Off button will work and visa versa
if (!fadeIt) {
if ((digitalRead(buttonPin1) == LOW) && (onOff == true)) { // button presed state = LOW
fadeIt = true;
for (int i = 255; i >= 0; i--) {
analogWrite(ledPin, i);
delay(10);
}
analogWrite(ledPin, 0);
onOff = false;
fadeIt = false;
} else if ((digitalRead(buttonPin2) == LOW) && (onOff == false)) { // button presed state = LOW
fadeIt = true;
for (int i = 0; i <= 255; i++) {
analogWrite(ledPin, i);
delay(10);
}
analogWrite(ledPin, 255);
onOff = true;
fadeIt = false;
}
}
}



Well that's it - and Happy Bunny Day! I also built an entire rail system that controlled 4 different directions in minecraft - took some time but was a lot of fun, and I think I made it pretty efficient too.

Sunday, April 1, 2012

Week 12 - Arduino Music and Cleanup week

This week I have made Circuit 6 of the ARDX experiments for the Arduino. This experiment played with a Piezo Element which produces tones which you can then control to make notes. By setting durations and pauses you can make melodies.

The sample that the experiment plays is "Twinkle Twinkle Little Star" - and that worked fine as the setup was very easy. So I toyed with the tempo and the notes and changed it up to play "Row Your Boat", which helped me to understand how the original sketch worked. This was fun.





Ended up going to Toronto to watch the Sabres play against the Leafs. Sat just above Wayne Gretzky's Dad (cool) and Mike Myers was there. With family coming in, getting over being sick and now dealing with a food allergy (ugh), I've all to do this and clean up around the house. But, actually getting the house clean before family showed up was a big goal this week and mission completed in time. Woo hoo! Sometimes it's the little things.

So in summary got one more Arduino experiment out of the way, and got the house cleaned up in time. Not bad again considering the ailments and time constraints.