Hello world, My third introductory lesson to Arduino is to connect a vacuum sensor to UNO for servo control. I managed to connect and activate the servo with sweep from examples (was my second lesson) and now using Analog Input attempting to connect vacuum sensor. When I run Serial Monitor (9600) it gives one read and an odd ones at that. (14 or 1414) the last time I saw this working (9600) the 0 (zero value) was closer to 142ish and it scrolled, changing if the vacuum sensor noticed suck. I started from scratch and can't fathom the values of what and for what. I have posted the code (from examples) I'm using, but have changed so many values I'm lost & stuck in a loop.
int sensorPin(A0); // select the input pin for the potentiometer
int ledPin(1); // select the pin for the LED
int sensorValue(14,15,0,100); // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
Serial.print(A0);
Serial.println(A0);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(A0);
// turn the ledPin on
digitalWrite(1, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(1000);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(1000);
}
int sensorPin(A0); // select the input pin for the potentiometer
int ledPin(13); // select the pin for the LED
int sensorValue; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
Serial.print(A0);
Serial.println(sensorvalue);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(A0);
delay(1000);
delay(sensorvalue;
}
int sensorPin(A0); // select the input pin for the potentiometer
Not the correct way to set up the sensorPin.
int sensorPin = A0; <- See the difference? Apply this to your setup of the led pin. Because your making the same mistake.
void setup() {
Serial.begin(9600); <- Good
Serial.print(A0); <- No, this.. I don't know what this'll do.
Serial.println(sensorvalue); <- You have not put anything into sensorvalue. Or sensorValue for that matter.
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(A0); <- This should work.
delay(1000); <- Why?
delay(sensorvalue; <- wrote sensorValue without the capital V and forgot the closing )
}
And you never put the Serial.prinln(SensorValue); into loop().
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue= analogRead(A0); // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
// Serial.print();
Serial.println(sensorValue);
delay(1);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
//delay(sensorValue);
}
Progress! I placed serial.println in the loop also.
I now have high & low values of vacuum sensor from Serial Monitor.
Next I'm asking the Uno to use the sensor to control the servo.
I inserted Servo.h into the sketch and now must assign 0-100 values to control action based on Serial Monitor readings.
// int sensorPin = A0; //select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue= analogRead(A0); // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
// Serial.print(sensorValue);
Serial.println(sensorValue);
delay(1);
#include <Servo.h>
Servo myservo;
int pos = 0;
myservo.attach(9);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(A0);
analogRead(A0);
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
//delay(sensorValue);
Serial.println(sensorValue);
Servo myservo;
myservo.write(pos);
delay(15);
}
//for (pos = 180; pos<= 0; pos -=1) {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
I am not a number, more of an algorithm. Watch me encrypt this sandwich...