arduino electronics

Not rated 10,675

Circuit Image

The example circuit and code should be sufficient to begin without delving into additional details. A rotary encoder is an electromechanical component with a shaft that records rotation and converts it into electrical pulses to indicate the direction of rotation. The shaft can rotate continuously through 360 degrees. Detecting changes in the pins indicates that the shaft is rotating, while the frequency of the pulses indicates the speed of rotation. The number of changes indicates how far the shaft has turned. The datasheet for the encoder will provide specific details about the type used, including a pulse diagram illustrating clockwise operation. It is noted that low-cost encoders may produce significant contact bounce, necessitating the debouncing of signals from the encoders. Interrupts on the Arduino will be employed to detect encoder rotation, allowing for easier hardware debouncing and cleaner pulses compared to software delays. A configuration using 47nF ceramic capacitors and Schmitt triggers has been found effective. Additionally, the encoder shield is connected to ground through another 47nF ceramic capacitor. If an encoder has stopping points at both the closed and open positions, it may require two clicks to register a turn. This can be corrected by changing the interrupt type from RISING to CHANGE, triggering an interrupt on every change. The code provided initializes the encoder pins and sets up the interrupt to detect changes in the encoder's position. The motor controlling the door operates by shorting two cables to close a circuit, requiring only a short pulse to start. The door will open if closed and vice versa. If the motor is already moving, the pulse will change its direction. A new solution is desired for increased security and similar range to the previous system, using an ATmega328P with an Arduino core and inexpensive 433MHz ASK modulated RX/TX modules. These RF modules have reliable range and can penetrate various obstacles. They are straightforward to interface with using the VirtualWire library for Arduino. However, they only support unidirectional communication, complicating the implementation of security features such as command obfuscation, as a challenge/response protocol cannot be used due to storage limitations on the Arduino.

The rotary encoder circuit utilizes an electromechanical device that converts mechanical rotation into electrical signals. The encoder typically features two output pins (A and B) that provide quadrature outputs, allowing for the detection of both direction and speed. The encoder's functionality is based on the principle of detecting changes in the output states, which can be processed using an interrupt-driven approach to minimize latency and ensure accurate readings.

In the described application, the encoder is connected to an Arduino microcontroller, specifically the ATmega328P, which is programmed to monitor the state of the encoder pins. The setup function initializes the pins as inputs and configures interrupts to trigger on either the rising edge or on any change, depending on the encoder's characteristics. The loop function continuously outputs the current value of the encoder, providing real-time feedback on its position.

To enhance signal integrity, debouncing techniques are implemented using hardware components. The use of 47nF ceramic capacitors in conjunction with Schmitt triggers helps filter out noise and contact bounce that might occur during rapid rotations. This hardware approach ensures that the signals received from the encoder are clean and reliable, allowing for precise control over the motor that operates the door.

The motor control mechanism is straightforward, relying on a simple circuit closure to initiate movement. A brief pulse sent through the control lines will toggle the motor's state, opening or closing the door as required. The design considers operational safety, ensuring that the motor can reverse direction if it is already in motion when a new command is received.

For wireless communication, the integration of 433MHz ASK modulated RX/TX modules provides a cost-effective solution for remote control operations. The VirtualWire library simplifies the interfacing process, allowing for the transmission and reception of commands over a distance. Despite the limitation of one-way communication, efforts are made to secure the data being transmitted, utilizing methods to obfuscate commands to prevent unauthorized access.

Overall, this schematic integrates various electronic components and programming techniques to create a functional and secure rotary encoder and motor control system, suitable for applications requiring precise positional feedback and wireless control.The example circuit and the code should be enough to get you started if you don`t want to read the other mumbo jumbo. A rotary encoder is electromechanical component with a shaft. Shaft rotation is recorded and converted to electrical pulses that tell in which directionthe shaft is rotating.

The shaft has unlimited 360 degree rotation. If we can detect that the pins are changing we know that the shaft is rotating. How often the pulses change tells us how fast it`s turning. How many times it has changed tells us how far it has been turned etc. Your datasheet will reveal which type you have. There will be a pulse diagram in of the pulses at clockwise operation that looks something like one of the below pictures. The dotted lines indicate shaft stops. Cheap encoders are known to cause a lot of contact bounce so you will need to debounce the signal from the encoders.

We will use interrupts on the Arduino for detecting encoder rotation so it`s easier to debounce the encoder with hardware and get nice clean pulses than to try and debounce using software delay. I have tried some variants and settled with 47nF ceramic capacitors and Schmitt Triggers on the outputs.

I have also connected the shield on my encoders to ground through another 47nF ceramic capacitor. If you have an encoder that stops at both closed and open you will have to turn your encoder two clicks to register a turn. Correct this by changing the interrupt type from RISING to CHANGE sol that an interrupt is triggered on every change.

int pinA = 2; //Encoder pin A connects to interrupt 0 (D2) int pinB = 4; //Encoder pin B connects to D4 int iValue = 0; //A variable that will be increased or decreased //when we turn the encoder void setup() { Serial. begin(9600); pinMode(pinA, INPUT); pinMode(pinB, INPUT); // Enable interrupt on encoder pin A // Trigger at RISING if your encoder stops (clicks) only at high pulse // Trigger at CHANGE if your encoder stops (clicks) at both high and low // positions or if it has no stops attachInterrupt(0, encoderClick, RISING); } void loop() { // continuously print the value to see how it changes Serial.

println(iValue); delay(200); } void encoderClick(){ // encoder must have turned one click because interrupt 0 was triggered // read value from both encoder pins int valA = digitalRead(pinA); int valB = digitalRead(pinB); // compare pins to determine in which direction encoder was turned if (valA != valB){ // pinA just changed but pinB had not yet changed // Direction must be clockwise if A changes before B iValue+; } else{ // pinA just changed and pinB had already done so. // Direction must be counter-clockwise if B changes before A iValue-; } } The motor to the door is controlled by shorting two cables and thereby closing a circuit.

A short pulse is enough to start the motor. If the door is closed it will open. If it`s already open, the door will close. If the motor is moving when the pulse arrives it will change direction. I wanted a new solution that would be a bit more secure and hopefully have the same range as the old one had and I wanted to base it onan ATmega328P with an Arduino core and some really cheap 433Mhz ASK modulated RX/TX modules that can be found everywhere on eBay. I have used these RF modules before and know they have a decent range and can penetrate doors, windows and even walls in some cases.

They are also easy to interface with using the VirtualWire library for Arduino. The downside is that they only work in one direction. Even if it wasn`t really necessary in this case I wanted to implement some kind of security or obfuscation of the commands sent over the air. This is something of a challenge with a system that only communicates in one direction since it`s not possible to use a challenge/response based protocol and the Arduino doesn`t have storage enough to store predefined

🔗 External reference




Warning: include(partials/cookie-banner.php): Failed to open stream: Permission denied in /var/www/html/nextgr/view-circuit.php on line 713

Warning: include(): Failed opening 'partials/cookie-banner.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/nextgr/view-circuit.php on line 713