How to get IR sensor alerts (NOOB HERE)

Hello!

So I have IR sensor, which reads distance, and now I wish to put alerts in the code. I have tried several things, googled this for last couple of days. Had many ups and downs...but now I just have no more idea. What I wnat to have is set alerts on several diatances, so that I know how far the object is. Something like parking sensor. Can someone please help me with the code? I am loosing my mind!!

Tell us more and we might help you out. :slight_smile:

As a start, how are things wired up?
List of parts?
What have you got so far in your program? (post using code tags).
What increments do you need to measure?
How many increments do you need to measure?

See how difficult it is without knowing the above? :confused:

Hi,

I have posted the code, but its waiting to be approved (attachement). I have Arduino Uno, IR sensor connected to my laptop. For now its set to read centimeters, and it shows a diagram with scale.

What I want to do is, to set green, yellow, orange and red areas with alerts, using if conditions.

I hope my attachement get approved asap, so that we can discuss on actual code.

For now, I thank you for your fast reply!

So, here is my code. If anyone can help me with this I would be really thankfull!! I hope that the part which is bold is the proper part of setting the alert and if conditions...

var http = require("http").createServer(handler); // on req - hand
var io = require("socket.io").listen(http); // socket library
var fs = require("fs"); // variable for file system for providing html
var firmata = require("firmata");

console.log("Starting the code");

var board = new firmata.Board("/dev/ttyACM0", function(){
console.log("Connecting to Arduino");
board.pinMode(0, board.MODES.ANALOG); // enable analog pin 0
});

function handler(req, res) {
fs.readFile(__dirname + "/primer07.html",
function (err, data) {
if (err) {
res.writeHead(500, {"Content-Type": "text/plain"});
return res.end("Error loading html page.");
}
res.writeHead(200);
res.end(data);
})
}

var vrednostIzSenzorja = 0; // desired value var

http.listen(8080); // server will listen on port 8080

var sendValueViaSocket = function(){}; // var for sending messages

board.on("ready", function(){

board.analogRead(0, function(value){
** vrednostIzSenzorja = value; // continuous read of analog pin 0**
** var txt = function)();**
** if (vrednostIzSenzorja > 40)**
** txt ("Critical height");**
});

io.sockets.on("connection", function(socket) {
socket.emit("messageToClient", "Srv connected, board OK");

setInterval(sendValues, 40, socket); // on 40ms trigerr func. sendValues

}); // end of sockets.on connection

}); // end of board.on ready

function sendValues (socket) {
socket.emit("clientReadValues",
{
"vrednostIzSenzorja": vrednostIzSenzorja
});

}