Day 1
Anyhow, we are now learning Arduino, which would help us understand the control and response process. It also exposes us to computer programming.
Our very first task was to understand the program that makes the LED light blink. We connected out Arduino Uno to the computer, and the LED light on the board that is connected to port 13 started blinking on an 1-second interval. To further our understanding, we deleted the delay in the code, later finding out that to human eyes, the LED would look like it remains on the whole time, even though it was in fact blinking at an extremely high speed that is undetectable.We also altered delay into a few different values, to see how the timing changes.
![]() |
| Code for Blink |
As we understood the use of delay and the general idea of setting up Arduino programs, my partner, Meredith, and I started working on a program that controls four LED's with delay. Here is our COOL pattern. The second part looks like a little bug made of two lights is running through the row of LED's!
void setup () {
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(4, OUTPUT);
}
void loop () {
digitalWrite(12, HIGH);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(7, HIGH);
digitalWrite(12, LOW);
delay(500);
digitalWrite(4, HIGH);
digitalWrite(8, LOW);
delay(500);
digitalWrite(7, LOW);
delay(500);
digitalWrite(4, LOW);
delay(500);
}
After understanding the delay function, we then moved onto a different way to achieve blinking without delay but with interval. It is necessary to do so, because sometimes the program must command other parts connected to Arduino, but having delay in the code will delay/affect other commands made to other parts.
The interval function is much harder to understand, since it incorporates variables that the computer would compute, as opposed to constants that we just plug in like in delay. It basically allows the program to check the status of the lights after each interval, and update the status of parts connected and other variables based on the code.
![]() |
| Blink without Delay |
We wanted to do a similar pattern we did before, which required different patterns. However, we could not find a way to make the pattern go back to the loop. We tried
if(currentMillis > 3000)
currentMillis = 0
and
if(currentMillis = 3000)
currentMillis = 0
However, it turned out that the first one makes each milli-second after 3000 become the 0th milli-second, and the latter one makes only the 3000th milli-second become the 0th milli-second. Neither code resets the timer. We may be using the wrong code to say what we want.
We ended up with only one pattern, alternating the lights on and off.
Day 2
As I said before, the main point of studying Arduino is to understand response and control. In the previous class we were able to control the LED's, but we did not get to the response stage. In our second day with Arduino, we worked with the servo motor, the potentiometer and the photocell.We first started with the servo motor. This is much more precise than PicoCricket, which we used for our Lego racer. We can control the servo by commanding it to move to certain positions. We may make it stop or move continuously. The example "Sweep" familiarizes us with controlling the motor. We changed the position and the rate at which the motor moves to understand the language better.
![]() |
| Modified "Sweep" |
The servo is in fact used to demonstrate as an output. We then started attaching the potentiometer on the proto-board and the potentiometer would be our first instrument to receive signals and ask the servo to respond. The first example was "Knob". The program uses the "map()" function to correspond the potentiometer's setting with the position of the servo. We then combined this with the flashing LED, which also became part of the response.
The second input control device we used was the Photocell. It detects the brightness of light and the Arduino program and read it and also produce a result as commanded by the program. Here, to detect the data, we used the following code.
Note that in this case, the photocell would check the brightness every second.
To use the reading to control the servo and the LED, we used similar functions as we did in "Blink" and "Knob". Here is the code.
When we were running the initial program to look at the reading, we noticed that the highest value we got by shining a phone flashlight to the photocell was in the 900's. We thus set the value of the photocell as 0-1000. We also used a "for()" statement here to let the LED light blinks three times before the next time the photocell detects again. The LED blinks faster when the light is brighter and slower when the light it dimmer.








I couldn't view your first video, where you discuss the alternating on and off pattern. I would really love to see the pattern that you started with.
ReplyDeleteI just checked it and it was working! Maybe reload? Sorry for the inconvenience and thanks for your comment. :)
Delete