Thursday, March 3, 2016

Arduino Introduction Part 2



Day 11 (3/1/16)

Today we continued to learn how to use Arduinos. We worked on a few more programming challenges that are shown in detail below:

Challenge #1: "Use the photocell to change something about the LED"

For our first challenge, we decided to change the speed of blinking based on the photocell. We set it up so that the Arduino would receive a certain numerical representation of the brightness of light and depending on the value, the LED would flash slower, faster, turn on completely, or turn off completely.

For our code, we took ideas from our previous programming challenges and combined those ideas. Here is what our code looked like:



Here is what our circuit looked like with the photocell and the LED set up:


Here is a video showing the change of flashing depending on the incident light:



Challenge #2: "Use the tiny tactile switch to turn the LED on and off"

Here is what the code looked like to control the LED light with a switch:


Here is what our resulting Arduino and circuit board looked like. There were simple connections between the switch, the LED, and the rest of the circuit:



Here is a video of the resulting function of the button:



Challenge #3: "Use sweep and knob to control your servo"

Sweep:

First I downloaded the code for the sweep function and figured out that the Servo needed to be connected to pin 9. The code told the servo to sweep between 0 and 180 degrees. Here is what the code looked like:



A tricky thing with the circuit is that the yellow wire on the servo needs to be connected to the appropriate pin number, the red wire on the servo needs to be connected to the power source, and the black wire on the servo needs to connect to the ground. Here is what the circuit looked like:



If we wanted to change the range of motion from 60 to 120 degrees, we would have to change line 15, 22 and 27 where it says 0 to 60. We would change lines 22 and 27 where it says 180 to 120. Here is a video of the servo sweeping out the angles:



Knob

The knob function uses the potentiometer and the servo to adjust the angle of the servo based on the position of the potentiometer. The initial code is set up so that the servo sweeps between 0 and 180 degrees:


To change the range of angles that the servo sweeps, you have to change line 23 from (val, 0, 1023, 0, 180) to (val, 0, 1023, 60, 120) and then the servo will move from 60 degrees to 120.

Here is a picture of the resulting circuit. Again, here it was important to make sure all of the connections were being made in the correct place:


Finally, here is a video of the potentiometer controlling the angle of the servo:





1 comment: