Go Down

Topic: Some little Help (Read 1 time) previous topic - next topic


Hi everyone,
I'm from France, and this year is my very last year at high school, and i have to lead an engineering project untill May, in order to pass my BAC (kind of French SAT). There's some electronics in my project so i decided to take an Arduino Nano (w/ Atmega 328) to control the whole device. The electronic circuit is quite basic : a DC Motor, controled by a H-bridge (L293D), a Arduino Nano, and some force sensors put into a Voltage/potential divider. The force sensors give me an analogic signal (between 0 and 5V) that i need to catch with the arduino, and then to ask for the motor's rotation. I managed to control my motor in both senses with a simple "digitalWrite(13,HIGH)" (without worrying about the force sensors). Now I need to have the motor turning in one sense, when my analog signal is > than 3,5 V. So i want it to be read, then converted from numeric values (from 0 to 1233) to the "real" analogic value (0 to 5V). So i use the step converter...

However i encountered a few problems :
The first one is that the output that should control the H-bridge, is directly High, whereas nothing is conected to the analog pin ...
The second one is that, in my program i say for example that : " const int Digital_Output_HBridge = 1 " (this means the variable Digital_Output is "connected" to pin D1 no?) ; But if i also write " const int Analog_Input_FSensor  = 1 ", how can the Arduino understand that "Analog_Input_FSensor " is connected to A1 (and not D1 // I've tried to write const int Analog_Input_FSensor  = A1, but it send me back an error message ...)
So i'm not sure, that " const int Analog_Input_FSensor  = 1 " is correct
And i've tried to catch back the values on the Analog input, with the serial browse, but the values were fluctuating from like 200 to 400 but in a very random way, and i didn't catch any different values when my analog signal came from 0V to 5V (which i tested with a voltmeter) ; and i tried the different input pins, withoud any success ...

So please, if you can give me a clue it would be sooo great

And there is my program :

const int Analog_Input_FSensor = 1; // connected to A1
int value_read;
float U_value_read;

const int Digital_Output_HBridge  = 4; // connected to D4

void setup ()
  pinMode(Analog_Input_FSensor, INPUT);
  pinMode(Digital_Output_HBridge, OUTPUT);

void loop ()

value_read = analogRead(Analog_Input_FSensor);
U_value_read = value_read*0.00489;

if (U_value_read>3,5);
digitalWrite(Digital_Output_HBridge , HIGH);


Thanks for your help !


Feb 08, 2013, 10:41 pm Last Edit: Feb 08, 2013, 10:52 pm by Krodal Reason: 1
How is your H-bridge driver connected ?
Do you use a H-bridge motor driver board ? which one ?

Normally 3 output pins are needed for each H-bridge.
Two for the direction and one for the PWM signal to control the speed. The PWM is mostly connected to the 'enable' of a H-bridge driver.

If you paste your code, please use the code tags (the button with the '#' above the text field). If you mention a device or board, please add a link (just copy the url in your text).


This piece is fine:
Code: [Select]
const int Analog_Input_FSensor = 1; // connected to A1
The analogread function knows you're talking about the analog pins.

Use of European decimal separators isn't going to work: 3.5 not 3,5

If there is nothing connected to the analog input it is said to be floating and will indeed give spurious random looking values. You need something (such as the voltage divider you mentioned) attached there.


OK thanks a lot!:)
So i'll try my program with the "3.5" instead of "3,5", and i'll see what will happen

And yes I know that I have to connect 3 Arduino Nano http://arduino.cc/en/Main/ArduinoBoardNano pins to 3 H-bridge http://www.datasheetcatalog.org/datasheet/texasinstruments/l293d.pdfpins (and I quite don't care about the enable pin which will always be on). I attached the circuit, but what was very suprising when i tested it, wasn't that i couldn't comand the dc Motor, but it was that with the serial connection, i got nothing about the values, only random fluctuating values. Does it happen often ? cause i'm a bit lost


You should be able to get it working now.

But printing some values to the serial monitor makes it easier to see what is going on.
In setup() initialize the serial monitor at 9600 baud: Serial.begin(9600);
In loop() write the value: Serial.println(U_value_read);


I'll try monday :)
Thanks for your help

Go Up