I'm new to Arduino, and I am doing this project where a pressure sensor activates a 0-180 degree rotation servo.
#include <Servo.h>
Servo servo;
int reading;
int pos=0;
void setup(void) {
Serial.begin(9600);
servo.attach(9); //servo at digital pin 9
servo.write(0); //initial point for servo
}
void loop(void) {
int value;
reading = analogRead(A0); //attached to analog 0
Serial.print("Sensor value = ");
Serial.println(reading);
if(reading>950){
value = map(reading, 180, 360, 360, 180);}
else{for (pos = 0; pos <= 180; pos += 1) {
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
delay(15);
}}
servo.write(value);
delay(100);
}
I found a code made by a user named Anas Siddiqui, I changed it a little because I do not want to use someone else's researched code to my use. However, this person did not provide any information on what the code is, or what is for what.
Any advice or things that may be able to help would be very appreciated. (BTW this is for an arduino UNO.