Tuesday, November 5, 2013

Reading output from a photocell and Arduino


My Arduino starter kit came with a photocell, aka photoresistor, aka a light dependent resistor (LDR). That made me happy (see Side Story, below). I didn't know if it was working or not.

Photo from Adafruit.com
An LDR works by varying the resistance in a current, depending on the amount of ambient light it detects. As a kid, this was the coolest device for me (again, Side Story). Unfortunately, I never got to playing with an LDR until I got it as part of the Arduino starter kit.

So I first tried inserting it in a basic Arduino-LED circuit. I tried covering the LDR with a finger or black cloth but I couldn't detect any change in the brightness of the LED.

Lady Ada came to the rescue with this Arduino photocell tutorial and I was able to set up the experiment. The tutorial should result to a LED light growing brighter as the room grows darker.

There was one problem though. Although I could get the LED to light up, I could only detect very faint changes in the brightness when I covered the LDR with different materials (including my finger). Turning off the room light didn't help because I couldn't be sure if the variation in brightness was the result of my eyes getting accustomed to the dark.

I wanted to be sure that this was really the LDR working and not some external factor. So I scrutinized the sketch and realized that the code included an output of the reading. Here's a snippet from the sketch, available at Adafruit:
photocellReading = analogRead(photocellPin); //read input from Pin 11 

  Serial.print("Analog reading = ");
  Serial.println(photocellReading); //print the value from Pin 11 
Lady Ada's circuit design involved hooking up the LDR into one of the analog inputs of Arduino (Pin 11). This then allowed Arduino to read and print the analog values as they got affected by the LDR. But where was the output being printed?

Well, the new Arduino IDE (1.0.5) includes a Serial Monitor (Click Tools > Serial Monitor), a window that displays output from the Arduino board. I covered the LDR and started detecting minute decreases in the values. Then I turned off the lights and found a significant drop. Eureka!

I altered the delay value in the sketch so I could record the changes in one screen (from the default "100" to "5000". You could see this in the screenshot below:

Notice the changes in value as the ambient light changes. 569 is when the lights are off.
It turns out the LDR was quite sensitive, detecting and printing out minute changes as I moved around the room. It's just that the circuitry and the LED weren't expressing the analog changes properly. I figured I could calibrate this by changing the other resistors in the circuit, but that's for another experiment.

See it in action in this video:


* * *

Trippy Side Story. As a kid, I was fascinated at how light-controlled switches worked. A friend of mine told me that such a switch was called a "light sensitive device" or LSD for short. I phoned our local electronics supply shop and asked the guy, "Do you guys sell LSD?" The guy at the other end said, "Huh?" and dropped the call. I only figured out his reaction years later, when I realized what LSD really meant. :)

Monday, November 4, 2013

Installed MySQL and PHPMyAdmin

I've been using sqlite3 mostly to brush up on programming and web app development. It's faster and easier to manage and I needed a quick way to run databases as soon as I upgraded to Mavericks. I also successfully reactivated the built-in Apache and PHP in Mavericks.



Eventually I had to install MySQL and phpMyAdmin again, so I did the usual web research on this. I was pleasantly surprised. Installing MySQL and phpMyAdmin have become lots easier than it used to (thanks partly to the now well-documented glitch in the default port/socket that MySQL uses in Mac OS X.)

I was wowed by the user interface (UI) improvements on phpMyAdmin.

I followed the instructions from this blog about installing and configuring Apache, PHP, MySQL, PHPMyAdmin. And also used BrianFLove's blog as a reference.

Reading these blogs made me understand more about the internal config of PHP in php.ini (a file I usually just quickly glossed over because I did not have the leisure of time). I was also happily surprised by the clearer explanatory notes in the php.ini file (it's been a while since I read the details).

Monday, October 28, 2013

A most insensitive and useless message box

Has this happened to you? From Facebook (or any other website), you're trying to jump to another page and this window pops up asking "Are you sure you want to leave this page? Your message is still being sent. Are you sure you want to leave?"



You can't proceed because you probably accidentally pressed the spacebar on the reply box of a friend's status message and now the browser thinks it's an unfinished message. But you can't find where that "unfinished message" is, unless you scroll all the way down and scrutinize each box (and what if it's a blank space or a tiny period?).

Microsoft calls this a modal box. It's a window that won't allow you to do anything else until you select the only options presented to you (in this case, stay or leave -- but have that nagging sensation that you've probably left a reply unsent). Modal boxes are frustrating, actually, though trying to be helpful.

In Gmail, this is a useful message because you are only dealing with one message at a time and if it pops up, you just go back to that message. But in Facebook, you'd have to be really patient, or just click "Leave Page".

Stepping back, you realize that this popup is a useless box. Why? You can't do much to rectify your error. It just reminded you and gave you one more little thing to worry about.

How can we improve this message? Maybe it should have a link that jumps you back to the unfinished message. Then we won't have to gnash our teeth.

Tuesday, October 22, 2013

Why the CATBus schedule handout is confusing

The photo shows a detail of the Red Route for the Clemson bus. I added the numbered blue circles to correspond to my comments.



  1. Centering long lines of text makes it hard to read the information. Since we generally read from left to right, our eyes need a visual cue on where to start from the left. Left-aligned text helps create a visual guide for our eyes. Centering the text removes that guide. Also, using ALL CAPS on the text makes it even harder to read the information. In another route, the ALL CAPS font are squeezed into what looks like Arial Narrow -- an even harder font to read especially in cramped spaces.
  2. The guide uses unnecessary effort to explain the regular and variant schedules, causing a lot of repeating information (eg, observe the repeated Mon-Thu info across Fall, Spring, Summer, and Holiday). This could be simplified by just listing the regular service common to all seasons, and then adding the exceptions in a separate section. 
  3. Long lines of text make it hard to follow the timings at the right side of the table. Using alternating row colors can help us read that information more easily.

Below is a snapshot of one page of the whole schedule (taken from the CATBus website). Notice anything?




  1. Too much real estate in the handout is devoted to a map that's not very informative. The most useful sections -- the schedules -- are relegated to about 20% of the paper. 
  2. The dimensions of the guide are not very portable: 28.5" x 22" (72.39 x 55.8 cm). It's almost like a tourist map with confusing folds. The schedules themselves could be printed on a strip of paper that could be folded and fit in a purse or wallet. 
Like I said in a previous post, I appreciate the CATBus service. It's free! But lots more could be done to help visitors and students to use the service.

* * *
See also: The (absence of) bus stops

The (absence of) bus stops

I'm thankful for the CATBus, because it's a free bus service (CAT stands for Clemson Area Transit). However, there is room for improvement.



The photo above shows the Hendrix bus stop at Clemson University. It was taken during a very hot summer day 40º C (104º F). Buses stop at 30 minute intervals on weekdays and every hour on weekends. Since the bus was late, people were baking under the sun. Note also the number of people waiting versus the only available bench. Most of the stops have no shade (imagine if it rains).

Within the university, bus stops are marked with small, hardly noticeable signs. Outside of the university, the signs are less prominent and sometimes absent.

To visitors, the bus stops seem random. And on occasion, the stops are arbitrary. At Greenville, I missed the Greenlink bus (a shuttle that links to the CAT Bus), because I waited at a different spot. It turned out the afternoon bus driver stopped at a different spot from where the morning driver stopped. I asked people at Clemson in Greenville, but nobody knew the right bus stop. There were no signs either.

I called the Greenville station and their advise was to wait where I was dropped off -- which is what I did and why I missed the afternoon bus in the first place. So the morning driver stopped at a different location than the afternoon driver, and no one knew, not even the folks at the terminal. So I had to wait 2 hours for the hourly shuttle. The Greenlink bus is not a free service.

The CATBus offers a free handout of the schedules and the stops -- but the publication and information it contains are not designed to help people unfamiliar with the territory. I am trying to come up with a redesign of the handout, but that's for another day.

* * *
See also: Why the CATBus schedule handout is confusing

Saturday, October 19, 2013

How not to design toilets

This photo, which I took from a mall in Metro Manila, says it all. As Stan Lee would have said, "'Nuff said."

Tuesday, August 6, 2013

The Origin of Jejenese (or, Jejenomics)

Image from: journalism.co.uk

Just a thought.

The standard mobile phone keyboard contains the following character clusters:

A B C
D E F
G H I 
J K L
M N O
P Q R S 
T U V
W X Y Z 

Reading from left to right, we assign a value of 1 on the leftmost character and increment it by 1 as we move to the right. We do this for each row and return to 1 when we start a new row.

Thus:

A = 1
B = 2
C = 3

D = 1
E = 2
F = 3
...

W = 1
X = 2
Y = 3
Z = 4


With me so far? 

Good. Next.

Lets call the numbers "letter weights". A letter weight is the number of taps on a key you need to display a letter. Example: to type a lowercase 'c', we need to tap the 2 key three times. 

To display a number 5 in a Nokia phone, you need to press the 5 key for about half a second. Knowing that, we assign a number weight = 1.5 for numbers.

Now, a "word weight" is the total of the letter weights in a word.

Example: 

"dito" has a word weight of 9. That is (d=1) + (i=4) + (t=1) + (o=3)

Compare this to "d2" with a word weight of 2.5. (d=1) + (2=1.5)

The average texter will have their autospell feature turned off. In the absence of autospell, the goal of a frequent texter (eg, jejemon) is to conserve key-taps. This means using characters that have the lowest weights possible. 

Let's test this theory on Jejenese words and compare them with normal spelling.

"jejeje": word weight = 9
"hehehe": word weight = 12

"eow p0h" is the Jejenese equivalent to the geek greeting "hello, world" (note that that's a zero between 'p' and 'h'). It has many variants in jejenese, but this most basic form represents a more jejenomic way of spelling an otherwise weighty "hello po". I'll leave it to you to do the math to compare its word weight with "hello po".

Why is the phrase terminated with an 'h' if the Jejenese really wanted to conserve? I have to theories on this anomaly.

One, the phrase used to be spelled "eow p0" but p0 might be read as p-zero, so the 'h' was added to emphasize that it's to be read as "po".

Two, after a while, Jejenese needed the equivalent of signature flourishes (or poetic license, if you may), so the 'h' was added as an embellishment.


Anyways, this is what happens to a bored and stressed out Silicon Carne.  :)

* * *
This post was quoted in a thesis written by Joseph Cataan at the UP College of Mass Communication. Link: Read at Scribd.

What to do when you've got a virtual scrum team

Scrum and Agile are suddenly popular in Asia, and because a lot of companies take on outsourced projects, they usually have virtual teams, w...