SHED-Article2SOFTWARE - 2-AnalogValues
Jump to navigation
Jump to search
SHED-Article2SOFTWARE - 2-AnalogValues
(tested TK)
This is similar to the sketch "AnalogValue" except two different analog sensors are being used. One is a Potentiometer and the other is a Photoresistor. The sketch displays the values read. The Photoresistor sensor will read higher values for more light intensity. YOU can compare them, but in an automatic system the software would compare them and make some decision.
CONNECTIONS:
- Potentiometer from +5 to Ground, center to pin A0
- Photoresistor from +5V to pin A1, 10K from A1 to Gnd.
(Copy the text in the box below and Paste it into a blank Arduino IDE window)
/* SHED Magazine Arduino Sketch: 2 Analog Values - Reads voltage on Analog Pin 0 and displays value - Reads voltage on Analog Pin 1 and displays value - SEE the comments after "//" on each line below - CONNECTIONS: - Potentiometer from +5 to Ground, center to pin A0 - Photoresistor from +5V to pin A1, 10K from A1 to Gnd. - V1.01 09/11/12 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ //none /*-----( Declare Constants and Pin Numbers )-----*/ #define potPin A0 // In separate group of pins #define photoPin A1 // In separate group of pins #define ledPin 13 // The onboard LED /*-----( Declare objects )-----*/ //none /*-----( Declare Variables )-----*/ int potValue; // Hold the values read in int photoValue; void setup() /****** SETUP: RUNS ONCE ******/ { pinMode(ledPin, OUTPUT); Serial.begin(9600); //Start sending to "Serial Monitor" Serial.println("SHED Magazine: Show Analog Value."); }//--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { potValue = analogRead(potPin); //Read value photoValue = analogRead(photoPin); //Read value Serial.print("POT VALUE = "); Serial.print(potValue,DEC); // Print value Serial.print(" PHOTORESISTOR VALUE = "); Serial.println(photoValue,DEC); // Print value delay(1000); // Wait 1 second }//--(end main loop )--- /*-----( Declare User-written Functions )-----*/ //none //*********( THE END )***********