I've got some code which uses an arduino to control a relay (12v motor) based on a float switch position. It is essentially "standalone" right now and works fine. I've copied the code below.
I'd like to convert it to be of use via mySensors so that it can report its activity to the gateway but continues to act independently.
I've tried to take the example mySensor code for a relay actuator, and inserted what I thought to be the relevant sections for presenting itself to the gw (and removed the parts on receiving commands) - and while the code compiles and loads - the unit does not function.
I've wired up the radio - but not got a gw or controller turned on at the moment - but I was expecting the unit to operate regardless.
Is this possible? If so can someone point me in the right direction please. Many thanks
/***********************************************************************************
* Rollermat control
*
*
* Wiring
* Pin 3 - Float Switch
* Pin 4 - Relay to 12v motor
* Pin 7 - Green LED
* Pin 8 - Red LED
*
* Control Behavior:
* If the float switch is floating (i.e. rollermat is clogged) then turn on the pump and green led
* If the float switch is not floating (i.e. rollermat is clean) turn off the pump and green LED and turn on the red LED
*
**********************************************************************************
*/
//define the input/output pins
#define FLOAT_SWITCH_PIN 3
#define MOTOR_1_PIN 4
#define LED_PIN 7
#define LED_RED 8
#define CHILD_ID 1 // Id of the sensor child
//setup runs once
void setup()
{
//setup input pins for float switch
pinMode(FLOAT_SWITCH_PIN, INPUT);
//setup output pins for relay and LED board
pinMode(MOTOR_1_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(LED_RED, OUTPUT);
}
//loop() runs indefinitely
void loop()
{
// LOW corresponds to the float switch being at its highest point (i.e. rollermat is clogged)
if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
{
digitalWrite(MOTOR_1_PIN, HIGH); //turn on the motor
digitalWrite(LED_PIN, LOW); //turn on the Green LED
digitalWrite(LED_RED, HIGH); //turn of the Red LED
}
//otherwise the float switch is HIGH
// HIGH corresponds to the float switch being at its lowest point (i.e. rollermat is clean and water is flowing)
else
{
digitalWrite(MOTOR_1_PIN, LOW); //turn off the pump
digitalWrite(LED_PIN, HIGH); //turn off the Green LED
digitalWrite(LED_RED, LOW); //turn on the Red LED
}
}```