9 Arduino
9 Arduino
2
Arduino UNO
Microcontroller
Digital pins
Reset switch
Crystal oscillator
TX RX LEDs
4
Major Components
5
USB connector
7
Microcontroller
8
Microcontroller
• Atmega328P has the following components:
• Flash memory (Flash ROM) of 32KB: Stores the application
code to be run
• RAM: 2KB
• CPU: Fetches the program instructions from flash memory
and runs them with the help of RAM
• Flash memory
• EEPROM of 1KB: Store small amount of data like states of
input or output devices so they it can be retained even if the
Arduino loses power
9
Analog input pins:
• The Arduino UNO board has 6 analog input
pins, labeled “Analog 0 to 5”
• These pins can read the signal from an analog
sensor like a temperature sensor and convert it
into a digital value so that the system
understands
• These pins just measure voltage and not the
current because they have very high internal
resistance. Hence, only a small amount of
current flows through these pins
• Although these pins are labeled analog and are
analog input by default, these pins can also be
used for digital input or output
10
Digital pins:
Pins labeled “Digital 0 to 13”
Used as either input or output pins
When used as output, these pins act as a power
supply source for the components connected to
them
When used as input pins, they read the signals
from the component connected to them
When digital pins are used as output pins, they supply 40 milliamps of
current at 5 volts, which is more than enough to light an LED
Some of the digital pins are labeled with tilde (~) symbol next to the pin
numbers (pin numbers 3, 5, 6, 9, 10, and 11)
These pins act as normal digital pins but can also be used for Pulse-Width
Modulation (PWM), which simulates analog output like fading an LED in
and out..
11
USB interface chip:
12
TX – RX LEDs:
13
Temperature Sensor
14
void setup() {
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(7, OUTPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
float temperatureCelsius = (voltage-0.5)* 100;
Serial.print("Temperature: ");
Serial.print(temperatureCelsius);
Serial.println("\xB0 C");
15
if (temperatureCelsius >= 45) {
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(7, HIGH);
}
else if (temperatureCelsius >= 35 && temperatureCelsius < 45)
{
digitalWrite(3, HIGH);
digitalWrite(5, HIGH);
digitalWrite(7, LOW);
}
else if (temperatureCelsius >= 30 && temperatureCelsius < 35)
{
digitalWrite(3, HIGH);
digitalWrite(5, LOW);
digitalWrite(7, LOW);
}
else
{
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(7, LOW);
}
delay(1000);
}
16
Thank you
17