Your SlideShare is downloading. ×
Session3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Session3

332

Published on

Arduino for Bed

Arduino for Bed

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
332
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Level II
    Programming
    Piezo Sounder Alarm & Sensors
    In What???
    Obviously easiest and fluent Arduino
  • 2. Flash Back of previous session
  • 3.
  • 4. What will you learn Today???
    New methods of Arduino
    Project
    • Project 1: Piezo Sounder Alarm
    • 8. Project 2: Piezo Knock Sensor
    • 9. Project 3: Light Sensor
  • Lets start with methods
    tone () and noTone ()
    tone() command to generate the frequency at the piezo sounder:
    tone(8, toneVal);
    The tone() command requires either two or three parameters, thus:
    tone(pin, frequency)
    tone(pin, frequency, duration)
    The pin is the digital pin being used to output to the piezo and the frequency is the frequency of the tone in hertz. There is also the optional duration parameter in milliseconds for the length of the tone.
    If no duration is specified, the tone will keep on playing until you play a different tone or you use the noTone(pin) command to cease the tone generation on the specified pin.
    analogRead() and analogWrite() was described in last session.
  • 10. Project 1. Piezo Sounder Alarm
    Why use?
    By connecting a piezo sounder to a digital output pin, you can create a wailing alarm sound.
    What is required?
    Piezo Sounder (or piezo disc)
    2-Way Screw Terminal
    Piezo Sounder
    2-Way Screw Terminal
  • 11. How to connect?
    Now you know what has to be included in your code by watching at
    pictorial representation above.
    But can you really code ??? Let’s try
    So you understood what is it that’s remaining…
  • 12. // Project 1 - Piezo Sounder Alarm
    float sinVal;
    inttoneVal;
    void setup() {
    pinMode(8, OUTPUT);
    }
    void loop() {
    for (int x=0; x<180; x++) {
    // convert degrees to radians then obtain sin value
    sinVal = (sin(x*(3.1412/180)));
    // generate a frequency from the sin value
    toneVal= 2000+(int(sinVal*1000));
    tone(8, toneVal);
    delay(2);
    }
    }
  • 13. The sinVal float variable holds the sin value that causes the tone to rise and fall
    The toneValvariable takes the value in sinVal and converts it to the frequency you require.
    You convert the value of x into radians :
    sinVal = (sin(x*(3.1412/180)));
    Then that value is converted into a frequency suitable for the alarm sound:
    toneVal = 2000+(int(sinVal*1000));
    You take 2000 and add the sinVal multiplied by 1000. This supplies a good range of frequencies for the rising and falling tone of the sine wave.
    To make shrill sound and disturb someone who enters your room, I recommend you keep base value 1000 rather than 2000… :p
  • 14. Project 2: Piezo Knock Sensor
    Why use?
    A piezo disc works when an electric current is passed over the ceramic material in the disc, causing it to change shape and hence make a sound (a click). The disc also works in reverse: when the disc is knocked or squeezed, the force on the material causes the generation of an electric current. You can read that current using the Arduino and you are going to do that now by making a Knock Sensor.
    What is required?
    Piezo Sounder (or piezo disc)
    2-Way Screw Terminal
    5mm LED (any color)
    1MΩ Resistor
    Piezo Sounder
    2-Way Screw Terminal
  • 15. //Project 2: Piezo knock sensor
    intledPin = 9;
    int piezoPin = 5;
    int threshold = 120;
    intsensorValue = 0;
    float ledValue = 0;
    void setup() {
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, HIGH); delay(150);
    digitalWrite(ledPin, LOW); delay(150);
    digitalWrite(ledPin, HIGH); delay(150);
    digitalWrite(ledPin, LOW); delay(150);
    }
    void loop() {
    sensorValue = analogRead(piezoPin);
    if (sensorValue >= threshold) {
    ledValue= 255;
    }
    analogWrite(ledPin, int(ledValue) );
    ledValue = ledValue - 0.05;
    if (ledValue <= 0) { ledValue = 0;}
    }
  • 16. Project 3: Light Sensor
    Why use?
    The more light, the lower the resistance. By reading the value from the sensor, you can detect if it is light, dark, or anywhere between. In this project, you use an LDR to detect light and a piezo sounder to give audible feedback of the amount of light detected.
    This setup could be used as an alarm that indicates when a door has been opened, for example. Alternatively, you could use it to create a musical instrument similar to a Theremin.
    What is required?
    Piezo Sounder (or piezo disc)
    2-Way Screw Terminal
    Light Dependent Resistor
    10kΩ Resistor
    Piezo Sounder
    2-Way Screw Terminal
  • 17. How is it connected…
  • 18. Code…
    // Project 14 - Light Sensor
    int piezoPin = 8;
    int ldrPin = 0;
    intldrValue = 0;
    void setup() {
    // nothing to do here
    }
    void loop() {
    ldrValue = analogRead(ldrPin);
    tone(piezoPin,1000);
    delay(25);
    noTone(piezoPin);
    delay(ldrValue);
    }
  • 19. Mechanism: LDR Working
    Vout = Vin * R2/(R2+R1)
    Table 4-1. Vout values for a LDR with 5v as Vin
    R1 R2 (LDR) Vout Brightness
    10kΩ 100kΩ 4.54v Darkest
    10kΩ 73kΩ 4.39v 25%
    10kΩ 45kΩ 4.09v 50%
    10kΩ 28kΩ 3.68v 75%
    10kΩ 10kΩ 2.5v Brightest
    As you can see, as the brightness increases, the voltage at Vout decreases. As a result, the value you read at the sensor gets less and the delay after the beep gets shorter, causing the beeps to occur more frequently. If you were to switch the resistor and LDR, the voltage would increase as more light fell onto the LDR. Either way will work; it just depends how you want your sensor to be read.

×