Pages: [1]   Go Down
Author Topic: Programming Arduino book sketch 6-08  (Read 1904 times)
0 Members and 1 Guest are viewing this topic.
Utah, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

A bad day at the beach is better than a good day at work.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 512
Posts: 26202
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post the sketch and anything connected?
Is it a digital output, and you haven't used pinMode (pinX, OUTPUT);  ?
Logged

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.

Utah, USA
Offline Offline
Newbie
*
Karma: 2
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

A bad day at the beach is better than a good day at work.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 512
Posts: 26202
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

Simon Monk.
Logged

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

Pages: [1]   Go Up
Jump to: