Hello friend I’m using arduino nano i want add a 3 mode switch in my blind stick to control the distance in mode 1 distance is 30 mode to distance is 50 in mode 3 distance is 100
How to apply this type of function in my code or hardware.
Code is below:
const int trigPin = 3;
const int echoPin = 2;
const int buzzer = 5;
const int motorPin = 6;
Please post your code using code tags. It is all explained in the sticky post at the top of the forum. It helps people help you. After reading that post, you can edit your post and fix it.
The easiest method would be to wire up a push button. Every time you press it, you change mode and when it gets to high, it wraps back around to the beginning. (1 -> 2 -> 3 -> 1 -> 2...)
Look at the state change detection example in the IDE (File->examples->02.digital->StateChangeDetection) to learn how to do it properly.
Now I’m using single slide switch which have 1 common and 4 states.
I use pull up circuit with this switch but it not working properly when I touch pin 7 to 9 any pin it works with my body resistance and when I connect it to switch only one threshold is working.
Please help me how to resolve this problem.
My code which is i use
const int trigPin = 3;
const int echoPin = 2;
const int buzzer = 5;
const int motorPin = 6;
long duration;
int distance;
int safetyDistance;
const int pinSlideSw = 7;
const int pinSlideSw1 = 8;
const int pinSlideSw2 = 9;
const int pinSlideSw3 = 10;
int threshold;