Questions and Discussion concerning the Bare Bones Board
Post Reply
Posts: 2
Joined: Wed Dec 31, 2008 1:47 pm


Post by hmsassen » Wed Dec 31, 2008 2:12 pm

I can't get the analogRead function to work on my Bare Bones Board. I know it is not the board because this is the third board I have purchased and I have the other two working on other applications (Which don't use the AnalogRead function). This application is to drive an old style Tyco Race car around the track. I want to be able to maximize the car's speed and possibly be able to detect the car leaving the track before it happens. My code is listed below but even the analogRead example program in the reference, which varies the timing of an led, doesn't work. I am using the Arduino 12 complier with the board selected as "Arduino NG or older w/AT mega 168". All the other functions work but not this one. I have swapped the boards but all of them don't work with this code either. The analogRead value doesn't change. I have tried different inputs but all the same. I have measured the voltage off the pot all the way back to the chip and they are good. I can even tie the input to VCC or Ground and no change. Any help would be appreciated.

#include <SoftwareSerial.h>
/* Tyco Race Car
Hardware Setup
Arduino Board
3 --- Tx to LCD 117
4 --- Rx from LCD 117 (Not really Used)
A0 14 --- Throttle Control Pot
9 --- PCM Output to Race Car

// Global Variables
#define txPin 3 // txPin my.Serial LCD
#define rxPin 4 // rxPin is immaterial - not used
#define PowerPin 9 // Power to Car
#define CarPin 14 // Pot that acts as throttle - note: should be 0 for analogRead()

int val=0, i=0, n=0; // Variables

// mySerial is connected to LCD
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup()
pinMode(PowerPin, OUTPUT); // sets the pin as output

// Warmup the car
analogWrite(PowerPin, 190); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
analogWrite(PowerPin,0); // Stop Car

// Serial Ports Setup
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // Open LCD at 9600 baud

mySerial.print("?f"); // clear the LCD
mySerial.print("Race Car Control?n");
mySerial.print("Setup Complete?n");
delay(5000); // pause five secs to admire

void loop()

for (i=0; i<=7; i++)
val = analogRead(CarPin); // read the input pin
delay (100);
val = map(val, 0, 1023, 0, 255);
mySerial.print (val);
mySerial.print (" - ");
analogWrite(PowerPin, val); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255


Posts: 2
Joined: Wed Dec 31, 2008 1:47 pm

Re: AnalogRead

Post by hmsassen » Wed Dec 31, 2008 8:42 pm

I finally figured it out. Some where I read that the Analog pins on the Bare Bones Board were 14-19 they are 0-5. I just changed the CarPin from 14 to 0 and it worked. I love these boards. The first project that I completed was to interface my X-10 Motion sensors to my Z-wave light switches. This project with the tyco cars is just for fun. Next I may get the train set out and play with it. Thank you all for this forum, I have learned a lot!

Site Admin
Posts: 733
Joined: Mon May 12, 2008 4:19 pm

Re: AnalogRead

Post by paul » Sun Jan 04, 2009 1:51 pm

Yes the pin numbering is confusing in my opinion. It's one of those things that the Arduino team in service of supposedly making things easy to use. But then as soon as people get a few chops and get past blinking three LED's it turns out to be confusing.

The Arduino team didn't ask me about it though,


Post Reply