SHARE
TWEET

Tinylab analog sensor test

a guest Mar 6th, 2017 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define pot_pin A0
  2. #define ldr_pin A2
  3. #define lm35_pin A3
  4.  
  5. void setup()
  6. {
  7.   Serial.begin(9600);
  8.   while (! Serial);
  9.   Serial.println("Analog input example");
  10.   delay(500);
  11. }
  12.  
  13. void loop()
  14. {
  15.   int pot_val = analogRead(pot_pin);
  16.   int ldr_val = ((2500.0 / (analogRead(ldr_pin) * (5.0 / 1024.0))) - 500) / 10.0;  
  17.   int lm35_val = (5.0 * analogRead(lm35_pin) * 100.0) / 1024;
  18.   Serial.print("Potentiometer value: ");
  19.   Serial.println(pot_val);
  20.   Serial.print("LDR value: ");
  21.   Serial.println(ldr_val);
  22.   Serial.print("Temperature: ");
  23.   Serial.println(lm35_val);
  24.   delay(100);
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top