Conveyor Belt - people counter - counting

I have setup a pi with a grovepi board. I want to use the ultrasonic sensor to count products. The standard value that comes off it is around 500. When a product passes it drops to around 20.

I want to make a counter that increments with 1 every time the sensor payload drops below 500.

How do I program this?

If value less than 30 add one to counter

That is also possible, but how do I script this?

Use a switch node for the if and you could use node-red-contrib-mycounter to count

2 Likes

Thank you so MUCH!!!

But now I need it to only count the next value if its back above 450. if a product gets stuck it should not keep counting. Any suggestions?

Search for Hysteresis on the node red flows site.

Can we let the swith pick up ?

var gelezen=context.get('gelezen') || 499;
if(msg.payload<450 && gelezen > 450)
{
context.set("waarde",1);
node.warn("1")

}else{
context.set("waarde",0);
node.warn("0")
}
context.set('gelezen',msg.payload);

return msg;

Solution

var gelezen=context.get('gelezen') || 499;
if(msg.payload<50 && gelezen > 450)
{
context.set('gelezen',msg.payload);
msg.payload = 1

}else{
context.set('gelezen',msg.payload);
msg.payload = 0

}

return msg;

1 Like