Intro to Arduino: Connecting vacuum sensor to UNO

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);
}

Thanks in advance for any help.

#6

int ledPin(1);      // select the pin for the LED What else is pin 1 used for?

int sensorValue(14,15,0,100); What's that?

Code: [Select]

int ledPin(1); // select the pin for the LED

What else is pin 1 used for?

A: Err, nothing, it's empty. I have a Servo on pin9 and Sensor on A0. But after reading Help, I thought I would try 1 as the first sensor. Pffft.

Code: [Select]

int sensorValue(14,15,0,100);

What's that?

A:The reading I get from the Serial Monitor = 14, so I added a higher value to see any change, from 0-100

The LED is pin 13 not 1 and int ledPin(1); doesn't actually do anything.

int <- Is saying I want room to store an integer, but this isn't complete.

int ledPin; <- Is saying, I want room to store an integer, and I'm going to call it "ledPin"

int ledPin = 13; Is sying, I want room to store an integer, and I'm going to call it "ledPin". And.. Put a 13 in there.

int sensorValue(14,15,0,100); ..should be..
int sensorValue;

when ou write...

delay(1000); your saying stop for 1000 milliseconds. If you want to delay for sensorValue milliseconds you need..

delay(sensorValue);

-jim lee

To write to Serial..

In setup() put..

Serial.begin(9600);

in your loop() after the analog read of the sensor put..

Serial.println(sensorValue);

-jim

jimLee:
int ledPin(1); doesn't actually do anything.

Are you being serious?

IN his case it doesn't

-jim

jimLee:
IN his case it doesn't

-jim

It absolutely does.

Whether or not it is the right thing, it assigns the value 1 to the variable ledPin

TheNewNumber6:

What's that?

A:The reading I get from the Serial Monitor = 14, so I added a higher value to see any change, from 0-100

That's because you printed (twice) the value A0, which, for a Uno, is equal to 14.

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;
}

You'll have noticed by now that that doesn't compile

(I'm a big fan of The Prisoner, BTW. Watched it first time round on TV, in B&W)

Yes, I noticed. I know I need the Serial Monitor to give me the values, but I'm unable to connect properly.

Indeed, The Prisoner was an awesome show, way ahead of it's time.
Plus username Hal 9000 was already taken. Sorry Dave.

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().

-jim lee

jimLee:
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.[/code]

To the compiler, there is no difference.
Please stop suggesting that there is.

  Serial.print(A0);          <- No, this.. I don't know what this'll do.

On a Uno, it will print "14"

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);
}

I'd use..

int sensorValue;

Then put the analogRead(sensorPin) in loop()

like..

sensorValue = analogRead(sensorPin);

-jim lee

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...

So.. you say you got this running? Because.. I can't get what you wrote to even compile. Lets see what you actually have.

-jim lee