Turn on dust collector when using table saw

Could please help me with this?
I am trying to get my dust collector to turn on when I use my table saw etc using current sensor and an Arduino powered 5v relay.

below is my problematic code:

// Dust collector, turns on my dust collector when I use a power tool in my shop.
int analogPin=0; // Pin of current sensor
int relayPin=0; // Pin of Relay Module

void setup() {
// Serial.begin(9600);
pinMode(relayPin , OUTPUT); // Set Pin connected to Relay as an OUTPUT
analogWrite(relayPin , LOW); // Set Pin to LOW to turn Relay OFF


void loop() {
// while (analoglRead(analogPin == HIGH) { // If current detected
analogWrite(relayPin, HIGH); // Turn Relay ON

Serial.println(“Relay is ON”);


analogPin, LOW); // Turn Relay OFF
Serial.println(“Relay is OFF”);

Right off I see two serious issues.

analogWrite is not the way to control a digital pin. Please read through the reference section at Arduino Reference - Arduino Reference to see how to use the digital and analog read write commands.

After you have read the analogRead you will see the while statement is also incorrect.

Once you have read through the following:




then try changing your program based on what you have learned and repost if you still have an issue.

Thank you.

A single toggle switch, to turn on, or off, a relay controlling power to the table saw and to turn on, or off, a relay controlling power to the dust collector, makes more sense to me.

No microcontroller to get dirty, no need to deal with voltage spikes when the power is turned on or off, and no need to write any code.