※ Control LCD with illuminance sencor
Circuit
Source Code
LiquidCrystal Library. This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs.
include LiquidCrystal Library.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,2,3,4,5);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.print("More Fun Life");
Serial.print("Test");
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,1);
lcd.print(analogRead(A0));
delay(200);
}
==> Display Illuminance sensor value on LCD
※ Control LCD using ultrasonic sencor
Circuit
Source Code
#include <LiquidCrystal.h>
#define TRIG 8
#define ECHO 9
LiquidCrystal lcd(12,11,2,3,4,5);
void setup() {
// put your setup code here, to run once:
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
lcd.begin(16,2);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long distance = pulseIn(ECHO, HIGH)/58.2;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(distance);
lcd.print(" cm");
delay(200);
}
refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=coFwvg_O1q4&index=8&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w
7 Segment Anode
7 Segment Cathode
※ 7 Segment
Circuit
Source Code
// Common Anode version
byte digits[10][7] =
{
{0,0,0,0,0,0,1 }, // display '0'
{1,0,0,1,1,1,1 }, // display '1'
{0,0,1,0,0,1,0 }, // display '2'
{0,0,0,0,1,1,0 }, // display '3'
{1,0,0,1,1,0,0 }, // display '4'
{0,1,0,0,1,0,0 }, // display '5'
{0,1,0,0,0,0,0 }, // display '6'
{0,0,0,1,1,1,1 }, // display '7'
{0,0,0,0,0,0,0 }, // display '8'
{0,0,0,1,1,0,0 } // display '9'
};
// Common Cathode version
/*
byte digits[10][7] = {
{1,1,1,1,1,1,0 }, // display '0'
{0,1,1,0,0,0,0 }, // display '1'
{1,1,0,1,1,0,1 }, // display '2'
{1,1,1,1,0,0,1 }, // display '3'
{0,1,1,0,0,1,1 }, // display '4'
{1,0,1,1,0,1,1 }, // display '5'
{1,0,1,1,1,1,1 }, // display '6'
{1,1,1,0,0,0,0 }, // display '7'
{1,1,1,1,1,1,1 }, // display '8'
{1,1,1,0,0,1,1 } // display '9'
};
*/
void setup() {
// put your setup code here, to run once:
for(int i=2;i<10;i++) {
pinMode(i,OUTPUT);
}
digitalWrite(9,HIGH); // turn off DP LED
}
void loop() {
// put your main code here, to run repeatedly:
for(int i=0; i<10;i++) {
delay(1000);
displayDigit(i);
}
}
void displayDigit(int num) {
int pin = 2;
for(int i=0; i<7; i++) {
digitalWrite(pin+i, digits[num][i]);
}
}
※ 7 Segment with buttons
Circuit
Source Code
#define PLUS 11
#define MINUS 12
int digit = 0;
// Common Anode version
byte digits[10][7] =
{
{0,0,0,0,0,0,1 }, // display '0'
{1,0,0,1,1,1,1 }, // display '1'
{0,0,1,0,0,1,0 }, // display '2'
{0,0,0,0,1,1,0 }, // display '3'
{1,0,0,1,1,0,0 }, // display '4'
{0,1,0,0,1,0,0 }, // display '5'
{0,1,0,0,0,0,0 }, // display '6'
{0,0,0,1,1,1,1 }, // display '7'
{0,0,0,0,0,0,0 }, // display '8'
{0,0,0,1,1,0,0 } // display '9'
};
void setup() {
// put your setup code here, to run once:
pinMode(PLUS,INPUT);
pinMode(MINUS, INPUT);
for(int i=2;i<10;i++) {
pinMode(i,OUTPUT);
}
digitalWrite(9,HIGH); // turn off DP LED
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(PLUS) == HIGH)
{
++digit;
if(digit > 9)
{
digit=0;
}
}
if(digitalRead(NINUS) == HIGH)
{
--digit;
if(digit < 0)
{
digit=9;
}
}
displayDigit(digit);
delay(100);
}
void displayDigit(int num) {
int pin = 2;
for(int i=0; i<7; i++) {
digitalWrite(pin+i, digits[num][i]);
}
}
refer to youtube tutorial (in Korean) : https://www.youtube.com/watch?v=SRtYpBnmPfA&index=9&list=PL0Vl139pNHbe-JlsydLg3NFRk6nC_cC7w
'IoT > Arduino' 카테고리의 다른 글
[Arduino] Motion Sensor and Water Level Sensor (0) | 2017.01.17 |
---|---|
[Arduino] Joystick, LED Dot Matrix and ADXL335 Module (0) | 2017.01.17 |
[Arduino] Ultrasonic, Keypad and Temperature and Humidity Sensor (0) | 2017.01.15 |
[Arduino] 7 Segment, Servo, LCD and Thermometer (0) | 2017.01.14 |
[Arduino] Using 74HC595 8-bit serial-in/serial or parallel-out shift register (0) | 2017.01.12 |
[Arduino] Library and RGB LED (0) | 2017.01.11 |
[Arduino] Servo Motor (0) | 2017.01.10 |
[Arduino] Illuminance (Photocell) and Ultrasonic Sensor (0) | 2017.01.09 |
[Arduino] Tri LED and Buzzer (0) | 2017.01.09 |
[Arduino] Arduino Basic and control button and LEDs (0) | 2017.01.08 |