Sensor Journalism: first day at The Quantified Self About Town
Arduino came into my life in a small black box via shipped mail. My roommates exclaimed in admiration as I felt the fear growing into my belly. It was the same sensation I had back in 2003 when they put a Betacam camera in my shoulder, or they sat me in a dark editing room – for the first time.
I wanted to be writer. A journalist. And I had thought that camera, and those buttons had nothing to do with me.
Check the collective blog I created for all my class so we can easily follow each other http://ccurly.org/
There I was 12 years later, coming out of the elevator at Tisch NYU with my arduino-box in my purse, trying to walk smoothly in between the lab atmosphere of the 4th Floor. As if I, from journalism school, knew the building.
This new elective I’m taking is called The Quantified Self About Town. All of my classmates at Studio 20 NYU are taking Data Journalism, but I decided to do something different and I registered in Arlene Ducao‘s course. She is from the MIT Media Lab and a research fellow at at the MIT International Development Initiative. We are about 20 students: half from Tisch, half from CUSP (Center for Urban Science and Progress) and… me. I think I’m the only one from Arthur L. Carter Journalism Institute NYU.
First Class
Tuesday February 03 was an introductory class and I noticed how some of my classmates took out their “black boxes” from their bags with my same lack of confidence.
The class last 3 hours. The first part of the class will be a lecture–discussion. The second half will be a hands-on-lab.
Today in this post I will talk about the lab part.
My First Day with Arduino
Sitting next to me I had Tanya Campbell, a student at Tisch who had a tool-box 3 times bigger than mine. She said she liked doing workshops with kids and my neighbor Kania Azrina (from CUSP) and I knew immediately that our first lab session was saved.
We started imitating Tanya and following her instructions.
She introduced us to The Elements Of Our Box:
Arduino
Breadboard (such a funny name!!)
A light sensor (or photo-resistor). That’s the sensor we used in our first practice!
Resistors (apparently, if we don’t use one of these, we could “burn” something).
THE EXPERIMENT
Achieve that the red LED goes on when the light sensor “feels” there is less light in the room.
How do we do that?
We plug the wires in the breadboard. We connect the breadboard to the Arduino. We give instructions to Arduino via USB cable from our Arduino software in our laptop, then the Arduino gives the instructions to the breadboard again.
It’s kind of easy.
Kind of easy, in the sense that if you follow all the instructions as if you are cooking a recipe, it should work.
My friend Nori Yoshida, a visiting journalist-student at Studio 20, explained to me later in a bar the basis of how I should think now: input and output.
INPUT AND OUTPUT
“Coding Arduino is simpler than HTML or CSS,” he said. “We have to think in terms of Input and Output”.
And actually that’s what we do when we send code to the Arduino. We say when Input “says” A, output does X.
So when (input), the light sensor, receives light, the LED (output) turns off.
So I tried the thing at home.
(Yes, with the admiration of my roommates).
I copied all Tanya had told me.
And
I
produced
the opposite of what I was meant to do.
I was happy because at least I had achieved communication between the LED and the sensor. But take a look at the video:
[youtube https://www.youtube.com/watch?v=52SBDUd3OBg&w=560&h=315]
The LED is ON all the time and it turns OFF when there is no light. WRONG!
I took a look at the code. And without really understanding what was happening, I googled another code.
I copied and pasted. ….and voilá! IT WORKED!!
[youtube https://www.youtube.com/watch?v=xD-SZoDw7-8&w=560&h=315]
Here you have the 2 codes I used. Find the difference.
Nori says maybe it is because in the first code the LED is a “const” (constant).
Proud anyway of my first successful-alone-encounter with Arduino. I kept silent on the sofa thinking of Matt’s Wait quote: “Data journalism, meet sensor journalism. You two should talk.”
Well, there we where.
And the Arduino smiled at the camera.
—————————————————————————————————————————
CODE THAT MADE THE LIGHT ALL THE TIME ON
const int ledPin = 7; // pin that the LED is attached to
int photocell=A0;
int analogValue = 0; // value read from the pot
int brightness = 0; // PWM pin that the LED is on.
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(photocell,INPUT);
}
void loop() {
analogValue = analogRead(A0); // read the pot value
brightness = analogValue /4; //divide by 4 to fit in a byte
analogWrite(ledPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); // print the brightness value back to the serial monitor
}
CODE THAT WORKED (so light if OFF until there is less light)
int photocellPin = A0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int LEDpin = 7; // connect Red LED to pin 11 (PWM pin)
int LEDbrightness; //
void setup(void) {
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print(“Analog reading = “);
Serial.println(photocellReading); // the raw analog reading
// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0
photocellReading = 1023 – photocellReading;
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
analogWrite(LEDpin, LEDbrightness);
delay(100);
}