Тёмный

How to setup a Rotary Switch with 1 Input 

Scotty D
Подписаться 14 тыс.
Просмотров 15 тыс.
50% 1

Struggling with a shortage of digital pins on your Arduino board? In this video, I've got you covered! Learn how to connect a rotary switch without depleting all your digital pins by employing just one analog pin.
🤔 Why Go Analog?
Traditional methods of connecting rotary switches demand multiple digital input pins, potentially exhausting your Arduino's available resources. Discover a smarter approach that conserves pins while efficiently managing your project's needs.
🔧 Applicable to Various Microcontrollers
This technique isn't exclusive to Arduino; it's compatible with a range of microcontrollers like Raspberry Pi, ESP32, and ESP8266, provided an analog pin is available.
📁 Get the Code
Access the code I used in this demonstration via GitHub: github.com/5cottyD/Projects/t...
🔗 Purchase Links from AliExpress here
ARDUINO UNO R3 CLONE: s.click.aliexpress.com/e/_DDV...
ARDUINO MICRO CLONE: s.click.aliexpress.com/e/_De4...
ROTARY SWITCH VARIOUS POLES: s.click.aliexpress.com/e/_DEE...
⏱️⏱️VIDEO CHAPTERS⏱️⏱️
------------------------------------------------
0:00 Intro
0:07 Digital pin method Wiring diagram
1:30 Analog pin method Wiring diagram
3:06 Resistor value selection
4:17 Breadboard Example
7:18 Arduino analogRead input range from 0 to 1023
8:07 Rotary switch setup / wiring / soldering
9:45 Wiring diagram vs Rotary switch setup
10:00 Coding example for reading input only and Serial monitor output/results
11:30 Readings are never exact and fluctuate
12:04 Coding example for reading input and assigning pin number and Serial monitor output/results
14:04 Adjusting Switch number to analog value
14:33 Rotary switch end product
15:03 Project example with minimum pin usage
📺 Explore more electronics tutorials in this playlist:
• Electronics & Projects
🔔 Subscribe to the channel and hit the notification bell to stay updated with the latest Electronics videos and tutorials!
/ @scottydiy
🔗 Check out Josephine's channel for her content: / @josephine5766
🔖 Tags: #arduino #arduinoproject #rotartyswitch

Наука

Опубликовано:

 

