Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / PWM preset state issues ("not declared in this scope") on: Today at 01:30:26 am
Hi everyone,

i am in the middle of designing a fast idle controller for my project car and cannot work out what my issue is, im still pretty novice in programming and this may be a simple issue, could some of the pros on here please look over my code and see if there are any mistakes?

thanks in advance


//PWM engine idle valve controller by Mike Quirke 2014 "jupiterengineering" is my username on the arduino forum.

//the code below is designed to control a two or three wire air idle valve used in many fuel injected cars.
//operating on PWM, in similar fashion to a servo, the valve opens to various positions, depending on engine conditions to allow throttle
//compensation for heavy electrical or mechanical loads at idle speed, to pevent engine stall should the A/C power up or, in a condition of a
//cold engine where a small percentage of extra throttle is needed .

//the device takes a 5v signal from either, or both of the A/C controller or compressor solenoid and the cold idle pinout from either the cars
//engine management unit, or a seperate temperature sensor and provides throttle compensation based on the state/s or the two inputs.
//if the two inputs are revieving their 5v signal, both duty cycles are summed up to compensate for the load of two situations, otherwise, either function
//as required by conditions.

//i have configured the pins for use with an attiny 85 chip.

#include <Servo.h>
Servo idlevalve; //initiate servo object to control the idle valve
int warmup; //integer (below) for engine warmup with A/C off
int ac; //integer (below) for A/C on, warmup off
int warmupandac; //integer (below) for warmup on, A/C on
const int goingHigh = 920; // goingHigh = 920: 4.50V/5V * 1023 punch this in calculator to verify...
const int goingLow = 102; // goingLow = 102: 0.50V/5V * 1023 punch this in calculator to verify...

