0% found this document useful (0 votes)
3 views

arduino session 3 course

The document outlines various tasks related to Arduino programming, including controlling an LED with switches and checking number ranges with blinking LEDs. It discusses ADC resolution, communication protocols like UART, and provides example codes for reading voltage and temperature using an LM35 sensor. Additionally, it covers different types of operators in programming, including arithmetic, relational, logical, and assignment operators.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

arduino session 3 course

The document outlines various tasks related to Arduino programming, including controlling an LED with switches and checking number ranges with blinking LEDs. It discusses ADC resolution, communication protocols like UART, and provides example codes for reading voltage and temperature using an LM35 sensor. Additionally, it covers different types of operators in programming, including arithmetic, relational, logical, and assignment operators.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Prepared by:

Esraa taha ali


Task1

The first task is to make the led on if


the two switches are pressed .using a
pull up connections.
Proteus design
code
#define led 8
#define switch1 2
#define switch2 3
void setup() {
pinMode(led,OUTPUT);
pinMode(switch1,INPUT);
pinMode(switch2,INPUT);}
void loop() {
if (digitalRead(switch1)==LOW){
if (digitalRead(switch2)==LOW){
digitalWrite(led,HIGH);}
else{ digitalWrite(led,LOW); }
}
else{ digitalWrite(led,LOW); }
}
Task2

The second task is to check number if it


was in range of numbers blinking led .using
switch case .
code
#define led 8
int x=7;
void setup() {
pinMode(led,OUTPUT);}
void loop() {
switch ((x>5)&&(x<99)){
case 1: digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000); break;
case 0: digitalWrite(led,LOW);break; }
}
Tinker cad design
ADC Resolution

Resolution has two different definition:


1-the number of bits output by the ADC. Therefore,
an ADC which converts the analog signal to a 10-bit
digital value has a resolution of 10 bits
2-the ADC resolution is defined as the smallest
incremental voltage that can be recognized and thus
causes a change in the digital output.
Resolution law

The development in the field of semiconductors has led to the •


emergence of integrated circuits, which are integrated circuits
on field of semiconductors has led to the emergence of
integrated circuits, which are integrated circuits on small chips
The development of integrated circuits led to the emergence of
Real voltage = resolution * ADCRead

ADCRead = analogRead(input pin) •



potentiometer
potentiometer is a variable resistor.
They have three terminals a knob or slider that can be moved
to vary the resistance between the middle terminal and either
one of the outer terminals.

The resistance between the two outer terminals is a fixed


(constant) resistance.
The resistance between the middle terminal and either one of
the outer terminals varies from 0 Ω to the maximum resistance
Communication
Communication is to transfer data between two devices.
data can be anything like text ,documents, images, audio or video •
files etc.
Data can be sent or received between two systems or devices and •
it is in the form of bits 0’s and 1’s.
There are many types of protocols that are used in transferring •
data between two devices, but all these protocols are based on
.
either Parallel Communication or Serial Communication
Serial communication vs parallel communication

Serial communication parallel communication


1- serial communication transfers one 1- Parallel communication is a method •
bit of data at a time over two to four of transferring multiple bits of data
wires depending on the protocol. simultaneously using more number of
data lines.
2- the data transfer speeds in •
2-Parallel communication is very high •
serial communication is very less speed But these high speed data
when compared to that of parallel transfers in parallel communication
communication, requires more number of wires
3- this speed is sufficient for devices 3-the distance of communication is •
like printer, hard disk, mouse etc very less . they cannot be used for
long distance communication
Serial communication vs parallel communication
Communication in Arduino
When coming to Arduino, the communication between Arduino
UNO and computer or any other board is a serial
communication.
Arduino has a three serial data transmission protocols UART,
I2C, and SPI.

We'll take a quick look at UART protocol.


