Go Down

Topic: Programming Arduino book sketch 6-08 (Read 2 times) previous topic - next topic

Summerman

I am working the exercises in this book and am having some trouble with sketch 6-08 having to do with Analog Outputs. No matter what number I type in the Serial Monitor 0-5 I get the same result displaying on my multi meter. The number I get is 2.15. If I type 3 it reads 2.15 and if I type 5 it reads 2.15. I have the multi meter set on the 20 mark in the V section of the meter just like in the picture on page 101 Figure 6-11. The ground lead (black cable) is connected to the wire from one of the GND pins and the red cable is connected to the wire from pin 3 on the Arduino. I am using the 1.0 version if the IDE.

Has anyone else been working from this book and had a similar problem?

All the other example I have tried out have worked as expected.
A bad day at the beach is better than a good day at work.

CrossRoads

Can you post the sketch and anything connected?
Is it a digital output, and you haven't used pinMode (pinX, OUTPUT);  ?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Summerman

Here is the sketch from the book that I'm using.

//sketch 6-08
int outputPin = 3;

void setup()
{
pinMode(outputPin, OUTPUT);
Serial.begin(9600);
Serial.println("Enter Volts 0 to 5");
}

void loop()
{
if(Serial.available() > 0)
{
char ch = Serial.read();
int volts = (ch - '0') * 51;
analogWrite(outputPin, volts);
}
}

I have a wire plugged into pin3 and another wire plugged into a ground pin. The red wire from the meter is connected to the pin 3 wire and the black wire from the meter is connected to the ground wire. When I upload the code to the Arduino and open the Serial Monitor and type a number from 1 to 5 and hit enter the readout on the meter says 2.15 and some times 2.16. According to the book If I type 3 and hit enter the read out on the meter should be 3 volts. I think if I were type 5 the meter should display 5 volts. The dial on the multi meter is set at V 20.

I don't know what else to say about it.
A bad day at the beach is better than a good day at work.

CrossRoads

Do the other PWM pins work? Maybe 3 is damaged.

If you write a simple on, off sketch, say at a 1 second rate, does the pin work?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Si

Just a thought, but is your meter set to DC?

Does it say 5V when you connect it to the 5V socket on the Arduino?

Is the negative lead from the meter connected to GND?

Is the meter probe lead in the right socket for Volts on the multimeter? Usually there are separate sockets for current measurement.

Hope you are enjoying my book :)

Simon Monk.
--
My New Arduino Book: http://www.arduinobook.com

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview