Read Temperature and Control a Buzzer
Overview
In this tutorial you will learn how to measure temperature and control a simple buzzer alarm circuit, access Cloud9 (the BeagleBone's coding interface), load and run a script. This project introduces the analog read function to measure a temperature sensor, and presents a typical control application.Note: This tutorial uses a BeagleBone set up specifically for our BeagleBone Black Tinkerer Workshop. The BeagleBone Black you will use in the Tinkerer Workshop will be set up with a Display and a Keyboard with a trackball mouse, and the JavaScript Files will be saved to the board. The BeagleBone will be running Angstrom, which come pre-loaded when you get the board. If you are not in a Tinkerer Workshop and want to do these projects, you can find a guide on how to attach a keyboard with a trackball mouse and a display here. You will also need to add the JavaScript files, which can be found here, to the following directory on the BeagleBone Black: /var/lib/cloud9/workshop
Parts List
- 1x BeagleBone Black Board
- 1x Medium Breadboard
- 1x Jumper Wire Pack for Breadboards
- 1x Push-button switch (Available in the Prototyping Parts Kit)
- 1x Electromagnetic buzzer (12mm "beeping" type, 30mA @ 5VDC, 2.3KHz +- 300hz )
- 1x Transistor, N-Channel Mosfet 2N7000 (Available in the Prototyping Parts Kit)
- 2x LEDs (Red, Green) (Available in the Prototyping Parts Kit)
- 1x LED (Yellow) can use RGY multicolor LED in Prototyping Parts Kit
- 4x 330 Ohm Resistor (Also available in the Prototyping Parts Kit)
- 1x 1000 Ohms Resistor (can use 3 x 330 in series from Prototyping Parts Kit)
- 1x Thermistor Temperature Sensor type: 103AT
- 1x 10K Ohms Resistor
Wiring Diagram
Step 1
Wire the components as shown. Note the orientation of the Transistor (3-leads) E-B-CNote: The face of the transistor is flat.
Step 2
Plug the DC power jack into the BeagleBone Black to power the device.Step 3
Once the system is ready, click on BEAGLEBONE-workshop icon to open the Chromium browser and then start the Cloud9 IDE BeagleBone.local:3000 (192.168.7.2:3000)Step 4
In the Cloud9 workshop folder click on the file Project5.js to open the BoneScript program that will control the LED and make it blink.The code should look like this:
var b = require('bonescript'); var analogPin = "P9_36"; var buzzerPin = "P8_13"; var ledRed = "P9_14"; var ledGreen = "P8_19"; var ledYellow = "P9_16"; var volume = "0.2"; var value = 0; // configure pins b.pinMode(buzzerPin, b.OUTPUT); b.pinMode(ledRed, b.OUTPUT); b.pinMode(ledGreen, b.OUTPUT); b.pinMode(ledYellow, b.OUTPUT); setInterval (inputHandler, 500); function inputHandler() { // read thermistor value value = b.analogRead(analogPin); value = Math.round(((value*10)-4.5)*4000); if (value < 100) value = 100; console.log (value); } loop(); //beep at interval of thermistor value function loop() { b.analogWrite(buzzerPin, volume); setTimeout(function(){b.analogWrite(buzzerPin, b.LOW);}, 50); setTimeout(loop, value); if (value > 1000) b.digitalWrite(ledGreen,b.HIGH); else b.digitalWrite(ledGreen,b.LOW); if (value > 200 && value < 1000) b.digitalWrite(ledYellow,b.HIGH); else b.digitalWrite(ledYellow,b.LOW); if (value < 200) b.digitalWrite(ledRed,b.HIGH); b.digitalWrite(ledRed,b.LOW); }
Step 5
Now press Run at the top of the Cloud9 interface. If this says "Debug", select "Run" from the drop down under this button.The script should now run. You can make the buzzer sound by warming the thermistor up by pinching it between your fingers.