This process is made really simple using the Teleduino sketch for your ethernet enabled Arduino. Haven't heard of Teleduino? That's cool, you may want to take a look at Arduino Control via a Web Service with Teleduino to get yourself started.
This tutorial will guide you through the process of attaching a LDR (Light Dependant Resistor) to your Arduino, and provide some example Teleduino API calls to:
- Fetch the value of an analog input
- Fetch all inputs with a single API call
If you get stuck on any of the steps, or if you feel that there is a step that could be explained better, please leave a comment so that we can improve things.
Let's get cracking!
Step 1: Parts Needed and Circuit Diagram
The need the following parts to complete this tutorial:
- Breadboard (optional, but makes prototyping much easier)
- 10K Resistor
- LDR (Light Dependant Resistor)
- Some hookup wire
Take a peak at the attached circuit diagram. It shows how the components need to be connected. Pretty simple!
Let's get it all together!
Step 2: Put Circuit Together
Add the components to your breadboard as shown. You may want to reference the circuit diagram from Step 1 to double check.
Add the Hookup Wire. There are three wires that need to be connected to your Arduino (5V, GND and Analog Pin 0).
Shows the correct way to connect the circuit to your Arduino board.
Time to get some readings!
Step 3: Fetch Values via the Teleduino API
Analog Pin Addressing via Teleduino
The analog pins on the Arduino can also be used as digital pins. To keep things simple when using the Teleduino, the analog pin numbering is different to the native Arduino.
The following shows the pin value to be used for addressing the analog pins:
A0 = 14
A1 = 15
A2 = 16
A3 = 17
A4 = 18
A5 = 19
A6* = 20
A7* = 21
* Some alternate brand Arduino boards support two extra analog pins.
Fetch the value of Analog Pin 0, Teleduino pin 14 (pin=14):
Fetch all input values in a single API call:
What to Expect
What you should find is that the darker the room, the lower the value. If it's pitch black then you should expect approximately 0, if direct sunlight then a value of approximately 1023. Perform some tests to see what values you can expect for your particular environment.