# Advice on 12V servo motor project!!

Hi,
I’m building a car exhaust system with servo flap control by UNO R3. Friend and I been on this project for months already. Not able to make the servo motor flap working. Been searching on web, but not much info on 12V servos coding and wiring. We are beginners, so hopefully some nice ppl willing to give us some help.

Goal: On/off switch or “sport mode” button signal through Uno R3, open/close 2 12V servo motor on exhaust system.

Servo motor: 12V, 3 pins (12V, ground and PWM signal). Operating value measured off from a factory car (same servo motor). Flap opens: 12V, 100 Hz, 92.80% duty cycle. Close: 100 Hz, 9.92%.

Coding:

``````unsigned long duty1,duty2;
// Duty Cycle in terms of a percentage.
unsigned long plus;
// Value read from A1, in case plus mode is activated
float xxx;
// Float numbers to calculate duty for PWM 1 and PWM 2
float yyy;
unsigned long pwm1;
// Value read from A0 and A2 to give PWM duty cycle output in terms // of 0-5V
unsigned long pwm2;
void setup(){

pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
TCCR1A = _BV(COM1A1) | _BV(COM1B1) ; // phase and frequency correct mode. NON-inverted mode
// TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1A0) | _BV(COM1B0) ;
//phase/frequency correct mode. SELECT THIS FOR INVERTED OUTPUTS.
TCCR1B = _BV(WGM13) | _BV(CS11);
// Select mode 8 and select divide by 8 on main clock.
}

void loop(){

// Program that lets different values on A3 choose different values of frequency, e.g. 100,200,400,500,1k,2k,3k,4k,10k,
//etc in relation with a free input.
if (analogRead(A3) <100) ICR1 = 10000; // 100Hz - Default value to 100Hz for A3 = 0V
if (analogRead(A3) <200 && analogRead(A3) > 100) ICR1 = 5000; // 200Hz
if (analogRead(A3) <300 && analogRead(A3) > 200) ICR1 = 2500; // 400Hz
if (analogRead(A3) <400 && analogRead(A3) > 300) ICR1 = 1000; // 1000Hz
if (analogRead(A3) <500 && analogRead(A3) > 400) ICR1 = 500; // 2000Hz
if (analogRead(A3) <600 && analogRead(A3) > 500) ICR1 = 333; // 3000Hz
if (analogRead(A3) <700 && analogRead(A3) > 600) ICR1 = 250; // 4000Hz
if (analogRead(A3) <800 && analogRead(A3) > 700) ICR1 = 100; // 10000Hz
if (analogRead(A3) > 800) ICR1 = 1000; // Default value to 1kHz for A3 = 5V

//ICR1 = 1000; // for ICR1 = 1000, frequency = 1kHz.
xxx = float(pwm2);
// Turn read values from the POTs to float for mathematical
yyy = float(pwm1);
xxx = xxx * ICR1;
// Multiply with ICR1 and divide by 1023 to give required percentage
yyy = yyy * ICR1;
xxx = xxx / 1023;
yyy = yyy / 1023;
//Assign values to OCR Registers, which output the PWM duty cycle.
OCR1B = int(xxx);
OCR1A = int(yyy);
}
``````

With that, I don’t even get PWM out of Uno.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

You do have the gnd of the arduino and the gnd of the servo power supply connected?

Tom... :)

Hi, Have you tried to use the servo library in the arduino IDE, click Files, Examples.

Also are you changing level from 5V to 12V for the servo signal?

Tom.. :)

I tried to use NPN transistor to step up to 12v for servo signal, but I don't get PWM signal out. So I stop the wiring, thought I should get the basic signal out of Uno 3 before I start going deeper.

Hi, I can't right now try your sketch, about to go to work, but can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I can see you are using the analog input to set your frequency. You are outputting two PWMs, I assume both outputs have no signal.

Can you measure your three analog signals with a DMM to confirm your inputs.

Thanks.. Tom.. :) Can you please try an Example from the arduino IDE, using a servo library, they run at standard PWM frequency. They are located in the Files tab.

I attached a basic circuit I original did, which I find likely wrong set up.
I hooked up a POT just to see I can vary the input, which I’m getting power to analog in (goal is to use a on/off switch or signal from “sport button”), but no output from both PWM.
I’ve tried the servo library from IDE, did not work. These motor I got runs at 100 Hz freq.

Hi,
The NPN transistor will not be able to do level change and switching the way it is configured.
The diag below should be more fruitful.
Note the resistor in the base circuit, it has to be there to limit base current.

Tom…
I’m not sure of your transistor number, but this should get you somewhere.
The transistor reverses the PWM duty , so min duty will open and max duty will close.

Hi Tom,

Been busy with school and work… trying to get back to the project.
I still couldn’t get pwm output from the Uno 3.
Any idea with the coding?

Hi, Look at examples in the Arduino IDE, showing the use of the servo library, it is quicker than setting up timers. The frequency is higher, but it would be worth seeing if it works. I'm at work at the moment, later at home I'll check if you have read this.

Tom... :)