View Single Post
Old 11-17-2016, 01:40 PM   #21 (permalink)
Daox's Avatar
Join Date: Dec 2007
Location: Germantown, WI
Posts: 11,152

CM400E - '81 Honda CM400E
90 day: 51.49 mpg (US)

Daox's Grey Prius - '04 Toyota Prius
Team Toyota
90 day: 49.53 mpg (US)

Daox's Insight - '00 Honda Insight
90 day: 64.33 mpg (US)

Swarthy - '14 Mitsubishi Mirage DE
90 day: 56.69 mpg (US)
Thanks: 2,457
Thanked 2,523 Times in 1,522 Posts
I just started looking the the arduino servo library the other day. However, it seems very easy to use. First, you setup a servo in the code. Then, at any point you can tell the servo to go to X degrees. Its really that simple. Here is an example code that moves a servo based off input from a potentiometer. My code will be very similar, except that it'll fully open or close the block based off of the temperature of the coolant. At this point I don't plan on partially opening the grill block.

 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <>

 modified on 8 Nov 2013
 by Scott Fitzgerald

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
Once I get done with the mechanical stuff, I will be moving into the electrical and I will post my code when I get there.

The arduino will be tapping into the coolant temperature sensor signal so it knows when to open and close, but that is about it other than hooking up power and ground wires.

As for powering the servo, it should be able to be run off the 5V power regulator onboard the arduino. The specs on the regulator say it can handle up to 800mA, and the servo specs say it uses 200mA. So, we have plenty of head room for the arduino to do its job.

Current project: A better alternator delete
  Reply With Quote