Arduino Unit4
Arduino Unit4
• It is cheap
– Lights, LED’s
– Motors
– Speakers
– Displays (LCD)
Sensors and Actuators
• The sensor is a device which
converter the physical or chemical
stimulus into an output signal.
• Physical parameters could be light,
heat, motion, moisture, force,
pressure, displacement, etc.
• It produces output signal as
electrical, mechanical, magnetic,
etc.
Sensors and Actuators
• Actuators changes electrical signals into mechanical signal.
• Actuators are connected to a system's output.
• It receives an electrical signal as input and produces
mechanical movement as output.
• Electrical signals are generated via sensors. On the other
hand, an actuator produces energy in the form of heat or
motion.
• Example of sensors are cameras, microphones, etc. Example
of actuators are LEDs, loudspeakers, motor controllers,
lasers, etc.
Sensors
Arduino
https://getintopc.com/softwares/3d-cad/proteus-professional-2020-free-download/
Getting Started (Installing Arduino IDE and Setting up Arduino Board)
https://www.arduino.cc/en/Main/Software
2. Connect the board to your computer via the USB cable
3. If needed, install the drivers
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
Basic Procedure
void setup()
{
// runs once
}
void loop()
{
// repeats
}
Arduino IDE
IDE =
Integrated Development
Environment
http://www.arduino.cc/en/Guide/Environ
ment
Arduino IDE (Cont..)
Your computer
communicates to the
Arduino microcontroller via a
serial port → through a USB-
Serial adapter.
pinMode(pin, mode);
Sets pin to either INPUT or OUTPUT
Eg1. pinMode(13, OUTPUT);
digitalRead(pin);
Reads HIGH or LOW from a pin
Eg3. digitalRead(2);
digitalWrite(pin, value);
Writes HIGH or LOW to a pin
Eg2. digitalWrite(13, HIGH);
Arduino IDE
Arduino IDE
Arduino Data Types (Cont..)
• Boolean types have two possible values: true or false. They are
commonly used for things like checking the state of a switch (if
it’s pressed or not).
• You can also use HIGH and LOW as equivalents to true and false
where this makes more sense;
Syntax:
Features-
• Can be used for obstacle sensing, fire detection, line sensing,
etc
• Input Voltage: 5V DC
• Comes with an easy to use digital output
• Can be used for wireless communication and sensing IR remote
signals
IR Sensor have three Pins
1. VCC = +5V DC
2. GND
InfraRed (IR) Sensor
InfraRed (IR) Sensor
InfraRed (IR) Sensor
Arduino sketch & Circuit diagram
/* void loop()
IR Proximity Sensor interface code {
Turns on an LED on when obstacle is if(digitalRead(ProxSensor)==LOW)
detected, else off. //Check the sensor output
*/ {
digitalWrite(13, HIGH); // set the LED on
const int ProxSensor=2; Serial.println("Stop something is ahead!!
"); //Message on Serial Monitor
void setup() }
{ else
// initialize the digital Serial port. {
digitalWrite(13, LOW); // set the LED off
Serial.begin(9600); Serial.println("Path is clear");
// initialize the digital pin as an output. //Message on Serial Monitor
pinMode(13, OUTPUT); }
pinMode(ProxSensor,INPUT); delay(1000); // wait for a second
} }
Proteus design:
Ultrasonic Sensor
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
Arduino Sketch (Cont..)
void loop()
{ // Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microsec.
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= (duration*0.034)/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance ");
Serial.print(distance);
Serial.println("cm");
delay(500); //500 m.sec = 0.5 sec
}
pulsein()