void setup() {
idlevalve.attach (0); //PWM output to idle valve driver transistor
pinMode (1,OUTPUT); //led indicating engine warmup mode activated
pinMode (2,OUTPUT); //led indicating A/C compensation mode activated
pinMode (A3,INPUT); //input from ecu to activate fast idle
pinMode (A2,INPUT); //input from A/C system to activate A/C idle compensation
const int warmup= map(warmup,goingLow,goingHigh,0,90); //for warmup on, A/C off,scaling input values to activate idle valve at (90,which is 50 percent duty cycle to warm up engine
const int ac= map(ac,goingLow,goingHigh,0,45); //for A/C on, warmup off (45 or 25 percent duty cycle)
int warmupandac= map(warmupandac,goingLow,goingHigh,0,135); //for warmup on, A/C on (135 or 75 percent duty cycle)
int enginetempStatus = analogRead(A3); //read A3 to determine if warmup mode required or not
int acStatus = analogRead (A2); //read A4 to determine if A/C mode required or not

void loop()
if  (enginetempStatus >= goingHigh){ //if ecu cold idle activated,
digitalWrite (1,HIGH); //turn on warmup mode LED
idlevalve.write(warmup); //also activate idle valve to specified warmup duty cycle.
if (acstatus >= goingHigh){ //if A/C is switched on,but warmup is off,
digitalWrite (2,HIGH); //turn on A/C status LED
idlevalve.write(ac); //activate idle valve to specified A/C duty cycle.
if (enginetempStatus, acStatus >= goingHigh){
digitalWrite (1,2,HIGH); //turn on both status LED's
idlevalve.write(warmupandac); //activate idle valve to specified A/C duty cycle.
delay (1);

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Mega or Mega 2560, ATmega1280"

idle_controller.ino: In function 'void loop()':
idle_controller:39: error: 'enginetempStatus' was not declared in this scope
idle_controller:43: error: 'acstatus' was not declared in this scope
idle_controller:47: error: 'enginetempStatus' was not declared in this scope
idle_controller:47: error: 'acStatus' was not declared in this scope
C:\Documents and Settings\Administrator\My Documents\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:125: error: too many arguments to function 'void digitalWrite(uint8_t, uint8_t)'
idle_controller:48: error: at this point in file

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

2  Using Arduino / Sensors / Re: battery temp sensing on: March 04, 2014, 09:39:44 pm
thanks for the reply,

i am using a TMP36 three pin sensor (to92 package) and want to measure only between 0c to 100c

3  Using Arduino / Sensors / battery temp sensing on: March 04, 2014, 07:26:34 pm
hi all,
ive been away from the arduino scene for a while due to other projects and was wondering if anyone can assist me on my code below,

its for a battery charger and i want to add in a temp sensor, but i am unsure how to factor in the values for it, is anyone able to give me any pointers?
thanks in advance and if there is anything else wrong, please let me know, as i still have a lot to learn!


// Automatic battery charger for audio use, designed by Mike Quirke 2014.
// my username on the arduino forum is "jupiterengineering".

//this program is for an automatic nimh battery charger designed to integrate with a piece of hi fi equipment
//designed to run on batteries, as they provide the perfect DC supply.

//my particular setup is a few battery packs in 24v configuration,which power a highly sensitive turntable
//preamp,however can be set to charge any voltage configuration via a voltage divider circuit.

//when the preamp is switched off in standby mode, the charging monitor is engaged, should the battery voltage
//in this state drop below 23.50v, the charge relay and flashing status led will activate,
//should the battery voltage rise above 28.00v, the charge relay and flashing status led will deactivate.
//when the power switch to the preamp is switched to the on position, a 5v signal is applied to the power toggle
//input, which instructs the charger to keep the charge relay and status indicator led illuminated, regardless
//of battery voltage.
//the temp sensor will monitor the temperature of the battery packs, should this temperature rise over 80c,
//the charger will disconnect the charging relay and fast pulse the status led as an added level of protection
//to a hardware fuse, charging will continue after the temperature has reduced to a more conservative 40c.
//when the power switch is turned off,the charger is then reenabled to continue monitoring battery voltage.

//i am using an attiny85 for this project, as it is very cheap, compact and it provides sufficient in/out
//pins for this purpose.

void setup(){
pinMode (0,INPUT); //battery voltage input via voltage divider
pinMode (1,OUTPUT); //charge relay driver output
pinMode (2,OUTPUT); //status led output
pinMode (3,INPUT); //power on/off toggle to disengage charger when in use
pinMode (4,INPUT); //temp sensor input

void loop(){
int batteryLevel = analogRead(0); // sample battery voltage (0-1023(0-5v))
int highVolt = 988; //(4.83v)
int lowVolt = 802; //(3.92v)
int statusLed = 2;  //status indicator led
int powerToggle = 3; //power on/off state input
int tempPin = 4; //temp sensor input
if (batteryLevel >=highVolt){ //if battery level over 28v (4.83v)
digitalWrite (1,LOW); //turn off charging relay
digitalWrite (2,LOW); //turn off status indicator led
float temp; //keep an eye on the ever changing temp of battery
temp = analogRead(tempPin); //read from the analog pin of the temp sensor
for (int i=0; i<=255; i+=5) //0 - 255 range
temp = temp * 0.48828125; //temp sensor vairable for tmp 35-37 sensor
delay (1000); //wait a second between reads

if (batteryLevel <=lowVolt){ //if battery level below 23.50v (3.92v)
digitalWrite (1,HIGH); //turn on charging relay
digitalWrite (2,HIGH); //turn on status indicator led (start charge mode flashing sequence)
delay (1000); //wait for one second
digitalWrite (2,LOW); //take status led state low
delay (300); //wait 300mS
if (powerToggle = HIGH) //if toggle input recieves a 5v signal
digitalWrite (1,LOW); //turn off charging relay
digitalWrite (2,HIGH); //permanantly illuminate status led
//end of loop
4  Using Arduino / Motors, Mechanics, and Power / Re: sliding gate controller on: April 18, 2013, 04:55:16 am
thanks for the reply, am still learning how the code functions, so it was a mistake:) thanks for pointing it out...
as far as stopping simultanious button pressing, my best effort is this part;

if (openbuttonpin == HIGH) {
if (closebuttonpin == HIGH) {

will look into how to program things as a state, this current sketch was based on the "button" example

again thanks


I suggest you rewrite your code as a state machine. The obvious states are Closed, Open, Closing, Opening and Stopped. Each state becomes a case in a switch-statement. Consider carefully how (if at all) you want to react to each of the possible inputs in each state.
5  Using Arduino / Motors, Mechanics, and Power / Re: sliding gate controller on: April 16, 2013, 06:26:01 pm
ok, so,

i have had a decent crack on the basics of how my code should begin...

const int openbuttonpin = A0;\\in/out pin configturation (not varible)
const int closebuttonpin = A1;
const int camswitchpin = A2;
const int tripbeampin = A3;
const int openrelaypin = 2;
const int closerelaypin =3;
const int overloadpin = 4;
const int gatelightpin = 5;

int openbuttonpinstate = 0;\\varying constants
int closebuttonpinstate = 0;
int camswitchpinstate = 0;
int tripbeampinstate = 0;
int overloadpinstate= 0;

void setup () {\\declaring pin operations
pinMode(openbuttonpin, INPUT);\\push to open
pinMode(closebuttonpin,INPUT);\\push to close
pinMode(camswitchpin,INPUT);\\microswitch switches high once per cog rotation
pinMode(tripbeampin,INPUT);\\5v input from an infa red beam switches high on interrupt
pinMode(overloadpin,INPUT);\\5v input from motor thermistor switches high on activation
pinMode(openrelaypin,OUTPUT);\\two polarity switching relays switch motor clockwise
pinMode(closerelaypin,OUTPUT);\\two polarity switching relays switch motor anticlockwise
pinMode(gatelightpin,OUTPUT);\\light supposed to flash on and off when motor runs

void loop (){
openbuttonpinstate = digitalRead(openbuttonpin);
closebuttonpinstate = digitalRead(closebuttonpin);
camswitchpinstate = digitalRead(camswitchpin);
tripbeampinstate = digitalRead(tripbeampin);
overloadpinstate = digitalRead(overloadpin);
if (openbuttonpin == HIGH) {
else { (openbuttonpin == LOW);
if (closebuttonpin ==HIGH) {
else { (closebuttonpin == LOW);
if (openbuttonpin == HIGH) {
if (closebuttonpin ==HIGH) {
if (tripbeampin == HIGH){ \\saftey trip beam
if (tripbeampin == HIGH){
if (overloadpin == HIGH){
if (overloadpin == HIGH){

what do you people think?
does anyone have any info on how to program in a counter code for the camswitch?
6  Using Arduino / Motors, Mechanics, and Power / Re: sliding gate controller on: April 04, 2013, 02:28:34 pm
thanks for that....

but i am a professional, im a registered electrician that has installed many of these without a single fatality!

there are genuine saftey issues, particularly with big heavy steel gates etc, but the one im modding is a lightweight aluminium unit with a motor that is not powerful enough to do any damage to anyone, also im not putting an auto close function into the code so it will only operate when the open or close button is actioned by someone...

7  Using Arduino / Motors, Mechanics, and Power / Re: sliding gate controller on: April 03, 2013, 04:54:30 pm
thanks for the reply,
i am going to use as much of the original parts as possible, as they are already fitted to the unit, and all of which work...
i will have to use transistors to control the relays, a couple of 2n2222a will work with the 12v relay coils and opto isolation has crossed my mind, might use a large transistor to handle things like the flashing light etc with a 4n25 in between the arduino and the relays...

and yes a due is a bit overkill, might just go shopping for a smaller duemillonove board once i get the code finished...

any info on the counter would be great!



8  Using Arduino / Motors, Mechanics, and Power / sliding gate controller on: April 03, 2013, 05:15:59 am
hi all

ive been playing around with a few boards and brushless escs for a while now but still very new to the programming side of things and was wondering if some of you could help me out....

my parents have an old sliding gate system in their driveway that has never functioned since they have owned the house, due to a fault on the control board, the motor and mechanics are fine and have taken it up as a project to get it going using and arduino due i have here...
i think first its best for me to give you the specs of the gate:

12vdc motor

foward (close),reverse(open) is controlled by four relays set up on the dead controller board to change polarity depending on opening or closing, two relays switched together

cam actuated micro switch that pulses x number of times tyo tell the controller where the gate is

infa red beam behind the gate as a saftey feature, should kids etc go near it during operation

ok, my question is here, and i cant seen to find it anywhere else,

is it possible to write a program for arduino that can count say a 3v or 5v pulse from said cam switch to count a pre programmed amount of pulses then turn off the motor in either direction?
also can one program in a "jam override" mode in so if the counts dont come in the specified time, arduino shuts the motor off?

the features im aiming to have in the program are:

cam switch pulse count preprogrammable 5v or 3.3v

pin13 led flashing for each pulse of cam switch

overload/over time/ jam mode timer to cut out motor

flashing led for overload timer

gate open controlled by a green button

flashing led for green button open

gate close controlled by a red button

flashing led for red button close

saftey override 5v low or high input from infared beam

led pinout to show saftey beam interrupt

open/close function from a remote control reciever

flashing led to confirm message recieved from reviever

open direction relay output tied to green button

flashing led on open relay action

close direction tied to red button

flashing led on close action

thermistor to prevent motor overheat cuts both relays when 5v connection through it is broken

flashing led to warn of heat problem


dont ask for much do i ??!!

any help you people can give me would be greatly appreciated, will also share the code when im done testing it!


9  Using Arduino / Motors, Mechanics, and Power / Re: Replacing a turntable AC motor on: April 03, 2013, 04:46:04 am
i collect old akai stuff from the early 70s, turntables, reel to reel and cassette decks for the most part....and have dealt with speed and motor your case, the simplest way around it is to replace the synchronous motor with another if you can find one, speed in these is dependant on frequency and your mains frequency should never vary...unless of course you want fully adjustable speed, in that case you are best to use  something like a small rc brushless esc to control a three phase brushless motor as previously mentioned...and use arduino to feed a pwm signal to the esc, using a 10 k pot to vary speed...

hope this helps! smiley
10  Using Arduino / Programming Questions / Re: help for newbie with existing code for brushless motors on: November 17, 2012, 08:44:33 pm
thanks for the info people, coding badly, you were right, all i did was change what you said and it was away...after much reading i can now write codes like the surprised how quick im picking it up!

11  Using Arduino / Programming Questions / help for newbie with existing code for brushless motors on: November 11, 2012, 02:18:08 am
hi all, my name is mike from new zealand,

i have been experimenting with microcontrollers on and off for a while,however i have not yet done any programming,but i thought id give it a try with aduino to get my feet wet.

i have a question for those that are able to help,

there is a code posted by a user on youtube to run a hdd motor through a model brushless esc,speed controlled via a pot. i have copied the sketch and tried to verify it, however it throws up some error codes,which i cannot copy and paste...i know i need to do some reading on how to program,but i just want to get this setup going to get started, as i plan to build an electric car speed controller that is 4wd and i think this code is a good one to build onto.

would someone be kind enough to run me through what i should be doing to make this operational?

for arguments sake, i could use A0 PIN 9 as an output to the controller and AREF PIN0 as the input for the pot.

thanks so much in advance!


DEMO sketch for arming and running a generic ESC brushless motor controller from an Arduino and using a potentiometer to vary the motor speed.

Tested and working.

19 Feb 2011

#include (Servo.h)

Servo myservo;

int val; //Value for motor speed.
int analogPin = 3; //Potentiometer on pin 3
int servoPin = 9; //ESC on pin 9
int armValue=20; //"ZERO" position for arming ESC. As some wont arm with a '0' value from the arduino. (may need to experiment)

void arm(){ //Arming sequence of sending a minimum or 'joystick zero' for 2 seconds to simulate radio gear is ON and operational. myservo.write(armValue);
delay(2500); //Delay for the ESC to activate. (may need to experiment)

void setup() { Serial.begin(9600);
myservo.attach(servoPin); arm();

void loop(){
int val = analogRead(analogPin); //Make a analogue reading. This is from 0-1023
val = map(val, 0, 1023, armValue, 180); //Scale input to use it with the servo ie from the arming value to 180.
myservo.write(val); //Send servo position - Motor speed to ESC.
Serial.println(val); delay(100);

Pages: [1]