Go Down

Topic: Problem with sensing in Project 4 (Read 1 time) previous topic - next topic


Jan 23, 2013, 11:27 pm Last Edit: Jan 23, 2013, 11:31 pm by tkc108 Reason: 1
I am having a problem with project four. For some reason the sensors doesn't work and continiously show value 0. i checked manualy and the serial connection is established and the led shows different colours, if i manually preset them.

My code is:

const int greenLEDpin=9;
const int redLEDpin=10;
const int blueLEDpin=11;

const int redSensorPin=A0;
const int greenSensorPin=A1;
const int blueSensorPin=A2;

int redValue=0;
int blueValue=0;
int greenValue=0;

int redSensorValue=0;
int greenSensorValue=0;
int blueSensorValue=0;

void setup(){
  pinMode(greenLEDpin, OUTPUT);
  pinMode(redLEDpin, OUTPUT);
  pinMode(blueLEDpin, OUTPUT);

void loop(){
  redSensorValue = analogRead(A0);
  greenSensorValue = analogRead(greenSensorPin);
  Serial.print("Raw sensor values \t Red: ");
  Serial.print("\t Green: ");
  Serial.print("\t Blue: ");
  Serial.print("Mapped sensor values \t Red: ");
  Serial.print("Green: ");
  Serial.print("Blue: ");
  analogWrite(redLEDpin, redValue);
  analogWrite(blueLEDpin, blueValue);
  analogWrite(greenLEDpin, greenValue);

I noticed also that if I unplug cables from a0 and a1, the led goes red and blue, respectively. but if i unplug the a2, nothing happens.

I would be greatful for help. I must be not seeing some simple error.


I don't have the beginners kit, but working with several Arduino boards.


What do you have at the inputs to the analog pins ?
If the voltage level is static, you won't have any change visible until you apply a varying voltage manually.

Again a guess from me, but when you unplug A0 and A1 you are changing the chip I/O pin state manually so you see an indication.
Also, you seem to have a wiring issue: should not A1 signal a "green" input state ?

I believe you don't have a programming error, you are simply not interpreting the purpose of the project correctly



Thank you for the advices. I found out the problem. I looked at the board today during the day and i saw one of the cables was plugged in wrong. i did not see it last time in the book in the picture as it was evening and i did not spot it. i knew it is something silly. thanks again.


The breadboard diagrams are quite tricky to read, especially in the evening when most of us probably do this stuff. Maybe a clearer solid black mark on which hole each thing was in, or x,y coordinates, would help
Photography nut trying to make the flux capacitor of macro pho

Go Up