Arduino Serial Communication
Computers can exchange bits of information serially (one after another, in sequence) or in parallel (several at the same time). In applications where it is necessary to have one computer talk to another, the most commonly used communication method is serial.
So it is no surprise that serial communication is the method used to send data between the Arduino board and a computer (or other device). Information is sent to and from the computer and the Arduino by setting a pin high or low. One side sets the pin and the other reads it.
The Arduino Duemilanove has one serial port that communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. When you use the IDE to Upload your sketches to the Arduino, the bits are transmitted one at a time through the USB cable to the Arduino. The serial connection can also be used in our sketches to send data to the computer and to receive data from the computer via the serial monitor available on the IDE. This proves very useful for debugging your projects, as we will explore in the upcoming posts.
Continue Reading »
Arduino RGB LED Control for the Spinning Night Light
When looking at the parts list for the Arduino RGB LED spinning night light you must have noticed that current limiting resistors of different values were used for the Red and the Green/Blue pins of the RGB LED. That is due to them having different forward voltage ratings. You can find complete specs for the LED in the datasheet (when buying an electronic component you will have the option to download its datasheet, or the relevant information will be provided by the vendor).
We use Ohm’s Law to calculate current limiting resistor values:
Forward voltage ratings:
RED: 2.1V
GREEN: 3.3V
BLUE: 3.3V
Current:
I = 20mA
Supply voltage:
V = 5V
Ohm’s Law:
I = V/R => R = V/I
So for Red:
(5 – 2.1)/0.02 => R = 145 Ohm
For Green/Blue:
(5 – 3.3)/0.02 => R = 85 Ohm
As for the Arduino sketch, I chose to have the lamp fade between two colors, aqua (#00FFFF) and magenta (#FF00FF). For that I kept the Blue value at 255 and varied the Green and Red values between 0-255 to achieve the desired colors, as shown in the diagram:
(You can pick your favorite colors, cycle through the entire spectrum, or go psychedelic and show random colors with random delays)
// fade from aqua to magenta
for (int i = 0; i < 256; i++) {
analogWrite(RED, i);
analogWrite(GREEN, 255-i);
analogWrite(BLUE, 255);
delay(50);
}
// fade from magenta to aqua
for (int i = 0; i < 256; i++) {
analogWrite(RED, 255-i);
analogWrite(GREEN, i);
analogWrite(BLUE, 255);
delay(50);
}
Arduino RGB LED Spinning Night Light: Assembly
Solder wires to motor terminals and cover with heat-shrink tubing
- Using a knife or sharp scissors, puncture a small hole (to fit the motor shaft snugly) on the center of the jar lid
- Solder motor shaft to jar lid (if necessary use hot gun or super glue, as some surfaces won’t “catch” the solder easily)
- Solder the RGB LED leads to long wires and cover the connections with heat-shrink tubing
- Build the circuit on the mini breadboard using the schematic as your guide
- Prepare the paper diffuser (use a hole puncher and punch a few holes to allow some light to shine through) and tape it around the jar lid using mounting tape
Arduino RGB LED Spinning Night Light
This month’s project uses the Arduino to control a motor and an RGB LED to create an aquarium style spinning night light.
The initial idea was to recycle empty toilet paper tubes to serve as the lampshade, but it turns out the project looks much more attractive and colorful using white paper. (I haven’t given up on the idea of finding a use for the empty tubes, though. Suggestions are welcome.)
A simple DC motor is used to spin the lamp structure, and a jar lid serves as the base. There is (a lot of) room for improvement in the design of the lamp, but I’m a computer scientist and wanna-be crafter at best.
Continue Reading »
Arduino 2-Digit 7-Segment Display with Buttons: Sketch
As you could see from last week’s full Arduino sketch listing, the source code for the 2-digit 7-segment display project using buttons is strikingly similar to the one without the buttons; praise for ‘copy and paste‘! (It is worth noting, though, that ‘copy and paste‘ can be responsible for a higher percentage of bugs than I’d care to admit).
There are just a couple of snippets that I would like to comment on:
The first part of the loop() function checks whether either button has been pressed and increments the value of each digit.
Continue Reading »
Arduino 2-Digit 7-Segment Display with Buttons
This week we modify the original circuit and sketch to include two buttons, one to control each digit of the display.
Here’s what the setup looks like:
And here’s the complete sketch:
Continue Reading »
Arduino 2-Digit 7-Segment Display Counter: Sketch
This is part 3 in the project to control a 2-digit 7-segment display using an Arduino. Here is the first post on this 2-digit 7-segment display project.
So now on the the meatier sections of the sketch for this project:
Common anode displays are not immediately obvious as a segment is lit when the corresponding pin is made LOW. You might be surprised, though, that common anode displays are most often used because they can be used with 74xx series logic data-selector chips and PNP bipolar transistors.
Continue Reading »









