|
Post by dimtim on Oct 23, 2017 18:44:56 GMT
Evening All, Been a bit quite on the Arduino side as been finishing off my Tug boat for winter (now the subs packed away for winter ) and the Light house built for the club. I got been coming up with idea for the tug to be controlled by arduino. Lights Sound Anchor What I'm scratching my head over is the following. built a smoker (water vapour style). But want it to smoke lots mid throttle and the slow the fan down at full throttle(forward and Reverse). All i keep coming up with is the following, ie If >1500 go to loop 1 if <1500 go to loop 2 loop1 & loop 2 = slow the fan down. is there a better way of doing this. cheers Tim
|
|
|
Post by c3po on Oct 23, 2017 19:01:02 GMT
Hi Tim,
Thinking on my feet - always dangerous
I think you could use several "map" functions not overlapping parameters
FanSpeed = map(ThrottleValue,1500,1700, FanX, FanY)
FanSpeed = map(ThrottleValue,1701,1900,X,Y)
Never tried this but the logic seems sense
value: the number to map
fromLow: the lower bound of the value's current range
fromHigh: the upper bound of the value's current range
toLow: the lower bound of the value's target range
toHigh: the upper bound of the value's target range
|
|
|
Post by dimtim on Oct 23, 2017 19:50:27 GMT
cheers c3po. will have play this week. makes sense (i think )
|
|
|
Post by dimtim on Oct 29, 2017 15:09:05 GMT
Hi C3PO
just working on this today,
two question FanX, FanY ---- Fanx would be the 255 and FanY but be 0 ?
the two maps, wouldn't they be 1000, 1500 & 1501 too 2000 ?
if is there a reason for it to be the they you put above.
I've got this written but not working(any ideas) , just got a led wire up instead of the fan
int ThrottleValue = A0; // select the input pin for the potentiometer int FanSpeed = 10; // select the pin for the LED int FanX = 255; int FanY = 0; int val = 0;
void setup() { pinMode(FanSpeed, OUTPUT); pinMode(ThrottleValue, INPUT); FanSpeed = map(ThrottleValue,1500,1700, FanX, FanY); FanSpeed = map(ThrottleValue,1701,1900,FanX,FanY); }
void loop() {
analogWrite(FanSpeed,val); }
cheers Tim
|
|
|
Post by dimtim on Nov 26, 2017 14:17:07 GMT
still playing around but having a wierd issue.
from mid throttle to top the led full to dull(not off ??)
but from mid throttle > bottom throttle it goes full on bottom throttle and dull on mid.
any ideas cheers .
int rc1 = 3; //input rx int fan1=10; //output for fan int ThrottleValue; int ThrottleValue1;
int fan; int FanX = 255; int FanY = 0;
void setup() { Serial.begin(9600); pinMode(rc1, INPUT); pinMode(fan1, OUTPUT);
} void loop() { ThrottleValue = pulseIn(rc1, HIGH); ThrottleValue1 = pulseIn(rc1, HIGH);
fan = map(ThrottleValue,1485,1011, FanX, FanY); //fan = map(ThrottleValue,2000 ,1487, FanY, FanX);
analogWrite(fan1,fan); }
|
|
|
Post by dimtim on Nov 26, 2017 16:45:14 GMT
alot of head banging i finally got it working int in1 = 10;
//the following are all ~PWM capable ports int enable1 = 10; int rc_channel4 = 3;
void setup() { pinMode(rc_channel4, INPUT); pinMode(in1, OUTPUT); pinMode(enable1, OUTPUT); Serial.begin(9600); }
void loop() { int pwm = 0; int rc4 = pulseIn(rc_channel4, HIGH, 25000); Serial.print(" raw channel4: "); Serial.print(rc4); if(rc4==0){ analogWrite(enable1, 0); } else if(rc4 > 1485){ //right stick pwm = map(rc4, 1485, 1970, 255, 80); analogWrite(enable1, pwm); } else if(rc4 < 1480){ pwm = map(rc4, 1480, 986, 255, 80); analogWrite(enable1, pwm); }else{ analogWrite(enable1, 200); } }
Video
|
|
|
Post by c3po on Nov 26, 2017 16:47:52 GMT
Tim,
I think this will be a step by step
Map value - fan = map(ThrottleValue,2000,1000,255,0);
And unless I am mistaken you are analogue writing to DIGITAL pin 10?
Try using A0-A5
Doh!
Let us know if that makes any difference.
Regards Jonathan
|
|
|
Post by dimtim on Nov 26, 2017 16:49:46 GMT
oh haddn't noticed that doh!, will change it and give it a go. cheers
|
|
|
Post by c3po on Nov 26, 2017 16:51:20 GMT
Actually - I think this may be my mistake - typing without thinking - you are OUTPUTTING not INPUTTING (READING) - Double Doh
|
|
|
Post by dimtim on Nov 26, 2017 16:57:08 GMT
cheers, posted a video on my facebook page showing it working. just got to add the lights control and should be finished to install in the boat.
|
|
|
Post by dave on Nov 26, 2017 17:21:36 GMT
simplest way to control the fan, if using a brushed motor, bridge rectifier on motor terminals, feeding the fan.
|
|
|
Post by dimtim on Nov 26, 2017 17:26:25 GMT
Hi Dave, did that before and worked well. but I wanted to have little on idle and then a lot and then little on full throttle
|
|
|
Post by dave on Nov 26, 2017 17:31:27 GMT
This is the pcb I put together for the Imara boat. top left: relay to switch smoke on. next: 12v to 30v buck. next: PICAXE chip, don't groan... right top/top: smoke generator 1 right top/mid: smoke generator 2 comes in on full throttle right top/ lower: pwm fan Attachments:
|
|
|
Post by dimtim on Nov 26, 2017 17:32:55 GMT
thats the next thing i need to learn is make pcb board,
looks neat
|
|
|
Post by dave on Nov 26, 2017 17:34:10 GMT
code for picaxe, but easy to transfer to Arduino...
#picaxe 20x2
b1=3
w3=0
w3=599 main:
;=== switch smoke ON/OFF === pulsin b.7,1,w2 if w2>300 then high c.0 else low c.0 endif ;========================== ;=== throttle input ======= ;=== convert to 799 max for fam === pulsin b.6,1,w3 if w3>295 then w4=w3-295 max 100 else w4=295-w3 max 100 endif if w4>14 then b1=255 endif if w4<15 then let w4=0:endif ; min cutoff w5=w4*8 max 799
if b1=255 then w5=w5 min 250 ; minimum fan speed pwmout C.5, 199, w5 ; fan output endif if b1>3 and b1<255 then pwmout C.5, 199,200 endif
if b1<2 then pwmout C.5, 199, 0 endif dec b1 if b1<100 then ; fan run on time b1=1 endif
;========================= ; = smoke 1 on/off ====== if w4>15 then high c.3 else low c.3 endif ;======================== ;=== smoke 2 on/off ==== if w4>55 then high c.2 else low c.2 endif ;======================= ;== running lights =====
pulsin b.5,1,w6 if w6>300 then high b.0 high b.2 else low b.0 low b.2 endif ;===================== ;=== cabin lights ==== pulsin b.4,1,w7 if w7>300 then high b.1 high b.3 else low b.1 low b.3 endif ;===================
goto main
|
|