Sunday, November 11, 2018

Week 2 Let the Learning Continue!!!

  


Nov. 7, 2018

Today is the day I start playing with my Arduino and work on Circuit #2.  The new vocabulary is Potentiometer or a variable resistor.  This resistor when connected with 5 volts across its tow outer pins, the middle pin outputs a voltage  between 0 and 5, depending on the position of the knob on the potentiometer.  This will control the brightness of the LED.

For this circuit  I needed 1 potentiometer, 1 LED, 1 330 resistor, and 6 wires.  Before I connected the Arduino to the computer I built the circuit according to the diagraph on page 24.  I connected my red wire to the 5v on the Arduino and then to the breadboard on the right vertical side to the bottom positive bus. Next using my black wire I connected it to the GND then to the breadboard's neg bus.
Next I used the green wire from the A0 to e7 on the breadboard.  I attached a red wire to 13 on the Arduino to j20 on the breadboard.  Next was the resistor from j21 to neg. bus straight across. I used a short orange wire from e8 to positive bus placement. My blue wire went from e6 to a neg. bus on the breadboard, finally I put the potentiometer to a6,a7,a8.  Now it is time to plug my Arduino to my computer.




Now comes the fun part.  I have learned one little mistake and the code will not work.  I was careful to make a clean copy of the code so I would have it before I started playing with it.  Below is the code I used and my LED was able to go high and low as the potentiometer knob is turned.
int sensorPin = 0;
int ledPin = 13;
void setup()
{
  pinMode(ledPin, OUTPUT);
}
                                                                       
void look()
{
  int sensorValue;
  sensorValue = analogRead(sensorPin);
    digitalWrite(ledPin, HIGH);                                               
  delay(sensorValue);
  digitalWrite(ledPin, LOW);
  delay(sensorValue);
}

 Circuit and Code Play


1.  See what happens if you use two digital pins rather than one digital and one analog pin.
 I moved the green wire from the analog pin from A0 to digital 12- the LED blinks at a stead rate the potentiometer makes no change in duration and frequency of blinking.

2.  See what happens if you use two analog pins rather than one digital and one analog pin.
      I put the green wire back to A0 then unplugged from digital 13 then put into Analog 1.  No signal was coming from A1 to J20.  LED does not blink at all.

3.  What happens if you replace analog Write  with digital Write and vice versa?
I changed all digital Writes to analog Writes  then I uploaded new code to the board.  LED flashed fast then went off.  Where as distal Write on the original code told it to turn the light off and on. 

Extension Challenge

1.  Can you control 2 lights with the same brightness or same blink rate?
   I added another red wire from 12 to 22 leaving 13 to 20.  I put on the second LED.  I was able to get both lights to blink but did not get the control that was asked for.  I changed the code and inverted the High and Low which did not work.  I was stumped.  Looking forward to reading others blog to see where I went wrong.  
  
Here is a video of the 2 LED blinking.


No comments:

Post a Comment