On/off switch to a fast pulse

Dear Arduino people,

My name is Finn and i am not that good in coding with an arduino, i have a arduino uno and i want to turn a on/off switch into a button sort of output.

So what I want to achieve is as follows:
I have a on/off switch,
when you turn the switch to on (input),
the arduino gets a input and outputs a little pulse form about 0.2 seconds(output),
and if you put the on/off switch back to off it pulses again for about 0.2 seconds(output),

i don't know how to explain this better but i hope someone can help me with this,

greetings finn.

Hello, Finn.
Begin with the beginning, just like learning a new language. IF you don't try and try and repeat and fix the errors and try again, you will always remain at the same spot.

What have you tried? How have you wired the switch?

Your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

You can read up on and play with

  1. Pull-up resistors; Most Arduinos (all ?) have them builtin.
  2. State change detection; you want to react when the switch becomes active and inactive, not when the switch is active / inactive. There is an example in the IDE.

Which board are you planning to use?

Start with point form explanation of what’s needed.

example

  • the Arduino sees its input go HIGH.
  • the Arduino outputs a HIGH pulse for 50ms

. . .

sometimes an image is better than a long explanation :slight_smile:

so is this what you mean?

➜ you want a 0.1s pulse every time the switch changes state so start looking at the state change detection example in the IDE

there will be questions to solve like

  • what happens if you flip the switch again during the 0.1s interval?
  • is the switch bouncing?

this is exactly what i mean, how can i put it in code?

sorry i have found what you mean, i really really thank you for helping

you found this example right? (from the File/Examples menu)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.