Exp 7
Exp 7
Exp 7
7: SERIAL COMMUNICATION
Aim:
1. To establish serial communication between Arduino Uno and PC
2. To receive a number through serial communication and display it in 7 segment display.
Components Requirement:
Theory:
Code Structure
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
● setup : It is called only when the Arduino is powered on or reset. It is used to initialize
variables and pin modes
● loop : The loop functions runs continuously till the device is powered off. The main logic of
the code goes here. Similar to while (1) for micro-controller programming.
PinMode
Pre Lab:
1. What is serial communication?
2. What is baud rate?
Lab Procedure:
1. Connect the Arduino Uno Development Board to the Desktop/Laptop through Type B
USB cable.
2. Write the code and compile it in Arduino IDE.
3. Select USB port in Arduino IDE.
4. Select Arduino Uno Development Board in Arduino IDE.
5. Download the code into Arduino Uno Development Board
6. Run the code in Arduino Uno Development Board.
7. Observe and verify the output.
Post Lab:
1. How do you establish serial communication between Arduin and PC?
2. In the code, explain the statement
COUNT = Serial.read()-48;
Output:
{
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
break;
}
while(!Serial.available());
COUNT = Serial.read()-48;
Serial.println(COUNT);
/*
if (COUNT<10)
{
COUNT++;
delay(1000);///increment count integer for every second
}
if (COUNT==10)
{
COUNT=0;// if count integer value is equal to 10, reset it to zero.
delay(1000);
}*/
}
Result:
We can read serial input and display it on a 7 segment display