Hi and thank you in advance, nubie here that has so far managed to cobble this together.
I've been whittling away at an agricultural project to count the number of hay bales and flakes per bale going through my small square hay baler, this has been a 3 year on and mainly off project
I have it working, using buttons, to the point where it works with the short leads on the desktop (all but the reset which seems to work in the simulator), but the minute I extend those leads to the 3 meter requirements to reach the baler, it starts playing up and counting itself at times, Iam using shielded (ex cable from a rear view camera) cable, but even if you wave your hands around the Arduino it sometimes adds to the counts.
Q1: would a resistor before the input pin help alleviate these false inputs or is there a way to code it?
end of issue one.
The next progression to move the project off the bench and onto the baler, I wanted to utilize an LJ8A3-2-Z/BY (6-36V) inductive sensor to provide a pulse (on the tinker cad it is replacing the left two buttons) sending a 12v signal back to the control box, which I then have to reduce to the 5v for the pin ins.
I im using an existing bolt on the plunger crank arm to trigger the flake count and the pin that counts the bales mechanically.
on the picture, left button is bale trigger (pink), middle is flake (purple) and right is reset (tan).
Q2: I am basically out of my depth with electronics learning on the fly.
I was thinking of using 12v to the sensor and returning to the enclosure in the cabin, then using the LM7805 regulator to bring it back to 5v for the input pin. see attached, but will the 5v out create a readable pulse without a -ve back into that circuit.
// C++ code
//
#include <Adafruit_LiquidCrystal.h>
int seconds = 0;
Adafruit_LiquidCrystal lcd_1(0);
//copy from here
int BaleCount= 0;
int PrevFlakeCount= 0;
int FlakeCount= 0;
int LastFlakeCount= 0;
int Bale_Pin= 2;
int Flake_Pin= 4;
int Reset_Pin= 7;
int Light_Pin= 6;
void setup()
{
lcd_1.begin(16, 2);
lcd_1.setBacklight(1);
lcd_1.setCursor(0, 0);
lcd_1.print("Bales :");
lcd_1.setCursor(10, 0);
lcd_1.print(BaleCount);
lcd_1.setCursor(0, 1);
lcd_1.print("Fl:");
lcd_1.setCursor(5, 1);
lcd_1.print(FlakeCount);
lcd_1.setCursor(10, 1);
lcd_1.print("La:");
lcd_1.setCursor(14 , 1);
lcd_1.print(LastFlakeCount);
pinMode(Bale_Pin, INPUT);
pinMode(Flake_Pin, INPUT);
pinMode(Reset_Pin, INPUT);
pinMode(Light_Pin, OUTPUT);
}
void loop()
{
//Print onto LCD
{
lcd_1.setCursor(10, 0);
lcd_1.print(BaleCount);
lcd_1.setCursor(5, 1);
lcd_1.print(FlakeCount);
}
//Reset Bales
if (digitalRead(Reset_Pin) ==HIGH)
{
BaleCount=0;
FlakeCount=0;
PrevFlakeCount=0;
}
//bale count
else if (digitalRead(Bale_Pin) == HIGH)
{
BaleCount++;
FlakeCount=0;
lcd_1.setCursor(5, 1);
lcd_1.print(" ");
lcd_1.setCursor(14 , 1);
lcd_1.print(" ");
lcd_1.setCursor(14 , 1);
lcd_1.print(PrevFlakeCount);
PrevFlakeCount=0;
}
//Flake count
else if (digitalRead(Flake_Pin)== HIGH)
{
FlakeCount++;
PrevFlakeCount++;
}
}