Serial monitor readings use for output

Hi there,

I am a novice looking for help to advance a project to get an old film scanner

In short, a motor rotates a cog with staggered rotation, i.e. rotates a bit, stops, rotates a bit, stops … and so on.

I’ve linked the powering voltage to my Arduino Uno through a transistor, and then read it on AO input pin.

I get a a reading on the serial monitor of 10001000100010001000… and so on

Here’s my question;)

Can i use the 1 entry to trigger an output voltage on another pin, so pulses occur all in synch?

What code entries do I need to read the Serial Monitor data and then use it?

I’d appreciate any tips from the ‘pros’ out there!

Many thanks

Patrick

code attached;

read.digital.ino (690 Bytes)

8176Patrick:
Can i use the 1 entry to trigger an output voltage on another pin, so pulses occur all in synch?

If you want all that to happen on the same Arduino then there is no need to get data from the Serial Monitor because the Arduino already had the data before it sent it to the Serial Monitor.

And, yes, based on the limited information you have provided I reckon you can use the 1s to trigger something else.

Perhaps you just need some code like this

if (sensorValue == 1) {
   // do something
}

By the way it is much easier for people to help you if you include short programs in your Post - like this

const int digitalInPin = 12;  // input pin:
const int digitalOutPin = 9;  // output pin led:
int sensorValue = 0; // value read from input pin:
int outputValue = 0; // value output to the PWM
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // read the analogue value
  sensorValue = digitalRead(digitalInPin); //map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 55); // change the analog out value:
  digitalWrite(digitalOutPin,outputValue);

  // print the results:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output =");
Serial.println(outputValue);

//wait 2:

delay(2);

}

...R

Many thanks, Robin, for the help, you're a star!

I've been thinking about whether there's a simpler way of getting the result I need:

Basically, whenever the cog stops rotating in its cycle, I'd like to trigger a camera exposure. I wonder if the code could simply detect either a high or low voltage, as the voltage cycle (going into the transistor) is one that goes from high (driving the cog rotation) to low (stopping it).

My attempt to re-write a simpler version would be as follows,

This is mainly based on amateur guesswork:) If there's an obvious flaw here, I'd be really grateful for any corrections, or explanations why this won't work

Many thanks, again,

Patrick

#define analogInPin = A0; // input pin:
#define analogOutPin = 9; // output pin led:

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
} // read the voltage relayed across the transistor
pinMode(analogInPin, INPUT);
pinMode(analogOutPin, OUTPUT);

void loop() {
// read the transistor output voltage
if (analogInPin, HIGH){analogWrite(analogOutpin, LOW);
}
else (analogWrite(analogOutpin, HIGH);
}

}

8176Patrick:
My attempt to re-write a simpler version would be as follows,

Before I look at your program, three things …

What happens when you try the program? And how, exactly does that differ from what you want?

Please use the code button </> when posting code so it looks like in my Post and is easy to copy to a text editor.

Please use the AutoFormat tool to lay your program out better for easy reading and fault finding.

…R

pinMode() goes inside setup() {}

To read a pin you must use digitalRead() or analogRead().

If you are comparing to HIGH then digitalRead() seems more appropriate. On most Arduinos all analog pins can be used with digitalRead()

Next time use code tags in your post.

This is how far I got. Unfortunately the code seems to uploads until the last line becomes highlighted as an error…

Many thanks, Robin and Morgan, for the tips in the two previous replies. Hopefully I’ll get there!

< /
#define inpin = A0; // input pin:
#define outpin = 9; // output pin led:

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(inpin, INPUT);
pinMode(outpin, OUTPUT);
}
// read the voltage relayed across the transistor

void loop() {
// read the transistor output voltage
inpinState = digitalRead(inPin);
if (inpinState == HIGH) {
digitalWrite(outpin, LOW);
}
else {
digitalWrite(outpin, HIGH);
}
} >

Did you try to compile the code before you posted it? Why not?

#define inpin = A0;  // input pin:
#define outpin = 9;  // output pin led:

Look carefully at the reference for the define directive. No = and no ;

inpinState = digitalRead(inPin);

Where in the code is inpinState declared? There is no inPin variable, there is inpin, though. Case matters.

The code button looks like </> but that is not how you type [ code ]