Lab 8
Lab 8
Objectives: to learn how to deal with Fire detector sensor and Stepper Motor.
The component:
The Arduino
Fire Sensor
1 X LED or Buzzer
1X Resistor
Breadboard
Connecting wires
Introduction:
These types of sensors are used for short range fire detection and can be
used to monitor projects or as a safety precaution to cut devices off / on.
Range: I have found this unit is mostly accurate up to about 3 feet.
How it works: The flame sensor is very sensitive to IR wavelength at
760 nm ~ 1100 nm light.
Analog output (A0): Real-time output voltage signal on the thermal
resistance.
Digital output (D0): When the temperature reaches a certain threshold,
the output high and low signal threshold adjustable via potentiometer.
Pin Configuration:
VCC...... Positive voltage input: 5v for analog 3.3v for Digital.
A0.......... Analog output
D0......... Digital output
GND..... Ground
Page 1 of 8
Wiring to an Arduino:
Exercise: Could you add led as well buzzer to complete the circuit
The code:
// lowest and highest sensor readings:
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
void setup() {
Page 2 of 8
// initialize serial communication @ 9600 baud:
Serial.begin(9600);
}
void loop() {
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// range value:
switch (range) {
case 0: // A fire closer than 1.5 feet away.
Serial.println("** Close Fire **");
break;
case 1: // A fire between 1-3 feet away.
Serial.println("** Distant Fire **");
break;
case 2: // No fire detected.
Serial.println("No Fire");
break;
}
delay(1); // delay between reads
}
Page 3 of 8
The following code maps and reads the analog values given by the flame sensor (0-
1024). The stock flame sensor will have the following reaction with this code:
If holding a flame within 1.5 feet in front of the sensor; "case 0" will be activated
and " ** Close Fire ** " will be sent to the serial monitor. If holding a flame
between 1.5 feet and 3 feet in front of the sensor; "case 1" will be activated and "
**Distant Fire** " will be sent to the serial monitor. If no flame is detected in
front of the sensor; "case 2" will be activated and " No Fire " will be sent to the
serial monitor.
* To view the output, point a serial monitor such as Putty at your Arduino.
* This code is constantly updating in order to provide a real time feedback of the
flame sensor.
We are surrounded by stepper motors without even realizing it, as they are used in
so many everyday items, including window blinds, 3D printers, DVD players,
security cameras, and CNC machines. We’re a lot closer to stepper motors than
you think. Stepper motors fall somewhere between a conventional DC motor and a
servo motor. They can rotate continuously like DC motors and be positioned precisely
(in discrete steps) like servo motors.
If you’re just getting started with stepper motors, the 28BYJ-48 is a great choice. They
typically come with a ULN2003-based driver board, making them very simple to use.
The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5V. It’s perfect for
projects that require precise positioning, like opening and closing a vent.
Page 4 of 8
Because the motor does not use contact brushes, it has a relatively precise
movement and is quite reliable.
Despite its small size, the motor delivers a decent torque of 34.3 mN.m at a speed
of around 15 RPM. It provides good torque even at a standstill and maintains it as
long as the motor receives power.
The only drawback is that it is somewhat power-hungry and consumes energy even
when it is stationary.
Pinout:
The 28BYJ-48 stepper motor has five wires. The pinout is as follows:
Page 5 of 8
The ULN2003 Driver Board:
Because the 28BYJ-48 stepper motor consumes a significant amount of power, it
cannot be controlled directly by a microcontroller such as Arduino. To control the
motor, a driver IC such as the ULN2003 is required; therefore, this motor typically
comes with a ULN2003-based driver board.
Page 6 of 8
IN1 – IN4 are motor control input pins. Connect them to the Arduino’s digital
output pins.
void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}
void loop() {
// Rotate CW slowly at 5 RPM
Page 7 of 8
myStepper.setSpeed(5);
myStepper.step(stepsPerRevolution);
delay(1000);
// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(MotorInterfaceType, 8, 10, 9, 11);
void setup() {
// set the maximum speed, acceleration factor,
// initial speed and the target position
myStepper.setMaxSpeed(1000.0);
myStepper.setAcceleration(50.0);
myStepper.setSpeed(200);
myStepper.moveTo(2038);
}
void loop() {
// Change direction once the motor reaches target position
if (myStepper.distanceToGo() == 0)
myStepper.moveTo(-myStepper.currentPosition());
Page 8 of 8