« Lab Three: Servo Motor | Main | Image Map of a Prototype in Progress »

Serial Lab

This was frustrating because I got so close to getting this to work!! When it came time for Processing and Arduino to talk it seemed as if the arduino was not quite registering any info. When the pots were turned the serial monitor was outputting very low numbers hovering around 48-50 and the sensors did not seem to work at all...

It is hard to figure out if it's the board or it's the code. I've made sure i was talking to the right port etc. I'll have to come back to it later... :(

offending code:

int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(0)/4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
// read switch, multiply by 255
// so that you're sending 0 or 255:
thirdSensor = 255 * digitalRead(2);
// send sensor values:
Serial.print(firstSensor, DEC);
Serial.print(secondSensor, DEC);
Serial.print(thirdSensor, DEC);
}
}

Comments

How were your pots wired up? Was it a different type of sensor?

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)