/************************************************************ * Water Atomization Module BM52O5221-1 example code * Arduino IDE version: 1.8.13 * Arduino Board: UNO R3 * Wire Connection: * BM52O5221-1 module pin 1 (GND) connects to POWER GND * BM52O5221-1 module pin 2 (24V) connects to POWER 24V * BM52O5221-1 module pin 3 (DATA_IN) connects to UNO pin 9 * BM52O5221-1 module pin 4 (WATER_DET) connects to UNO pin 8 * BM52O5221-1 module pin 5 (FAN_DRV) connects to FAN * BM52O5221-1 module pin 6 (SW/VR) no connection required * * Created on 2022/02/23 by Best Modules Corp. *************************************************************/ #define DATA_IN 9 #define WATER_DET 8 #define BUTTON 2 volatile boolean i = LOW; void setup() { TCCR1B = TCCR1B & 0xF8 | 5; //PWM Frequency = 30.637 Hz // PWM mode [PIN3:PIN4] = 1,0 pinMode(DATA_IN, OUTPUT); pinMode(WATER_DET, OUTPUT); pinMode(BUTTON, INPUT); digitalWrite(DATA_IN, HIGH); digitalWrite(WATER_DET, LOW); digitalWrite(BUTTON, LOW); } void loop() { attachInterrupt(digitalPinToInterrupt(BUTTON), SetFlag, RISING); if(i==HIGH) analogWrite(DATA_IN, 127); //duty cycle = 50% else analogWrite(DATA_IN, 255); //duty cycle = 100% } void SetFlag() { pinMode(WATER_DET, INPUT); // sets the pin as intput i=!i; }