Hello guyz can you help me how to code
IR sensor controlling servo to stay on 90 degrees and after that when i press button it goes to 0 degrees
Most examples found use Infrared Remote control. This one on Youtube may be useful:
How to Control Servo Motor and IR sensor Module Using Arduino Uno R3 || Servo Motor || IR Sensor || - YouTube
Hello greedisland23
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
#include <Servo.h>
Servo tap_servo;
int sensor_pin = 4;
int tap_servo_pin = 5;
int touch_sensor = 6;
int val;
int val2;
void setup(){
pinMode(sensor_pin, INPUT);
tap_servo.attach(tap_servo_pin);
}
void loop() {
val = digitalRead(sensor_pin);
val2 = digitalRead(touch_sensor);
if (val == 1 && val2 == 0)
{
tap_servo.write(90);
}
while (val == 1 && val2 == 1)
{
tap_servo.write(0);
}
}
this my code i want for my servo
thanks for helping us
Hello
Nice sketch.
And the question is?
How i overlap my sensor when it is equal to 1 that my servo is in 90 degrees then when i touch the touchsensor it will go back the servo to 0 degrees
Hello
The IDE provides an example called State change detection
You may use this example to control the servo correctly.
Have a nice day and enjoy coding in C++.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.