Positive switch, low 1.5ms is closed, higher than 1.5ms is open.
I've understood this as I need: " I need to generate 50% + duty cycle, in order to trigger this switch", but unfortunately I'm new to electronics and I might be wrong, since this code is not working:
#include <Arduino.h>
#define IO_READ 2
#define VALVE_PIN 3
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
int ioState;
void setup() {
Serial.begin(9600);
pinMode(IO_READ, INPUT);
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(VALVE_PIN, ledChannel);
}
void loop() {
unsigned long duration = pulseIn(IO_READ, HIGH);
Serial.println(duration);
if (duration > 2000) {
Serial.println("OPEN");
ledcWrite(VALVE_PIN, 255); // 100%
delay(1000);
}
}
I see button press in terminal as it should be, but valve is not opening at all. I've checked wiring it's fully matches wiring scheme for both ins and outs, switch is powered on. I'd be very grateful if somebody could help me with this.
I doubt it. I think this specification was just oddly formulated/translated from Chinese and the actual specification is "<1.5V input signal = switch open, >1.5V is switch closed". The item descriptions on AliExpress often require a massive dose of guesswork and imagination to interpret.
Either way, it's easy enough to test. I'd start by hooking something up to the switch (a LED indicator etc.) and then just applying 3.3V to the signal input manually, using a piece of wire. See if it switches. I bet it's just an ordinary "active high" input that you can control with a simple "digitalWrite(VALVE_PIN, HIGH)".
This is what I did. Used just "digitalWrite(VALVE_PIN, HIGH)". It did not work, so I switched to PWM control via duty-cycle, it doesn't work either, so I thought that I'm doing something wrong.
Prior to trying PWM I had digitalWrite(VALVE_PIN, HIGH) and pinMode(VALVE_PIN, Output), white cable I'm about to show was soldered to pin 20. Now I've removed pinMode to work with PWM, and soldered white cable to pin 3.
Are you sure bout that ? Product naming says PWM, I see PWM label near white cable pad, description says "Control Signal:PWM" not sure how it can be "not pwm"
This is what I'll try. If it's not hard for you can you please copy paste Arduino library part mention from seller's statement? I really can't find it, so I'll atleast save it to my notes to know this next time I'll buy this switch. Thanks in advance
This sketch will turn the switch on for 1 second then off for 1 second
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{
// Attaches the servo on pin 9 to the servo object
myservo.attach(9);
}
void loop()
{
myservo.write(0); // Turn switch OFF
delay(1000);
myservo.write(180); // Turn switch ON
delay(1000);
}
#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{
// Attaches the servo on pin 9 to the servo object
myservo.attach(9);
}
void loop()
{
myservo.write(0); // Turn switch OFF
delay(1000);
myservo.write(180); // Turn switch ON
delay(1000);
}
For whatever reason it's not working. I've soldered white cable to esp32 c3 pin9
That's OK, there are no markings on the chip. I was hoping that @jim-p would respond since he's sure on how the switch needs to be controlled, so he might know what the nature of the little controller on that board is.
Input voltage is I believe what it can pass through onto output. Nevertheless I've soldered vIn, to 5V voltage source and it's still not working. Maybe in case of esp32 c3 supremini we need a different pin for servo control ?
It's unclear from the website whether it will work with a 3.3V control signal on the white wire.
However since you already have the switch it was worth a try.
So apparently it does not work 3.3V
Just to check did you have the thin black wire connected to the Mini GND?