Friday, 4 March 2016

Arduino Part 2


Outline of process
In the second part of our introduction to Arduino, we learned and accomplished the following:
1) We used a photocell to measure brightness of light shining on it, and to change the blinking rate of LED lights;
2) We used a tactile switch connected to the Arduino to turn an LED on and off
3) We used the "sweep" code from the Arduino library to make the Servo rotate between 0 and 180 degrees.
4) We used the "knob" code from the Arduino library to make the Servo follow the rotation of a potentiometer from 0 to 180 degrees and then from 0 to 60 degrees.

1)  Using a photocell measure brightness 


Notes:
We used the 1 k Ohm resistor because it worked best with the given values quantifying brightness. The resistor helps control the voltage across the photocell and prevents short circuits. We also grounded the resistor which is connected to the entire circuit in series. The coding was straightforward. We used our hands to cover the photocell to different degrees and judge the label of the brightness to the best of our ability. We also used flashlights to see readings of "bright" and "very bright". We noticed a 1 digit boundary between the different labels of brightness is really impossible. The boundaries are all approximations and not objective truth. 


2) Using a photocell to control LED behavior




Notes: Here, we used the delay function in combination with the analogue input of the photocell to vary the rate of blinks of an LED. We set an input of a value of brightness from the photocell to translate into a certain rate of blinking output in the LED. This is shown in both the code and the video above. 
The most challenging part in setting this up was figuring out what about the LED to vary. Since we already had some experience with blink, we incorporated the delay function to give this pattern controlled by the photocell.

3) Using switch to control LED behavior
Note: This was a straight forward process in which we followed the circuit diagram and the code provided to use a button to turn on an LED (when button is pushed). Although this was a basic process that can be accomplished by a simple circuit, I believe it is just an introduction to more complex systems where the use of Arduino would actually be more efficient. 

4) Using "sweep" code to control Servo

Note: We used the above code and arduino.cc's explanation on the function of the different pins on a Servo to figure out what connections to make while making the circuit. Since the code defined 9 as pin attached to the Servo, we connected it to the middle (orange) tip of the Servo. We also connected the red tip to the 5V power supply and the black tip to the ground. 
Once the program was run, the servo started rotating from 0 to 180 degree continuously as expected. 


5) Using "knob" code and a potentiometer to control Servo


We modified the circuit in #4 above by adding a potentiometer to the circuit. We connected the middle pin of the potentiometer to the 5 V outlet, the pin at one end to pin A0, the analog output suggested in the code above, and the other pin on the potentiometer to the ground. We also kept the connection between the 5 V outlet and the Servo.

This allowed us to control the rotation of the Servo with the turn of the potentiometer. I found it interesting that the potetiometer and the servo rotated at the same speed. 


Code and Video for rotation between 0 and 180 degrees



Code and video for rotation between 60 and 180 degrees



With more time, I would be interested in finding out how to manipulate the speed of rotation of the Servo using the Arduino code and/or the potentiometer.

2 comments:

  1. I really liked how you gave an outline of what you were going to discuss in the beginning of the blog post. That, and the combination of the bolded headings, make navigation a lot easier!

    ReplyDelete
  2. Nice commentary in the video! It creates clarity in watching!

    ReplyDelete