arduino:arduino_crash_course:analog_input
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
arduino:arduino_crash_course:analog_input [2017/12/06 01:17] – [Night light] mithat | arduino:arduino_crash_course:analog_input [2017/12/06 01:27] (current) – [Night light] mithat | ||
---|---|---|---|
Line 16: | Line 16: | ||
FIXME We need a circuit diagram | FIXME We need a circuit diagram | ||
+ | |||
+ | In the following example, we output the light-level reading to serial communication. This should help you get a feel for the range of numbers that result from for your particular unit. | ||
+ | |||
+ | <file c cds2serial.ino> | ||
+ | /* | ||
+ | CdS to Serial | ||
+ | | ||
+ | */ | ||
+ | |||
+ | const int inputPin = A0; // use analog 0 (A0) as input pin | ||
+ | const int ledPin = 13; // connect the LED to pin 13 | ||
+ | |||
+ | int lightLevel = 0; // used to store the input value | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(9600); | ||
+ | pinMode(ledPin, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | lightLevel = analogRead(inputPin); | ||
+ | Serial.println(lightLevel); | ||
+ | delay(500); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And here is the working nightlight. You may have to adjust '' | ||
<file c NightLight.ino> | <file c NightLight.ino> |
arduino/arduino_crash_course/analog_input.txt · Last modified: 2017/12/06 01:27 by mithat