You are on page 1of 11

Demonstration

In this project when you press a key, its displayed the value in your serial montior. Heres what you
should see in your Arduino IDE serial monitor when you start pressing the keypad keys.

Conclusion
Now you can create an interface for your Arduino using a keypad. You could also add an LCD to this
project.
Because these keypads consume 7 or 8 io pins, it may be better in some projects to use them in
conjunction with an IIC port expander. You can find some modules on aliexpress (and probably ebay too)
that have 8 digital ports, based on the 8574 chip, for under $5. On aliexpress search for things like IIC
8574 I/O and you can find modules with header pins ready to go. Using IIC you only use up 2 analog
pins on your arduino, plus you can still daisy chain other IIC devices like a 1602 LCD if desired.

Infrarou, IrDA, bibliotec


http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
A Multi-Protocol Infrared Remote Library for the Arduino

I2C
http://playground.arduino.cc/Main/WireLibraryDetailedReference

! I2C Detalii - WireLibraryDetailedReference.htm

I2C Philips NXP Manual ghid.pdf


http://www.nxp.com/products/interface_and_connectivity/#I2C Teorie i interfee I2C de vnzare

http://tronixstuff.com/2010/05/20/getting-started-with-arduino-chapter-seven/
The I2C bus (also known as two wire interface) is the name of a type of interface between devices
(integrated circuits) that allows them to communicate, control and share data with each other. (It was
invented by Philips in the late 1970s.
SDA (serial data) and the other SCL (serial clock).
Maxim DS1307 Serial I2C real-time clock.
ine minte ceasul chiar nealimentat i genereaz unde dreptunhjiulare
First of all, we need to know the I2C address for our DS1307. It is 068 in hexadecimal. Addresses are
unique to the device type, not each individual device of the same type.
/*
Example 7.3
reading and writing to the Maxim DS1307 real time clock IC
tronixstuff.com/tutorials
based on code by Maurice Ribble
17-4-2008 - http://www.glacialwanderer.com/hobbyrobotics
*/

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 Este adresa fix dat de fabric a circuitului

// Convert normal decimal numbers to binary coded decimal


byte decToBcd(byte val) Lucreaz cu numere codificate BCD
{
return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers


byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307


// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers

void setDateDs1307(byte second, // 0-59


byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(00010000); // sends 0x10 (hex) 00010000 (binary) to control
register - turns on square wave
Wire.endTransmission();
}

// Gets the date and time from the ds1307


void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12
hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}

void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.

second = 0;
minute = 47;
hour = 0;
dayOfWeek = 3;
dayOfMonth = 31;
month = 3;
year = 12;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}

void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,


&year);
Serial.print(hour, DEC);// convert the byte variable to a decimal number
when being displayed
Serial.print(":");
if (minute<10)
{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print("0");
}
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day of week:");
switch(dayOfWeek){
case 1:
Serial.println("Sunday");
break;
case 2:
Serial.println("Monday");
break;
case 3:
Serial.println("Tuesday");
break;
case 4:
Serial.println("Wednesday");
break;
case 5:
Serial.println("Thursday");
break;
case 6:
Serial.println("Friday");
break;
case 7:
Serial.println("Saturday");
break;
}
// Serial.println(dayOfWeek, DEC);
delay(1000);
}
Generare und 1 Hz
void sqw1() // set to 1Hz
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary)
Wire.endTransmission();
}
Wire.requestFrom(ads1110, 3);

Transmisie radio VirtualWire library for Arduino


http://www.airspayce.com/mikem/arduino/
Supports a number of inexpensive radio transmitters and receivers.
Nu folosete USART

Client
Trimite un mesaj i ateapt rspunsul
// client.pde
//
// Simple example of how to use VirtualWire to send and receive messages
// with a DR3100 module.
// Send a message to another arduino running the 'server' example, which
// should send a reply, which we will check
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: client.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
Serial.println("Sent");
digitalWrite(13, false);
// Wait at most 200ms for a reply
if (vw_wait_rx_max(200))
{
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
}
}
else
Serial.println("Timout");
}

Server
Ateapt uhn mesaj i rspunde
// server.pde
//
// Simple example of how to use VirtualWire to send and receive messages
// with a DR3100 module.
// Wait for a message from another arduino running the 'client' example,
// and send a reply.
// You can use this as the basis of a remote control/remote sensing system
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: server.pde,v 1.1 2008/04/20 09:24:17 mikem Exp $
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
const char *msg = "hello";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Wait for a message
vw_wait_rx();
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
const char *msg = "goodbye";
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(" ");
}
Serial.println("");
// Send a reply
vw_send((uint8_t *)msg, strlen(msg));
digitalWrite(13, false);
}
}

Transmisie prin Xbee


ZigBee (este protocolul)
baud rates of 250 kbit/s is targeted at radio-frequency (RF) applications that require a low data rate, long
battery life, and secure networking.
baud rates of 250 kbit/s
Scump, 2,4 GHz, dar i 800 MHz

LCD monocrom
Four-bit parallel interface
This is the cheapest method of interface, and our first example for this article. Your LCD will need a
certain type of controller IC called a Hitachi HD44780 or compatible such as the KS0066. From a
hardware perspective, there are sixteen pins on the LCD. These are usually in one row:

