WEEK 4 – Individual Project 01- MusiCake

Project Aim

I’ve done the testing of flame sensor and stepper motor at the previous stage, and the aim for this stage is to run these two components at the same time. The motor, led lights and buzzer will be on when flame is detected, and they will stop when the flame goes out.

Components needed:

Flame sensor

Buzzer

Led lights

Stepper Motor

Cables

 

Circuit Diagram

屏幕快照 2018-02-25 02.17.04.png

I connected the stepper motor to the Digital Pin 8 to ~11, the buzzer to digital pin ~5, the red led light to pin ~6, the green led light to pin 7. And I connect the AO pin of the sensor to pin A2, the DO pin to the pin ~3.

Schematic Diagram

屏幕快照 2018-02-25 02.32.14.png

Task 1 –  How to use flame sensor to control the stepper motor?

Coding

屏幕快照 2018-02-25 20.37.16.png

 

 

 

 

I put stepper motor speed into Setup { } with other component set up.

 

 

 

And, I put the direction of motor rotate under the ” if ( val == HIGH) “, which means if flame is detected by the sensor, the motor will start to run.

 

屏幕快照 2018-02-25 20.25.21.png

 

These code is for birthday song playing by the buzzer.

These code is for birthday song playing by the buzzer.

After upload this code to Arduino, the stepper motor will run when flame is detected, however, the led lights and buzzer only can run after the stepper finish one rotation. Also, the lights and buzzer won’t stop running if the flame goes out already, they only stop until the birthday song is finished. This situation is not what I want.

Please check the video to see the problem.

video: 

Task 2 – How to run stepper motor, led lights and buzzer at the same time when flame is detected?

Final flowchart.png

The flowchart shows the overall structure of the code should be.

As the myStepper.set function is to control a certain number of step, the next instruction cannot be executed before the motor finish one step, so the led lights and buzzer will run afterward.

final code-1.png
final code-2.png

To solve the problem, I set the ” stepsPerRev = 128 ” and the speed = 200.

 

 

Then, I insert ” myStepper.step(stepPerRev) ” after every set of output instruction instead of “delay( )”, so that the motor will run with other components at the same time.

The birthday song has 4 parts, this is a small part of part one.

 

 

 

 

final code-3.pngAlso, I set every 3  tone as a group in every “if(val=HIGH)” loop, which aims to make sure the program will check if there is flame detected after 3 tone produced, so that the program can stop when flame goes out.

 

 

 

The complete code is here.

 

https://create.arduino.cc/editor/yusu1224/bae0e22b-80ec-4158-8d1a-850c17261ad3/preview

Please check the video for final working model.

1351519611514_.pic_hd.jpg

video: 

Reference:

Flame sensor coding reference from: http://arduinosensors.nl/index.php?route=product/product&path=20&product_id=50

 

Advertisements

WEEK 3 – Individual Project 01- MusiCake

Project Brief

This project is to break the common sense about a flame sensor not only can be used on fire alarm but also can be applied to many other creative projects.

1371519614466_.pic_hd.jpg

The idea is about using the flame sensor to control the stepper motor, buzzer and LED lights to build a creative music box which can put a cake on it. The buzzer will play the music when flame is detected, and music stop when flame goes out. And, the motor will start to rotate the cake when flame is detected.

TASK 1 – How to use flame sensor to control a buzzer and a LED light at the same time?

Component:

Flame sensor

LED light

Buzzer

Cables

屏幕快照 2018-02-23 23.18.04.png

I connected the AO pin of the sensor to A0 input pin on UNO board, the LED light goes to Digital ~9, and the buzzer goes to Digital 12.

1281519428683_.pic_hd.jpg

Schematic Diagram

屏幕快照 2018-02-25 02.41.58.png

Flowchart

sensor testing flowchart.png

Coding

Reference from:https://kandrproject.blogspot.co.uk/2018/01/arduino-with-fire-sensor-led-and-buzzer.html

屏幕快照 2018-02-25 05.52.26.png

I tried to add a tone for the buzzer. The “tones[] = (525)” means the buzzer will produce sound in 525Hz.

This is a video I’ve done about how it works.

 

Task 2 – How to drive a stepper motor?

屏幕快照 2018-02-24 00.22.38.png

Connect the stepper motor to the UNO board as above.

1321519433984_.pic_hd.jpg

Coding

屏幕快照 2018-02-24 00.45.16.png

This code I’ve done during the tutorial session is for running the stepper motor.

Video:

WEEK 2 – Individual Research – Flame Sensor

How does flame sensor work?

The flame sensor has both outputs, analog and digital. The analog output gives us a real-time voltage output signal on thermal resistance while the digital output allows us to set a threshold via a potentiometer.  We can use the flame sensor to make an alarm when detecting the fire, for safety purpose in many projects and in many more ways.

Flame Sensor Interfacing with Arduino Using Digital Pin

屏幕快照 2018-02-23 19.40.44.png

First, connect the + and the GND pin of the sensor to the +5V and the GND of the Arduino. Then connect the DO pin to the Digital Pin 2 of the Arduino. Next, I connect the led at the pin 12 of the Arduino. When the sensor will detect a flame, then the led will light up.

1311519431300_.pic_hd.jpg

Code for Flame Detection Using Digital Pin

digital pin.png

Flame Sensor Interfacing with Arduino Using Analog Pin

屏幕快照 2018-02-23 19.58.25.png

When using the analog input of the Arduino. The Arduino will read from the sensor and gives us values from 0 to 1023. The only difference is to connect the AO pin to the Analog Input A0 pin on Arduino.

1301519431296_.pic_hd.jpg

Code for Flame Detection Using Analog Pin

analog pin.png

Reference from:

http://microcontrollerslab.com/flame-sensor-arduino-fire-detection/#Code_for_flame_sensor_arduino

WEEK 1 – Individual Research – Flame Sensor

What is flame sensor?

1251519225524_.pic_hd.jpg

The flame sensor is used to detect the fire or other infra red light which are in the range of wavelength from 760nm to 1100nm. The module consists of an IR sensor, potentiometer, OP-Amp circuitry and a LED indicator. When a flame will be detected, the module will turn on its red led. This module is sensitive to flame but it can also detect ordinary light. The detection point is 60 degrees. The sensitivity of this sensor is adjustable and it also has a stable performance.

 

What does flame sensor have?

sensor intro.jpg

A0: This is the analog pin and this will be connected to the analog input of the Arduino.

G: This is the ground pin and this will be connected to the ground of the Arduino.

+: This is the input voltage pin of the sensor and this will be connected to the +5V of Arduino.

D0: This is the digital pin and this will be connected to the digital input of Arduino

Flame Sensor Circuit Diagram

fdsfassa.png

Circuit diagram Source: http://forum.arduino.cc/index.php?topic=394981.0

The flame sensor module has the following features.

  • The operating voltage is from 3.3 – 5V.
  • It gives us both analog and digital output.
  • It has a led indicator, which indicates that whether the flame is detected or not.
  • The threshold value can be changes by rotating the top of potentiometer.
  • Flame detection distance, lighter flame test can be triggered within 0.8m, if the intensity of flame is high, the detection distance will be increased.
  • The detection angle of the flame sensor module is about 60 degrees.Reference From:http://microcontrollerslab.com/flame-sensor-arduino-fire-detection/#Code_for_flame_sensor_arduino