Hi guys,
I am new to the Arduino and I hope you guys can help me out a bit.
What I am currently doing is to connect the light sensor and the continuous rotation servo to the Arduino board. When the light intensity is below a certain amount, it will then trigger the servo so it will rotate for certain degree. It will then stay at that position for a while and goes back to the original position. The code works perfectly, and I want to connect more servos and more sensors, so that sensor A will control servo A; sensor B will control servo B. But the questions are:
- Is it possible to have several light sensors as different input?
- I was using "delay" in my script, so it might not possible to have the servos operate properly in the same time. Is there any way but doing the same job?
I really need your help, thank you for reading my quesitons.=]
Here is the Arduino script I used:
#include <Servo.h>
Servo myServo;
#define myServoservopin 8
#define Sensor A0 // setting up light sensor
int Sensorvalue;
const int Threshold = 10; // the value that the servo will trigger
void setup(){
myServo.attach(myServoservopin);
myServo.writeMicroseconds(1500);
Serial.begin(9600);
Serial.println("Inactive!");
Serial.println(Sensorvalue);
}
void loop(){
Sensorvalue = analogRead(Sensor);
Serial.println(Sensorvalue);
if (Sensorvalue < Threshold) {
Serial.println(Sensorvalue);
Serial.println("Active!");
myServo.writeMicroseconds(1600); // servo rotating in a specific direction
delay(4500); // the time that the servo would keep rotating in that direction
myServo.writeMicroseconds(1500); // the servo would stay stationary in 1500
delay(1000); // the time that the servo would stay in position
myServo.writeMicroseconds(1400); // servo rotating in opposite direction in attempt to go back to the original position
delay(4500);
Serial.println("Inactive!");
myServo.writeMicroseconds(1500);
}
}