GND
5V (careful! Some LCDs use 3.3 volts adjust according to LCD data sheet from supplier)
Contrast
RS
RW
Enable
DB0 (pins DB0~DB7 are the data lines)
DB1
DB2
DB3
DB4
DB5
DB6
DB7
backlight + (unused on non-backlit LCDs) again, check your LCD data sheet as backlight voltages can
vary.
backlight GND (unused on non-backlit LCDs)
GLCD

http://tronixstuff.com/2011/01/08/tutorial-arduino-and-monochrome-lcds/
ILI9325 LCD TFT

IrDA
http://tronixstuff.com/2011/03/30/tutorial-arduino-and-infra-red-control/
ILI 9325 LCD TFT 240x320
http://tronixstuff.com/2013/04/26/tutorial-arduino-and-ili9325-colour-tft-lcd-modules/

ADC
ADC 1110 16 bii
#include "Wire.h"
#define ads1110 0x48
float voltage, data;
byte highbyte, lowbyte, configRegister;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
Wire.requestFrom(ads1110, 3);
while(Wire.available()) // ensure all the data comes in
{
highbyte = Wire.read(); // high byte * B11111111
lowbyte = Wire.read(); // low byte
configRegister = Wire.read();
}

data = highbyte * 256;


data = data + lowbyte;
Serial.print("Data >> ");
Serial.println(data, DEC);
Serial.print("Voltage >> ");
voltage = data * 2.048 ;
voltage = voltage / 32768.0;
Serial.print(voltage, DEC);
Serial.println(" V");
delay(1000);
}

Surs de tensiune de referin extern, Aref


analogReference(EXTERNAL); // use AREF for reference voltage

SPI
Poate comunica n ambele sensuri. I2C nu poate.
MOSI Master-out, Slave-in. This line carries data from our Arduino to the SPI-controlled device(s);
MISO Master-in, Slave out. This line carries data from the SPI-controlled device(s) back to the
Arduino;
SS Slave-select. This line tells the device on the bus we wish to communicate with it. Each SPI device
needs a unique SS line back to the Arduino;
SCK Serial clock.
Within these tutorials we consider the Arduino board to be the master and the SPI devices to be slaves. On
our Arduino Duemilanove/Uno and compatible boards the pins used are:
SS digital 10. You can use other digital pins, but 10 is generally the default as it is next to the other SPI
pins;
MOSI digital 11;
MISO digital 12;
SCK digital 13;
#include "SPI.h"
SPI.begin();

SPI.setBitOrder(MSBFIRST);

SPI.setBitOrder(LSBFIRST);
SPI.transfer(value); emite sau primete
Pentru a citi se selecteaz registrul i se scrie 0
// send the device the register you want to read:
SPI.transfer(dataToSend);
// send a value of 0 to read the first byte returned:
result = SPI.transfer(0x00); -- se poate repeta dac serverul mai are de trimis un byte

Ultrasunete
http://tronixstuff.com/2011/11/28/tutorial-parallax-ping-ultrasonic-sensor/

The Ping))) only measures a distance when requested to do this we send a very short HIGH pulse of
five microseconds to the signal pin.
// Example 45.1 - tronixstuff.com - CC by-sa-nc
// Connect Ping))) signal pin to Arduino digital 8
int signal=8;
int distance;
unsigned long pulseduration=0;
void setup()
{
pinMode(signal, OUTPUT);
Serial.begin(9600);
}
void measureDistance()
{
// set pin as output so we can send a pulse
pinMode(signal, OUTPUT);
// set output to LOW
digitalWrite(signal, LOW);
delayMicroseconds(5);

// now send the 5uS pulse out to activate Ping)))


digitalWrite(signal, HIGH);
delayMicroseconds(5);
digitalWrite(signal, LOW);

// now we need to change the digital pin


// to input to read the incoming pulse
pinMode(signal, INPUT);

// finally, measure the length of the incoming pulse


pulseduration=pulseIn(signal, HIGH);
}
void loop()
{
// get the raw measurement data from Ping)))
measureDistance();

// divide the pulse length by half


pulseduration=pulseduration/2;
// now convert to centimetres. We're metric here people...
distance = int(pulseduration/29);

// Display on serial monitor


Serial.print("Distance - ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}

Ethernet
! ARDUINO C Programming si hard Bayle.pdf
Adresa MAC o gsesc pe plac
Adresa IP trebuie s fie unic n reea
Appletul de pe calc
We need the library hypermedia. We can find it at http://ubaa.net/shared/
processing/udp.
Autorul prefer protocolul UDP
Pentru TCP http://arduino.cc/en/Reference/Ethernet.

Bluetooth
2400-2480 MHz
Permite crearea de reele cu securitate
Modelul referit https://www.sparkfun.com/products/10559 cost 59$

Wi-FI
Wi-Fi isa set of communication protocols wireless driven by standards of IEEE
802.11. These standards describe characteristics of Wireless Local Area Networks
(WLANs).
Mai multe tipuri:
Infrastructure mode: se comunic printr-un nod, securitate
Ad-hoc, fiecare cu fiecare
Dei mai bun, mai ieftin ca bluet
Internet, cuplare la twitter
! ARDUINO C Programming si hard Bayle.pdf
Internet, interogare Google
This example shows you how to make a HTTP request using an Ethernet shield. It returns a Google
search for the term "Arduino". The results of this search are viewable as HTML through your Arduino's
serial window.

/*
Web client

This sketch connects to a website (http://www.google.com)


using an Arduino Wiznet Ethernet shield.

You might also like