UART protocol
UART stands for Universal Asynchronous Receiver/Transmitter.
It is a hardware device (or circuit) used for serial communication
between two device .
One wire is for transmitting data (called the TX pin) and the other is for
receiving data (called the RX pin).
We can only connect two UART devices together .
UART
To transfer code from the PC to the arduino board we use a
UART protocol.
Arduino UNO has an on board serial to USB converter and
hence we can directly connect the Arduino to the computer.
Using this USB connection and Arduino IDE, we can send data
to Arduino or receive data from Arduino.
Serial Monitor
The data between the PC and arduino can be monitored with
the help of Serial Monitor in the Arduino IDE.
In Arduino environment, in order to begin serial
communication, we need to use a predefined function called
“Serial.begin(baud rate)”.
Serial functions
Serial.read()
Reads incoming serial data.
The first byte of incoming if serial data available or -1 if no data is
available. Data type: int.
Serial.readString()
return a String read from the serial buffer.
Serial.write()
Writes binary data to the serial port. This data is sent as a byte or
series of bytes
Serial.print()
Prints data to the serial port .
First project

The first project is to Read a various


voltage from the pot and monitor the
out put values of ADC on a Serial
monitor .
Code
#define pot A0
int ADCRead;
void setup() {
Serial.begin(9600); }
void loop() {
ADCRead=analogRead(pot);
Serial.print("The read from ADC=");
Serial.println( ADCRead);
}
Design on tinkercad
Proteus design
Transducer
LM35
lm35 calculations

Real voltage = resolution * ADCRead


Real voltage(mv) = 4.88mv* ADCRead*1000
Temp in celsius=Real voltage/10

volt
temp
Example 2
Write a code to display the temperature
measured using LM35 on the seial monitor.
Code
# define lm35 A0
int ADCRead,voltage,temp;
void setup() {
Serial.begin(9600);}
void loop() {
ADCRead=analogRead(lm35);
voltage=ADCRead*4.88;
temp=voltage/10;
Serial.print("Temp=");
Serial.println(temp);
}
Proteus design
Tinker cad design
Operators

Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Arithmetic operators
Operator name Operator simple Description Example

addition + Adds two operands A + B will give 30

subtraction - Subtracts second


operand from the first
A - B will give -10

multiplication * Multiply both operands A * B will give 200

division / Divide numerator by


denominator
B / A will give 2

Modulus Operator and


modulo % remainder of after an
integer division
B % A will give 0
Operator name
Relational operators
Operator simple Description Example
Checks if the value of
two operands is equal
equal to == or not, if yes then (A == B) is not true
condition becomes true.

Checks if the value of


two operands is equal
not equal to == or not, if values are not (A != B) is true
equal then condition
becomes true.
Checks if the value of left

less than < operand is less than the value


of right operand, if yes then
condition becomes true.
(A < B) is true

<
Checks if the value of left
operand is greater than the
greater than value of right operand, if yes (A > B) is not true
then condition becomes true.

less than or equal to


<= Checks if the value of left
operand is less than or equal to
the value of right operand, if (A <= B) is true
yes then condition becomes
true.

greater than or equal to


<= Checks if the value of left
operand is greater than or
equal to the value of right (A >= B) is not true
operand, if yes then condition
becomes true.
Logical operators
Operator name Operator Description Example
simple
Called Logical AND
operator. If both the
operands are non-
and && zero then then
(A && B) is true
condition becomes
true.
Called Logical OR
Operator. If any of the
two operands is non-
or || zero then then
(A || B) is true
condition becomes
true.
Called Logical NOT
Operator. Use to
reverses the logical
state of its operand. If
not = a condition is true
!(A && B) is false
then Logical NOT
operator will make
false.
assignment operators
Repeat the first task using operators

#define led 8
#define switch1 2
#define switch2 3
void setup() {
pinMode(led,OUTPUT);
pinMode(switch1,INPUT);
pinMode(switch2,INPUT);}
void loop() {
if ((digitalRead(switch1)==LOW)&&(digitalRead(switch2)==LOW)){
digitalWrite(led,HIGH);}
else{ digitalWrite(led,LOW); }
}

You might also like