Proogramming with arduino
Fi1h Program
LCD Monitor
Monitor LCD 16(columns)x2(rows)
• Library: LiquidCrystal.h • You can communicate with 4 bit (4 lines) or 8 bit (8 lines) • Total lines: 4 or 8 + 2
controller lines: • Register Select (RS) • Enable (E) • + 1 opFonal line Read/
write (RW)
hIps://www.sparkfun.com/datasheets/LCD/ADM1602K-‐NSW-‐FBS-‐3.3v.pdf
From the datasheet 16 pins
Pin descripAon
16 Digital Pins
Pin FuncAon • Pin 1: Vss – connected to the GND • Pin 2: VDD – connected to +5V • Pin 3: V0 – control of the leIers contrast. It is general connected to a potenFometer
(or trimmer). (in this way it is possible apply a changeable voltage between 0V and 5V . Changing the voltage the contrast changes as well. Pin 4: RS signal– to select the register where register what appear on the LCD
• Pin 5: Read/Write signal – to select funcFonal mode: RW – connected to GND • Pin 6: Enable (E) signal – to enable wriFng to the registers • From Pin 7 to Pin 14: lines used to communicate with the registers:
• HIGH (H) value indicates a wriIen value (WRITE) of the bit on the display register
• LOW (L) indicates a read value (READ) from the register • Pin 15: A (Anode) – Pin to which a posiFve voltage is applied (+5V) to have the
backlight of the display. • Pin 16: K (Cathode) – Pin to which a GND is applied to have the backlight of the
display.
I2C CommunicaAon
The I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL) that the Arduino or Genuino Master board pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock line changes from low to high (known as the rising edge of the clock pulse), a single bit of informaFon -‐ that will form in sequence the address of a specific device and a a command or data -‐ is transferred from the board to the I2C device over the SDA line. When this informaFon is sent -‐ bit acer bit -‐, the called upon device executes the request and transmits it's data back -‐ if required -‐ to the board over the same line using the clock signal sFll generated by the Master on SCL as Fming. The iniFal eight bits (i.e. eight clock pulses) from the Master to Slaves contain the address of the device the Master wants data from. The bits acer contain the memory address on the Slave that the Master wants to read data from or write data to, and the data to be wriIen, if any.
LCD monitor with I2C Driver
Board I2C/TWI pins
Uno, Ethernet A4 (SDA), A5 (SCL)
Mega2560 20 (SDA), 21 (SCL)
Leonardo 2 (SDA), 3 (SCL)
Due 20 (SDA), 21 (SCL), SDA1, SCL1
Jumper Blackligth
Arduino DUE Pin Map
The Circuit
PCF8574T Arduino
SDA SDA
SCL SCL
Vcc +5V
GND GND
The Code
#include <LiquidCrystal_I2C.h> #include <Wire.h> LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { // put your setup code here, to run once: lcd.begin(); lcd.backlight(); lcd.print("ciao"); lcd.setCursor(0,1); lcd.print("rucola"); } void loop() { // put your main code here, to run repeatedly: }
hIps://github.com/fdebrabander/Arduino-‐LiquidCrystal-‐I2C-‐library
Sixth Program
Temperature and humidity sensor
DHT11 Sensor
The DHT11 is a relaFvely cheap sensor for measuring temperature and humidity. The DHT11 has three lines: • GND, • +5V • and a single data line. Signal transmission range: 20m Temperature range: 0-‐50°C Humidity range: 20-‐90%RH By means of a handshake, the values are clocked out over the single digital line. Datasheet: hIp://www.micro4you.com/files/sensor/DHT11.pdf
The Circuit
Parts List • Arduino • I2C LCD display 16×2 • DHT11 Temperature and Humidity Sensor • 4.7k resistor
Libraries • DHT11 Library (Sensor) • Wire Library (I2C communicaFon) • LiquidCrystal_I2C Library (LCD Monitor)
The Code #include <DHT11.h> #include <LiquidCrystal_I2C.h> #include <Wire.h> Int pin=4; DHT11 dht11(pin); LiquidCrystal_I2C lcd(0x27, 16, 2); double Kelvin(double celsius){ return celsius + 273.15; } void setup() { // put your setup code here, to run once: lcd.begin(); lcd.backlight(); lcd.clear(); lcd.print("HUM & TEMP"); delay(2000); lcd.clear(); lcd.print("StarFng ........"); delay(2000); }
void loop() { // put your main code here, to run repeatedly: int err; float temp, humi; if((err=dht11.read(humi, temp))==0) { lcd.clear(); lcd.setCursor(0,0); lcd.print("temp: "); lcd.print(Kelvin(temp)); lcd.print(" K"); lcd.setCursor(0,1); lcd.print(" hum: "); lcd.print(humi); lcd.print(" %"); } else { lcd.println(); lcd.print("Error No :"); lcd.print(err); } delay(DHT11_RETRY_DELAY); }
Contenuto kit
• 1 scheda ProtoShield con mini breadboard; 1 Breadboard MB102 830 punF; 15 LED (5 rossi, 5 verdi, 5 gialli); 10 Resistori metal film da 10KOhm; 10 Resistori metal film da 1KOhm; 10 Resistori metal film da 220 Ohm; 1 Circuito integrato SN74HC595 8-‐bit Shic Register; 1 Buzzer axvo; 1 Buzzer passivo; 10 pulsanF 12*12*7.3; 3 Fotoresistori; 1 Potenziometro da 10kOhm; 1 Sensore di temperatura LM35DZ LM35 TO-‐92; 1 Sensore di fiamma ad infrarossi; 1 Ricevitore ad infrarossi HS0038B HS0038 SIP3 TO-‐92; 2 Sensori di inclinazione(Tilt Sensor);
1 Tilt Sensor Switch; 1 modulo LCD Blu 1602 con interfaccia seriale IIC/I2C/TWI; 1 modulo joySFck PS2; 1 Motore Stepper 5V con scheda drive ULN2003; 1 Servo motore compaFbile SG90; 1 Modulo RGB 3 Colori; 1 Modulo Relè ad 1 canale 5V; 1 kit jumper wire (65 pezzi); 10 pezzi Dupont Line (F a M); 1 Header femmina 2.54mm 1x40 Pin Single Row; 1 case per baIerie 6-‐AA-‐1.5V; 1 Modulo Real Time Clock RTC DS1302; 1 kit RFID con Card read/write; 1 Modulo Sensore di suono; 1 Modulo Sensore di Temperatura e umidità DHT11; 1 TasFera a matrice 4x4; 1 Modulo Display 8x8 Dot-‐Matrix 32x32 mm; 1 Modulo Sensore del livello dell'acqua;
Fritzing
Dimensionamento dei componenA • Dimensionamento baIeria
• Dimensionamento aIuatore
Contactless thermometer
MLX90615 by Melexis
BaIery capacity 550 mAh @9 V
Contactless thermometer
Current consupAon
Current consupAon
Current consupAon
Current consupAon
References • hIp://predictabledesigns.com/how-‐to-‐develop-‐and-‐prototype-‐a-‐new-‐product/
• hIps://learn.sparkfun.com/tutorials/how-‐to-‐use-‐a-‐breadboard • hIp://www.electronics-‐tutorials.ws/resistor/res_1.html
• hIp://www.studyelectrical.com/2016/12/different-‐types-‐classificaFon-‐of-‐capacitors.html
• hIps://learn.sparkfun.com/tutorials/light-‐emixng-‐diodes-‐leds
• hIp://www.madehow.com/Volume-‐2/Printed-‐Circuit-‐Board.html • hIps://www.arduino.cc/en/Guide/IntroducFon • hIps://www.engineersgarage.com/tutorials/twi-‐i2c-‐interface