Hi everyone, I have a dilemma, I have a project with a rotating wheel with 3 hall effect sensors positioned 120 degrees apart (duinotech XC-443) with a magnet positioned on the wheel.
I have a mega 2560 board to process the inputs to send an output signal to a relay block ( Songle SRD-12VDC-SL-C ) which powers 3 solenoids.
The problem I have is the person who help with the coding is no longer with us.
I'm 40 years in the automotive industry and although I understand all the components and wiring and workings, I sadly don't know how to write code let alone understand some of it.
I have inadvertently wiped the original basic program and have discovered it was never saved anywhere else.
We have tried to to do a new sketch to no avail, if someone could assist it would be greatly appreciated.
I have made a detailed wiring diagram with components and have a sketch I can provide.
Kind regards Pat
Please do so. Also, please provide a good description of what the application is supposed to do.
With that, people might be able to help.
You can drag an image file into a reply window to show us the wiring diagram.
Please use code tags when posting code; the easiest is probably to use edit -> copy for forum* and next past it an a (the) reply.
PS
Please provide a link to the relay / relay module that you are using.
Also can you tell us what sort of speed these magnets are rotating at. If it is too fast it is likely that the relays will not be able to respond fast enough.
You will need to read the Hall effect sensors. Then Determine the position of the wheel based on which sensor is activated. Use the wheel position to decide which solenoid to trigger. Send output signals to the relay to control the solenoids.
Do you need to change the program, or just replicate it?
If the Mega2560 with the program is working, you can't get the source code from it, but it is possible to make copies of the executable code to program other Mega2560s.
Otherwise, if you need to make changes, then the best approach is indeed your wiring diagram and a detailed explanation of how it should all function.
Thank you for your response. This was working ok, but I think it could be improved i.e. pin 21 may not be in the right input.
It would be doing maybe 100rpm and its simple water feature.
This was our attempt a writing the code.
Kind regards Pat
// Identifying internal components and declaring as variables
//////////////////////////////////////////////////////////////
// Identify Input/Output Pins
const int firstHall=2; // select the input pin (sensor input)
const int firstCoil=5;// select pin for relay (relay output)
const int secondHall=3; // select the input pin (sensor input)
const int secondCoil=6; // select pin for relay (relay output)
const int thirdHall=21; // select the input pin (sensor input)
const int thirdCoil=7; // select pin for relay (relay output)
// Local Vairbales for execution
int hallState01 = 0; // Working variables for detecting Hall Effect Status
int hallState02 = 0;
int hallState03 = 0;
bool coilActive = false; // Stops loop from performing simultanious powering when Hall Effect is detected
int timingManager = 200; // The timing adjustment
// void setup - first function to initialize variables and start loop function
//////////////////////
void setup() {
// Identifying
pinMode (firstHall, INPUT);
pinMode (secondHall, INPUT);
pinMode (thirdHall, INPUT);
pinMode (firstCoil, OUTPUT);
pinMode (secondCoil, OUTPUT);
pinMode (thirdCoil, OUTPUT);
Serial.begin (9600);
}
// Continuous action chain to detect Hall Effects and engage coils.
void loop() {
// Check status of Hall Effects.
hallState01 = digitalRead (firstHall);
hallState02 = digitalRead (secondHall);
hallState03 = digitalRead (thirdHall);
// elseIf status for which Hall Effect
if (hallState01 == HIGH && !coilActive) { // Checks if Hall Effect is triggered and if there is no other coils active
Serial.println ('The first Hall Effect has been triggered');
coilActive = true; // local boolean set to true
digitalWrite (firstCoil, HIGH); // power coil
delay(timingManager); // delay by timing
digitalWrite (firstCoil, LOW); // power off coil
coilActive = false; // local boolean set to false
} else if (hallState02 == HIGH && !coilActive) {
Serial.println ('The second Hall Effect has been triggered');
coilActive = true;
digitalWrite (secondCoil, HIGH);
delay(timingManager);
digitalWrite (secondCoil, LOW);
} else if (hallState03 == HIGH && !coilActive) {
Serial.println ('The third Hall Effect has been triggered');
coilActive = true;
digitalWrite (thirdCoil, HIGH);
delay(timingManager);
digitalWrite (thirdCoil, LOW);
} else {
Serial.println ('A coil is active');
}
}
HI, @pjg7061
This link will tell you how to post code in a scrolling window.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Tom...
You are putting 12V on a 5V relay module. You should have kickback suppression diodes across the valve coils.
Hi, @pjg7061
Check you relay assembly, for the relay operating voltage.
As @JCA34F has pointed out you have 12V to the assembly yet the assembly in your image has 5V coil voltage written on it.
What is the part number of the hall effect module?
Tom..
// Identifying internal components and declaring as variables
//////////////////////////////////////////////////////////////
// Identify Input/Output Pins
const int firstHall=2; // select the input pin (sensor input)
const int firstCoil=5;// select pin for relay (relay output)
const int secondHall=3; // select the input pin (sensor input)
const int secondCoil=6; // select pin for relay (relay output)
const int thirdHall=21; // select the input pin (sensor input)
const int thirdCoil=7; // select pin for relay (relay output)
// Local Vairbales for execution
int hallState01 = 0; // Working variables for detecting Hall Effect Status
int hallState02 = 0;
int hallState03 = 0;
bool coilActive = false; // Stops loop from performing simultanious powering when Hall Effect is detected
int timingManager = 200; // The timing adjustment
// void setup - first function to initialize variables and start loop function
//////////////////////
void setup() {
// Identifying
pinMode (firstHall, INPUT);
pinMode (secondHall, INPUT);
pinMode (thirdHall, INPUT);
pinMode (firstCoil, OUTPUT);
pinMode (secondCoil, OUTPUT);
pinMode (thirdCoil, OUTPUT);
Serial.begin (9600);
}
// Continuous action chain to detect Hall Effects and engage coils.
void loop() {
// Check status of Hall Effects.
hallState01 = digitalRead (firstHall);
hallState02 = digitalRead (secondHall);
hallState03 = digitalRead (thirdHall);
// elseIf status for which Hall Effect
if (hallState01 == HIGH && !coilActive) { // Checks if Hall Effect is triggered and if there is no other coils active
Serial.println ('The first Hall Effect has been triggered');
coilActive = true; // local boolean set to true
digitalWrite (firstCoil, HIGH); // power coil
delay(timingManager); // delay by timing
digitalWrite (firstCoil, LOW); // power off coil
coilActive = false; // local boolean set to false
} else if (hallState02 == HIGH && !coilActive) {
Serial.println ('The second Hall Effect has been triggered');
coilActive = true;
digitalWrite (secondCoil, HIGH);
delay(timingManager);
digitalWrite (secondCoil, LOW);
} else if (hallState03 == HIGH && !coilActive) {
Serial.println ('The third Hall Effect has been triggered');
coilActive = true;
digitalWrite (thirdCoil, HIGH);
delay(timingManager);
digitalWrite (thirdCoil, LOW);
} else {
Serial.println ('A coil is active');
}
}
- Where is your schematic ?
hi everyone.
Sorry I've been away.
In the current wiring configuration this did run, however I did suspect we were getting back EMFs causing the relays to get confused. will fit the diodes and try.
the problem is we don't have the sketch anymore and the person who wrote it is no longer available (ex Naval electronics engineer).
As you can see this is what we have started to write as supplied and not right of course.
the relays are 12v and use the 5v from the 2560 mega to switch.
So what we have is 3 hall effects (digital) to the Mega 2560 and an output to switch the relays and to be able to change the output signal (duty cycle) to increase/decrease the duration as required.
Probably simple to you guys but i haven't been trained in writing code.
kind regards Pat
What is turning the wheel and how fast?
just an electric motor and about 80rpm. Thanks
Does the motor and wheel do anything else besides being a trigger for the valves?
According to the datasheet,
XC-443 datasheet
The output signal goes LOW when a magnet is sensed so, this:
if (hallState01 == HIGH && !coilActive)
Should be:
if (hallState01 == LOW && !coilActive)
its only to trigger the halls.
I'll try that, thanks.
Then why not use the Arduino for RPM timing?
Ok, thanks.
Could that be the reason the number 3 hall is connected to SLC pin 21?