Pages: [1]   Go Down
Author Topic: Problem with sensing in Project 4  (Read 1353 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
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(){
  Serial.begin(9600);
  pinMode(greenLEDpin, OUTPUT);
  pinMode(redLEDpin, OUTPUT);
  pinMode(blueLEDpin, OUTPUT);
}

void loop(){
 
  redSensorValue = analogRead(A0);
  delay(5);
  greenSensorValue = analogRead(greenSensorPin);
  delay(5);
  blueSensorValue=analogRead(blueSensorPin);
 
  Serial.print("Raw sensor values \t Red: ");
  Serial.println(redSensorValue);
  Serial.print("\t Green: ");
  Serial.println(greenSensorValue);
  Serial.print("\t Blue: ");
  Serial.println(blueSensorValue);
 
  redValue=redSensorValue/4;
  greenValue=greenSensorValue/4;
  blueValue=blueSensorValue/4;
 
  Serial.print("Mapped sensor values \t Red: ");
  Serial.println(redValue);
  Serial.print("Green: ");
  Serial.println(greenValue);
  Serial.print("Blue: ");
  Serial.println(blueValue);
 
  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.
« Last Edit: January 23, 2013, 05:31:00 pm by tkc108 » Logged

Land of Oz
Offline Offline
Jr. Member
**
Karma: 3
Posts: 73
I dream in Assembler
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Suggestions:

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

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

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Photography nut trying to make the flux capacitor of macro pho

Pages: [1]   Go Up
Jump to: