Skip to main content

Communicating with Arduino using Serial Communication | Arduino UNO | Tutorial | DIY Project

Communicating Arduino Using Serial Port Communication

In this tutorial we'll see, how to program Arduino to send and receive signals using serial ports. We'll send signals from PC to our UNO board, which will change the state of the LED and will return the current state.

Components Required

- 1 * Arduino UNO 
- 1 * USB Cable 
- 1 * LED 
- 1 * 220Ω Resistor 
- 1 * Breadboard 
- Several jumpers wires

Circuit Diagram

Procedure

1. Make the connections according to the circuit diagram.
2. Connect your Arduino UNO to PC.
3. Upload the code provided to the board using Arduino IDE.
4. Now go to tools > Serial Monitor. Try entering 0 and 1 alternatively to play with the LED.

Code


int ledpin=11;            //definition digital 11 pins as pin to control the LED

void setup()
{
  Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
  pinMode(ledpin,OUTPUT); //Set digital 11 port mode, the OUTPUT for the output
}
void loop()
{
    char receiveVal;                   // Defined receive data
   
    if(Serial.available() > 0)        //Receive serial data
    {        
        receiveVal = Serial.read();   //Save the serial data received 
        
       if(receiveVal == '1')          //Receive data is 1, lit LED lights    
       { 
           digitalWrite(ledpin,HIGH);  //print out the value of the LED       
           Serial.println("LED:ON");  //send data to the serial monitor
       }
       if(receiveVal == '0')           //Receive data is 0, off LED lights
       { 
           digitalWrite(ledpin,LOW);    //print out the value of the LED                
           Serial.println("LED:OFF"); //send data to the serial monitor
      } 
    }
  delay(50);                           //delay 50ms
}


Comments

Popular posts from this blog

Blink LED using Arduino UNO | Tutorial | DIY Project

Making an LED Blink Using Arduino UNO: For making an LED Blink using Arduino, which is a very basic project a beginner can perform, We'll need some components and pre-requisite knowledge of using computer system. Components Required: - 1 * Arduino UNO  - 1 * USB Cable  - 1 * 220Ω Resistor  - 1 * LED  - 1 * Breadboard  - 2 * Jumper Wires  Circuit Diagram: Procedure: 1. Make connections according to the circuit diagram. 2. Connect Arduino UNO to PC. 3. Upload the code provided. 4. Enjoy. Code : i nt ledPin=8; //definition digital 8 pins as pin // to control the LED void setup() { pinMode(ledPin,OUTPUT); //Set the digital 8 port mode, // OUTPUT: Output mode } void loop() { digitalWrite(ledPin,HIGH); //HIGH is set to about 5V PIN8 delay(1000); ...

Arduino | All you need to know about Arduino | Micro Controllers

A rduino Arduino is a micro-controller device, it is also quoted as an open source electronic platform. It is used for converting some inputs to outputs using GPIO pins provided on the semiconductor motherboard. It is commonly used by hobbyists, electronic enthusiasts and small scale industries to control things like diodes, transistor and relays. It is also contributing to the field of IoT - Internet of Things. Here's an image of Arduino's most common board, Arduino UNO. It is widely used by people for simple automating tasks.  What Are Micro-Controllers ? Microcontrollers, as defined on Wikipedia, are a small  computer  on a single  metal-oxide-semiconductor  (MOS)  integrated circuit  (IC) chip. A microcontroller contains one or more  CPUs  ( processor cores ) along with  memory  and programmable  input/output  peripherals. These are compact and portable devices which can be used in simple automation tasks. They are use...