Simple touch sensor override

Hello, can someone please advise? …im pretty new to this

I am trying to set up a project that uses a light sensor to control a servo (this works fine) but can be overridden by a touch sensor. So, when the touch sensor is pressed it goes to a designated servo position. I am struggling as my touch sensor does not work … I know it works with my other codes so the (<120 / >120) is correct.


// include the servo library
#include <Servo.h>

// create a servo object called servo1
Servo servo1;

int pos = 0;
int postarg=0;
int button = (A5);

void setup() {
pinMode(pos, OUTPUT);
pinMode(button, INPUT);

void loop () {
int lightValue = analogRead(A0);
lightValue = map (lightValue, 0, 1023, 0 ,180);
servo1.write (lightValue);
if (analogRead(button)<120) postarg=lightValue;
if (analogRead(button) >120) postarg=90;

if(pos<postarg) pos++;
if(pos>postarg) pos–;



…if anyone can help I would be truly grateful.


Please use code tags to post your code. What does it do? You are trying to output some serial data but haven't setup the serial connection. Do that and see what comes out.

Also the first "servo1.write" sets the servo to the ligthvalue and then if the button is pressed it is set to 90. But the loop then starts again (after the short delay of 5) and sets it to lightvalue again. So i would say remove the first servo1.write and see if that works