کنترل یک خروجی از طریق شبکه یکی از اصلی ترین قسمت شبکه های هوشمند سازی گلخانه ها ، خانه های هوشمند و… است . در واقع با این کار شما امکان کنترل هر وسیله ای را از راه دور دارید . در این آموزش نحوه کنترل یک ماژول رله از سریق برد آردوینو و ماژول ENC28J60 خواهیم پرداخت . ماژول ENC28J60 مدل های مختلفی دارد که در این آموزش از مدل معمولی آن استفاده می کنیم . ENC28J60 یک ماژول شبکه با رابط SPI است که به راحتی می توانید آن را از طریق یک کابل شبکه به مودم متصل کرد . این ماژول از کلیه استاندارد های IEEE802.3 پشتیبانی می کند لذا می توانید درخواست های HTTP را به شبکه ارسال کنید و یا از طریق FTP با یک دیتابیس ارتباط داشته باشد .
در تصویر زیر پین های ماژول ENC28J60 نشان داده شده است :
همچنین در تصویر زیر شماتیک اتصال ماژول رله و ماژول ENC28J60 به آردوینو نشان داده شده است :
کد های آردوینو :
int latchPin = 5; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 6; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 4; // Data pin of 74HC595 is connected to Digital pin 4
byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
/*
* loop() - this function runs over and over again
*/
void loop()
{
leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++) // Turn all the LEDs ON one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(500);
}
}
/*
* updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
*/
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
پس از بستن مدار و پروگرام کردن آردوینو ، ماژول ENC28J60 را از طریق یک کابل شبکه به مودم خود متصل کنید . سپس وارد محیط Serial monitor شوید . IP که توسط آردوینو چاپ می شود را در مرورگر خود سرچ کنید تا پنل کنترل باز شود .



