The document outlines an Arduino course that covers various projects involving components like sensors, motors, and displays. Key topics include using the Arduino IDE for programming with sketches, controlling outputs through PWM, and interfacing with various modules like Bluetooth and ultrasonic sensors. It provides detailed instructions and circuit designs for hands-on projects such as using LEDs, push buttons, and LCDs with the Arduino Uno.
WHAT WE LEARN
â˘P8-Arduino with LM35.
⢠P9-Arduino with gas sensor.
⢠P10-Arduino with dc motor.
⢠P11-Arduino with Servo Motor.
⢠P12-Arduino with Bluetooth.
⢠P13-Arduino with ultrasonic.
⢠P14-Arduino with IR sensor.
⢠Arduino IDE.
⢠P1-Arduino with led.
⢠P2-Arduino with push button.
⢠P3-Arduino with potentiometer.
⢠P4-Arduino with PWM.
⢠P5-Arduino with LCD.
⢠P6-Arduino with PIR.
⢠P7-Arduino with DHT11
STRUCTURE OF THEPROGRAM
ďEach Arduino program (often called a sketch)
has two required functions:
1-void setup (){ }
All the code between the two curly brackets will
be run once when your
Arduino program first runs.
2-void loop (){ }
This function is running after setup has finished.
After it has run once it will be run again, and
again, until power is removed.
5.
VARIABLES
1-int (integer): Themain workhorse, stores a number in 2 bytes (16 bits).
2-float (float): Used for floating point math (decimals). Takes 4 bytes
(32bits).
3-char (character): Stores one character using the ASCII code, (i.e 'A' =
65). Uses one byte (8 bits)
DIGITAL PORTS
1-pinMode (pin,mode):
Used to set a pins mode, pin is the pin number and the mode can either be INPUT or OUTPUT.
2- digitalWrite(pin, value):
Once a pin is set as an OUTPUT, it can be set either HIGH (pulled to +5 volts) or LOW (pulled
to ground).
3- int digitalRead(pin);
Once a pin is set as an INPUT you can use this to return whether it is HIGH (pulled to+5 volts)
or LOW (pulled to ground).
8.
ANALOG PORTS
1-int analogWrite(pin,value):
Someof the Arduino's pins support pulse width modulation (3, 5, 6, 9,10 and 11). This turns
the pin on and off very quickly making it act like an analog output (Pulse Width Modulation
PWM technique). The value is any number between 0 bit (0% duty cycle ~0v) and 255 bits
(100% duty cycle ~5
volts).
2-int analogRead(pin):
When the analog input pins are set to input you can read their voltage. A value between 0bit
(for 0volts) and 1024 bit (for 5volts) will be returned.
9.
CONTROL STRUCTURE
if(condition){ }
elseif( condition ){ }
else { }
This will execute the code between the curly brackets if the condition is true,
and if not it will test the else if condition if that is also false the else code will
execute.
ANALOG PORTS INPUT
-int analogRead(pin):
When the analog input pins are set to input you can read their voltage. A value
between 0bit (for 0volts) and 1024 bit (for 5volts) will be returned.
SERIAL
Serial
Used for communicationbetween the Arduino board and a computer or other devices.
All Arduino boards have at least one serial port (also known as a UART or USART),
and some have several.
Serial.begin(speed) ď¨ Sets the data rate in bits per second (baud) for serial data
transmission.
Serial.available() ď¨ Get the number of bytes (characters) available for reading from
the serial port. This is data thatâs already arrived and stored in the serial receive buffer
(which holds 64 bytes).
31.
SERIAL
Serial.read()ď¨ Reads incomingserial data.
Serial.print(val) ď¨ Prints data to the serial port as human-readable ASCII text.
Serial.println() ď¨ Prints data to the serial port as human-readable ASCII text followed
by a carriage return character (ASCII 13, or 'r') and a newline character (ASCII 10, or
'n').
Serial.write(val) ď¨ Writes binary data to the serial port. This data is sent as a byte or
series of bytes; to send the characters representing the digits of a number use the
print() function instead.
PULSE WIDTH MODULATION(PWM)
Pulse Width Modulation or PWM is a technique for supplying electrical power to a
load that has a relatively slow response. The supply signal consists of a train of
voltages pulses such that the width of individual pulses controls the elective voltage
level to the load. Both AC and DC signals can be simulated with PWM. In these notes
we will describe the use of PWM on an Arduino for controlling LEDs and DC motors.
An Arduino Uno has 14 digital I/O pin(s) 6 provide PWM output. The PWM give an
analog output signal in rage[0,255] where each 255samples means 5V digital so, to
determine the required analog output voltage use the relation:
37.
PULSE WIDTH MODULATION(PWM)
Veff is the required output level such (2, 2.5, 3, 3.5âŚetc.).
LIQUID CRYSTAL DISPLAY(LCD)
Parallel LCD Pins
PIN1 or VSS to ground
PIN2 or VDD or VCC to +5v power
PIN3 or VEE to ground (gives maximum contrast best for a
beginner)
PIN4 or RS (Register Selection) to PIN0 of ARDUINO
UNO PIN5 or RW (Read/Write) to ground (puts LCD in read
mode eases the communication for user)
PIN6 or E (Enable) to PIN1 of ARDUINO UNO
PIN11 or D4 to PIN8 of ARDUINO UNO
PIN12 or D5 to PIN9 of ARDUINO UNO
PIN13 or D6 to PIN10 of ARDUINO UNO
PIN14 or D7 to PIN11 of ARDUINO UNO
PIN 15 and 16 for background light.
LIQUID CRYSTAL DISPLAY(LCD)(CONT.)
Basics of the I2C Communication Protocol
SDA (Serial Data) â The line for the
master and slave to send and receive
data.
SCL (Serial Clock) â The line that
carries the clock signal.
P5-ARDUINO WITH LCD(CONT.)
-Important LCD instructions:
- #include< LiquidCrystal.h> ď¨ This library allows an Arduino board to control LiquidCrystal
displays (LCDs).
- lcd.begin(16,2) ď¨ This instruction use to set up the LCD's number of columns and rows.
- lcd.print("Message") ď¨ This instruction used for print a message to the LCD if need to display
numbers must remove the double quotation mark like this {lcd.print(var)}.
- lcd.setCursor(j, i) ď¨ This instruct used for determine site scripting as row and column where,( j)
represent the column and (i) represent the row. The figure below shows us the locations of rows and
columns in the 2x16 Liquid Crystal Display.
49.
P5-ARDUINO WITH LCD(CONT.)
-Important LCD instructions:
- lcd.clear( ) : This instruction used to clear the screen .
- delay(n): This instruct used to give delay time where,(n) is an integer number in millisecond.
P5-ARDUINO WITH LCD
-ImportantI2C LCD instructions:
- #include <Wire.h> ď¨ This library allows you to communicate with I2C / TWI devices.
- #include <LiquidCrystal_I2C.h> ď¨ This library allows an Arduino board to
control I2C LiquidCrystal displays (LCDs).
- lcd.init() ď¨ initialize the lcd.
MOTION SENSOR (PIR)
â˘There are two potentiometers on the board to adjust a couple of
parameters:
⢠Sensitivityâ This sets the maximum distance that motion can be
detected. It ranges from 3 meters to approximately 7 meters. The
topology of your room can affect the actual range you achieve.
⢠Timeâ This sets how long that the output will remain HIGH after
detection. At minimum it is 3 seconds, at maximum it is 300
seconds or 5 minutes.
⢠Hâ This is the Hold/Repeat/Retriggering In this position the HC-
SR501 will continue to output a HIGH signal as long as it
continues to detect movement.
⢠Lâ This is the Intermittent or No-Repeat/Non-Retriggering In this
position the output will stay HIGH for the period set by the TIME
potentiometer adjustment.
LM35 TEMPERATURE SENSOR
â˘The LM35 is an integrated circuit sensor that can be used to measure
temperature with an electrical output proportional to the temperature (in đC),
It has an output voltage that is proportional to the Celsius temperature 10 mv
for 1 Celsius, the accuracy of reading up to Âą0.5 đC the rated range of
LM35 is â55°C to +150°C.
⢠The general equation to convert the voltage into temperature is given below:
SERVO MOTOR
The servomotor unlike dc motors; with servo
motors you can position the motor shaft at a specific
position (angle) using control signal. The motor
shaft will hold at this position as long as the control
signal not changed. This is very useful for
controlling robot arms, unmanned airplanes control
surface or any object that you want it to move at
certain angle and stay at its new position.
P11-ARDUINO WITH SERVOMOTOR (CONT.)
important servo motor instructions:
These instructions found in the library following:
#include <Servo.h>
1-Servo myservo: create servo object to control a servo where, my servo is variable!
2- myservo.attach(pin number): attaches the servo on pin number such(pin 9) to the
servo object.
3-myservo.write(pos): tell servo to go to position in variable 'pos" such 20
degree,90degree ⌠etc '
P12-ARDUINO WITH BLUETOOTH
ATCommand Mode:
AT mode refers to the form of communication to the HC-05 Bluetooth Module.
AT Commands are short for ATtention Commandswhich is a command
languageused for modems known as theHayes command set. Hayes command
setis a specific command language originally developed by Dennis Hayes for
the Hayes Smartmodem 300 baud modem in 1981 [2].The HC-05 Bluetooth
Module was used due to its ability to be configuredas Master or Slave mode as
well as adding a password to the module.
P12-ARDUINO WITH BLUETOOTH(CONT.)
ATCommand Mode (Bluetooth Connection) (Cont.):
The red LED has 3 continuous flashing modes: ON for 2 seconds and Off for 2
seconds (AT Command Mode), fast blinking (searching for a connection), Off
for 2 seconds and blinks twice (connected).
97.
P12-ARDUINO WITH BLUETOOTH(CONT.)
Enterto AT Command Mode :
To enter AT Command Mode the following must be
done:
1.Arduino Uno must be connected to the Computer
via USB and Arduino software opened
2.The Module must be disconnected from Arduino
3.Arduino needs to have a Blank Sketch downloaded
98.
P12-ARDUINO WITH BLUETOOTH(CONT.)
Enterto AT Command Mode : (Cont.)
4.The Button Switch must be held pushed and
simultaneously connected to the Arduino as seen in
figure 2 (This is done most easily if using a
breadboard).
5.The Button Switch can be released once connected
to Arduino and the Bluetooth Module LED should
be blinking ON for 2 seconds and Off for 2 seconds
indicating it has entered AT Command Mode
6.The Correct COM Port should be Selected and
Serial Monitor needs to be opened as seen in figure.
99.
P12-ARDUINO WITH BLUETOOTH(CONT.)
Enterto AT Command Mode
: (Cont.)
Serial Monitor:
7.38400 baud rate should be
selected and âBoth NL & CRâ as
seen in figure.
ULTRASONIC SENSOR
An ultrasonicsensor is an electronic device that measures
the distance of a target object by emitting ultrasonic sound
waves, and converts the reflected sound into an electrical
signal. Ultrasonic waves travel faster than the speed of
audible sound (i.e. the sound that humans can hear).
Ultrasonic sensors have two main components: the
transmitter (which emits the sound using piezoelectric
crystals) and the receiver (which encounters the sound
after it has travelled to and from the target).