13 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 22   
@kinnikunky
@kinnikunky 2 года назад
Thanks Scotty! This was super useful. If anyone is looking for a more elegant way to select a 'rotswitchNumber' you can do all of that with one line: rotswitchNumber= map(sensorValue, 0, 1023, 1, 8); (with the last number being the number of switch positions your rotary switch has). No need for the big if/then statement so long as the sensor values are evenly spread. Cheers :D
@fredmethot6116
@fredmethot6116 4 месяца назад
I almost gave up on this until tonight... I'm using a modded version of that same switch that allows for infinite rotation... however when the rotary was moved between the 2 pins that aren't bridged together by a resistor (PIN 14 from this video's schematic), it was shorting 3v3 and GND and would reset the board (which is not convenient when workiing on an ESP32 WROOM losing BT connection) . Finally resolved the issue by adding a diode in series between 3v3 and the switch PIN connecting to 3v3... BINGO! No more shorts, perfect stable reading @ +/-3.
@mikey38632
@mikey38632 8 месяцев назад
Awesome video, it's going to be very helpful. I'm learning to code C++ with an interest in MCUs, and my first dev board is on its way. If I'm able to realize my vision down the road, quite a few GPIO will be needed, so this sort of advice is key to success. Thanks again!
@pi.actual
@pi.actual 10 месяцев назад
A tip: soldering the resistors on looked to be difficult and tedious as shown. I would suggest a single wrap of each resistor lead around the pin which will hold them in place then solder all in one go and trim the ends of the leads when done.
@hralvesoctopi3504
@hralvesoctopi3504 Год назад
Muito obrigado por este video! Foi muito importante para um trabalho! Grato, Helder Alves, Portugal
@Roadstercycle
@Roadstercycle 2 года назад
Hi Scotty, Loved your video. You gave me the basics on controlling my Mustang/Tesla conversion steering wheel buttons. They are a 2 wire setup with resistors that send signals to the onboard computer. I am wanting to change them to use as Park, Reverse, Neutral and drive. So I watched and setup what you did and got my 0-5 switch numbers but now I'm confused as to to implement then in the arduino to use as momentary switches. Any chance you could do a follow up on using the rotary switch to control on and off leds using the switch numbers generated and how to set them up to use as switched to control a relay or Mosfet?
@Linrox
@Linrox 2 года назад
Love the video thanks. It will help with my current project. Looking at the number bouncing around, i think a debouncer might help stabilize the number. Could be wrong.
@leondcarpenter
@leondcarpenter 2 года назад
Awesome idea and great video. Totally new to Arduinos but am looking to control programable LEDs using the switch to drive different patterns as my first project. In tinkercad, I've mocked up your switch idea and have also loaded the neopixel template as well. If I wanted to combine the two setups (to eliminate the neo Arduino), where do I connect the power and ground for the LEDs? My guess is that the switch and the LEDs are 2 separate operations and the LEDs can connect anywhere there is ground and power. If this is true, and I want to eliminate the breadboard, I see that there are 2 grounds but only one 5v pin on the Arduino. Thanks again for the fantastic vid, I'm just not sure how to now put it into practical use.
@KiKoLaw
@KiKoLaw Год назад
Thx 🙏
@hurricanenzl
@hurricanenzl Год назад
Thanks for the video, would this work on a leonardo and return a button push per postion change?
@fartmaster2933
@fartmaster2933 2 года назад
Amazing video. Is it possible to connect the ground of many rotary switches to a common pin. So that way only 2 new pins are need for each extra switch.
@skorkmaz
@skorkmaz Год назад
Great video. I have the almost same switch (dual pole 6 position). I'll use Arduino Due. Can I use the same? Same resistor and cap value? Thanks
@fernandogs8377
@fernandogs8377 Год назад
hey! good video, how can we use this rotary ladder switch, to drive rgb leds and modify brightness according to ladder value?
@hkr4life
@hkr4life Месяц назад
hi i have a rotary switch with these specifications: Number of Positions: 12 Position Number of Decks: 1 Deck Number of Poles per Deck: 1 Pole Current Rating: 200 mA Voltage Rating DC: 30 VDC Voltage Rating AC: 125 VAC Contact Style: Shorting Termination Style: Solder Lug Actuator: Flatted Index Stops: Adjustable Voltage Rating: 115 VAC, 30 VDC what resistors and capacitor do i need to buy to perfect match the rotary switch above? thx!
@eatthisvr6
@eatthisvr6 9 месяцев назад
does this work the same with leo bodner boards?
@awaagrikh8331
@awaagrikh8331 3 месяца назад
Hi, will the resistor wear out and reduce its resistant after several years?
@johnmitchell130
@johnmitchell130 2 года назад
Hi Scotty, Why did you use the 2.2uf Capacitor? You didn't tell us why.
@carneeki
@carneeki 2 года назад
My guess is to handle debounce. That is, the 2.2uF cap will (hopefully) hold the charge and maintain the present voltage on the analog pin as the switch wiper wipes off one contact before it reaches the next contact.
@halcyonanon
@halcyonanon Год назад
Hey John - I tried with and without the capacitor (although I only had a 0.1uF. also added the 100Ohm resistor inline which was mentioned in the video). Without the capacitor, the values you get from each switch position fluctuated widely; so much so that it was very hard to code discreet switch positions. Adding the capacitor in series smoothed out the figures entirely, and I got stable readings at each switch position (with a margin of ~5).
@jhonyyoelromerocapcha5400
@jhonyyoelromerocapcha5400 5 месяцев назад
¿Cual es el voltaje del capacitor?
@hatray4540
@hatray4540 7 месяцев назад
If anyone wants to use this or many buttons on 1 analoge pin with the joystick.h library: void loop() { int analog = analogRead(A0); // analogue pin "A0" if (analog> 800 && analog < 1000) { //we set up range for button 0 Joystick.pressButton(0); button_pressed = 0; } else if (analog > 750 && analog< 800) { //we set up range for button 1 Joystick.pressButton(1); button_pressed = 1; }.... // etc, if we want more buttons .... delay(50); Joystick.setButton(button_pressed, 0); // we release button when we no longer click
@chunhochan7157
@chunhochan7157 2 года назад
1
Далее
How to use rotary encoders
14:12
Просмотров 29 тыс.
Use FS2020 with an Arduino: MobiFlight Installation
11:02
Growing Algae
2:57
Просмотров 113 тыс.
Flight Simulator Switch Panel 2.0 DIY Project
16:14
Просмотров 79 тыс.
How to use Rotary Encoder with Arduino
14:44
Просмотров 40 тыс.
APPLE дают это нам БЕСПЛАТНО!
1:01
Просмотров 503 тыс.
$1 vs $100,000 Slow Motion Camera!
0:44
Просмотров 19 млн
Я УКРАЛ ТЕЛЕФОН В МИЛАНЕ
9:18
Просмотров 93 тыс.