Control AC Light with Hand Gesture (Python - OpenCV - MediaPipe and Arduino)
Upload Dimmer.ino to Arduino
Install Dependencies
pip3 install opencv-python
pip3 install mediapipe
pip3 install pyserial
Run and Enjoy
python3 dimmer.py
In alternating current, the zero-crossing is the instantaneous point at which there is no voltage present. In a sine wave or other simple waveform, this normally occurs twice during each cycle. It is a device for detecting the point where the voltage crosses zero in either direction.
The zero-crossing is important for systems that send digital data over AC circuits, such as modems, X10 home automation control systems, and Digital Command Control type systems for Lionel and other AC model trains.
https://en.wikipedia.org/wiki/Zero_crossing
Signal frequency > 50hz
Fully rectified signal frequency > 100hz
T=1/F -> T=1/100 -> T=0.01 Second -> T=10ms
With the code below, we add a function that is triggered every 10ms
attachInterrupt(digitalPinToInterrupt(ZERO_CROSS_PIN), zeroCrossInterrupt, RISING);
void zeroCrossInterrupt()
{
delayMicroseconds(dimLevel*75);
digitalWrite(DIM_PIN, LOW); //Turn On Triac
delayMicroseconds(10);
digitalWrite(DIM_PIN, HIGH); //Turn Off Triac
}
Copyright 2022 bilkeonur
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.