Resistance is Futile

Last week in class we started coding our Arduino UNO boards. We began with uploading the “Blink” sketch and then added a photoresistor.

We had learned previously about Ohm’s Law in which:

V = (i)(R) 
where V is voltage, i is current/amperage, and R is resistance (Ohms)

We used water through a pipe as a metaphor to determine how much is flowing out? [amperage].

Using a Data Sheet or description helps determine the capacity and needs of components. These specs show that a 10K resistor is necessary for the photocell. This chart is very helpful.

Resistors are color coded: each band symbolizes a number and the order determines the decimal place.
Resistors are color coded: each band symbolizes a number and the order determines the decimal place.

 

After connecting all the important doodads, we uploaded “Blink” and modified it with a logic if() statement. It worked great, having the LED off when it is light outside (or rather, the photocell detects light) and on when I covered the resistor (senses darkness). It’s pretty neat that it changes with physical/human interaction rather than just the coding.

Here is my sketch:
/
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
  _______
  
  Class build up: making a night-light (detects light/lack of light and turns on LED to compensate)
 
/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
int fotovalue = analogRead(A0); //assigns name to photoresistor and identifies analog pin
Serial.println(fotovalue);
if(fotovalue > 500) {
digitalWrite(led, LOW);
}  else{
digitalWrite(led, HIGH);
}
}

The threshold that worked best was this code–I didn’t have to change anything, it went from the high 800s to a low of 0 at one point.

And here it is live and in person(ish): ARDUINO BLAM!!

I think a good application for something like this would be to dim appliance lights at nighttime. For instance, my printer is in my bedroom and it has this super annoying bright blue LED button. Turning the whole thing off would make the light disappear, but sometimes I forget. It would be great if it self-dimmed when the room is dark.