Professional Documents
Culture Documents
Lab - 12 Hardware Integration With Raspberrypi: Team Members
Lab - 12 Hardware Integration With Raspberrypi: Team Members
Lab - 12 Hardware Integration With Raspberrypi: Team Members
Team Members: -
1. Tom Jose Oorasala -19BLC1058
2. Ritesh Kumar Shukla -19BLC1076
Aim
Our aim is to perform hardware integration program using Raspberry PI.
Programs: -
1. Blinking LED using Raspberry PI
Procedure:
Code: -
var onoff = require('onoff');
var Gpio=onoff.Gpio,led=new Gpio(6,'out'),interval;
interval = setInterval(function(){
var value=(led.readSync() +1)%2;
led.write(value,function(){
console.log("changed LED state to :"+value);
});
},2000);
process.on('SIGINT',function(){
clearInterval(interval);
led.writeSync(0);
led.unexport();
console.log('bye bye');
process.exit();
});
Output: -
Program 2:-PIR Sensor using Raspberry pi
Procedure:
Code: -
var Gpio = require('onoff').Gpio,
sensor = new Gpio(17, 'in', 'both');
sensor.watch(function (err, value) {
if (err) exit(err);
console.log(value ? 'there is some one!' : 'not anymore!');
});
function exit(err) {
if (err) console.log('An error occurred: ' + err);
sensor.unexport();
console.log('Bye, bye!')
process.exit();
}
process.on('SIGINT', exit);
Output
Program 3 : Blink Led when Person is detected
Procedure:
Code
var Gpio = require('onoff').Gpio,
sensor = new Gpio(17, 'in', 'both');
led=new Gpio(6,'out'),interval;
sensor.watch(function (err, value) {
if (err) exit(err);
if(value){
led.write(1,function(){
console.log("changed LED state to :"+value);
});
}
else{
led.write(2,function(){
console.log("changed LED state to :"+value);
});
}
});
function exit(err) {
if (err) console.log('An error occurred: ' + err);
sensor.unexport();
console.log('Bye, bye!')
process.exit();
}
process.on('SIGINT', exit);
Program 4 : Working with DHT sensor
Procedure:
Code:
var sensorLib = require('node-dht-sensor');
sensorLib.initialize(22, 12);
var interval = setInterval(function () {
read(); }, 2000);
function read() {
var readout = sensorLib.read();
console.log('Temperature: ' +
readout.temperature.toFixed(2) + 'C, ' +
'humidity: ' + readout.humidity.toFixed(2) + '%');