Advertisement
MUstar

IoT 아두이노 0616 - CDS

Jun 15th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. int pin_VIB = 22; ////Vibrator Set
  3. int pin_CDS = A0;
  4. int pin_LCD_DATA[8] = {A8,A9,A10,A11,A12,A13,A14,A15};
  5. int pin_LCD_CTRL[3] = {A5,A6,A7};
  6. LiquidCrystal lcd(A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15);
  7.  
  8.  
  9. void setup() {
  10.   pinMode(pin_CDS, INPUT);
  11.   pinMode(pin_VIB, OUTPUT); //Vibrator Set
  12.   lcd.begin(16,2);
  13.   lcd.print("ADC Data :");
  14.   lcd.setCursor(0, 1);
  15.   lcd.print("Volt :      [V]");
  16.  
  17. }
  18.  
  19. void loop() {
  20.   uint16_t da = analogRead(pin_CDS);
  21.   float voltage = (float)da * 5 /1023;
  22.   lcd.setCursor(11, 0);
  23.   if(da<1000){lcd.print(" ");}
  24.   if(da<100){lcd.print(" ");}
  25.   if(da<10){lcd.print(" ");}
  26.   lcd.print(da);
  27.   lcd.setCursor(8, 1);
  28.   lcd.print(voltage);
  29. //v Vibrator Set
  30.   if(voltage <= 2)
  31.   {
  32.     digitalWrite(pin_VIB,HIGH);
  33.     delay(500);
  34.   }
  35.   else
  36.   {
  37.   digitalWrite(pin_VIB,LOW);
  38.   delay(500);
  39.   }
  40. //^
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement