session 4 arduino
session 4 arduino
VCC supplies power for the module. You can connect it to 5V output •
from your Arduino.
GND is the Ground Pin and needs to be connected to GND pin on •
the Arduino •
provides a digital representation of the presence of combustible •
D0 gases.
A0 provides analog output voltage in proportional to the concentration •
of smoke/gas
First project
1-For loop
2-While loop
3-do while loop
the syntax of for loop
Test
Expression
Updatecounter
Second task
void setup() {
Serial.begin ( 9600);
for ( int i = 0 ; i <= 1000 ; i++ ){
Serial.println( i ) ;}
}
void loop() {
}
While loop
The syntax of While loop
While (condition){
Statement ;
}
While loop
Flow chart for while
Test •
Expression
Arduino code
#define sw 6
#define led 5
int i=0 ;
void setup() {
Serial.begin (9600);
pinMode(sw,INPUT_PULLUP);
pinMode(led,OUTPUT);
}
void loop() {
while(digitalRead (sw)==LOW ){
digitalWrite (led,HIGH);}
digitalWrite (led,LOW);
Serial.println(i);
i++;}
Proteus design
Ultrasonic Sensor
HC-SR04 Ultrasonic Distance Sensor that can report the range
of objects up to 13 feet away( between 2 cm to 400). Which is
really good information to have if you’re trying to avoid your
robot driving into a wall!
They are low power.
HC-SR04 Hardware Overview
the HC-SR04 Ultrasonic distance sensor consists of •
two ultrasonic transducers. The one acts as a transmitter
which converts electrical signal into 40 KHz ultrasonic sound
pulses. The receiver listens for the transmitted pulses. If it
receives them it produces an output pulse whose width can
be used to determine the distance of the pulse travelled
What is Ultrasound?
Ultrasound is high-pitched sound waves with frequencies •
higher than the audible limit of human hearing.
Human ears can hear sound waves that vibrate in the range •
from about 20 times a second to about 20,000 times a
second.
HC-SR04 Ultrasonic Sensor Pinout
VCC VCC is the power supply for HC-SR04 Ultrasonic distance sensor •
which we connect the 5V pin on the Arduino.
Trig
(Trigger) pin is used to trigger the ultrasonic sound pulses. •
Echo
ECHO pin produces a pulse when the reflected signal is received. •
The length of the pulse is proportional to the time it took for the
transmitted signal to be detected.
GND
GND should be connected to the ground of Arduino
How Does HC-SR04 Ultrasonic Sensor Work