vendredi 2 février 2018

Serial In Arduino

Arduino Serial (UART and USART)





Arduino has a built in Universal Synchronous Asynchronous Receiver Transmitter (USART) hardware that allows to communicate with a wide range of serial devices such as memory chips, LCDs, personal computers, etc. The USART module has two modes of operation: synchronous (requires a synchronized clock between the transmitter and receiver) and asynchronous (no synchronization clock required). As the asynchronous mode is more popular, we will focus today on this and will establish a two way serial data link between the Arduino and a PC.



Serial communications are used in microcontroller-based systems, mostly due to the scarcity of available I/O pins. Besides for long distance communications, serial data transfer is more simple and cost effective as the required hardware connections in the data link can be reduced to three (Tx, Rx, and Gnd).

in this tutorial  we ll show you a simple use of serial of  2 Arduino   which will show us that we are connected and the serial is ready to recieve an information

for that we ll need :
              - 2 Arduino
              - LED
              - Button
              - 330  resistance
              - 10K resistance


//Master code
int bt=10;

void setup() {
Serial.begin(9600);
pinMode(bt,INPUT);
}
void loop() {
  if (int r=digitalRead(bt)==1) {
Serial.print('H');
delay(1000);
  }
  else {
Serial.print('L');
delay(1000);
}
}


//Reciever code
const int led = 13;
int car1;


void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
    }
 
 
void loop() {
   if (Serial.available() > 0) {
     car1 = Serial.read();
     if (car1 == 'H') {
     digitalWrite(led, HIGH);
     }
     if (car1 == 'L') {
       digitalWrite(led, LOW);
     }
   }
}
   

figure




           







1 commentaire:

  1. Online Gaming - JT Hub
    Playtech Group AB. PENNSYLVANIA online gaming 광주광역 출장안마 with innovative software Playtech Group 하남 출장마사지 AB, Limited - 파주 출장안마 The company provides all 삼척 출장마사지 online 나주 출장마사지 gaming content

    RépondreSupprimer