Photoresistor
Materials:
1. Arduino board
2. Breadboard
3. LED
4. Photoresistor
5. Resistor
6. Jumperwires
I followed the schematic below. On my first trial, it didn't work because the jumper wires weren't place correctly. I'd to borrow Mr. Robert's set up and reset my own breadboard. I think my breadboard doesn't look exactly like the diagram and I'm not sure if the original schematic has a complete circuit or not. However, Mr. Robert's setup worked and mine does too (because I copied his exact setup). Below is a short footage of me experimenting with the photoresistor.
/* turns on and off a light emitting diode(LED) depending on ambient light (using a photocell).
Project tutorial: http://osoyoo.com/?p=123
*/
int photocellPin = 2; // select the input pin for the photocell
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(photocellPin, INPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(photocellPin); // read the value from the sensor
if(val<=512){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}
http://www.instructables.com/id/Artemis-Apollo-Dancing-with-Arduino-and-light-d/
http://www.instructables.com/id/Photocell-Piano/
http://www.instructables.com/id/Piano-Stairs-with-Arduino-and-Raspberry-Pi/
Tilt Resistor
The materials are still the same as the previous one except we had to use more wires, and a tilt resistor instead of a photoresistor. I followed this tutorial.
I also recorded a short footage for this experiment. (Please ignore the background audio!)
I'd to let Ernst, one of my awesome classmate, help figure out what was wrong with my initial set up. I found out that changing the type of resistor greatly affect the setup, and so instead of using 1k resistor, I used ___ resistor (the blue one). It turns out that the LED shines brighter and the circuit works!
When it comes to practical uses, I thought of video game controller and other game devices that when you tilt the device, it gives different set of instructions and act accordingly. There are some cool projects below (link attached)- I liked the jacket and the LED box projects.
/* tilt sensor test project
* copyright Yi Lun Yu
* project tutorial http://osoyoo.com/?p=231
*/
int led=2;
int tilt_port=0;
void setup()
{
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int tilt_value;
while(1)
{
tilt_value=analogRead(tilt_port);
Serial.println(tilt_value);
if(tilt_value>500)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
}
}