0% found this document useful (0 votes)
90 views

Arduino Injector Control

This code defines pins for a potentiometer, LED, and transistor. It reads the potentiometer value and uses it to calculate on and off delays for pulsing the LED, with the delays varying from 20-500ms based on the potentiometer position. The potentiometer value is mapped between 0.04 and 1 to control the pulse widths.

Uploaded by

Teguh Priyono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Arduino Injector Control

This code defines pins for a potentiometer, LED, and transistor. It reads the potentiometer value and uses it to calculate on and off delays for pulsing the LED, with the delays varying from 20-500ms based on the potentiometer position. The potentiometer value is mapped between 0.04 and 1 to control the pulse widths.

Uploaded by

Teguh Priyono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

#define fetPin 2
2. #define potPin A0
3. #define ledPin 13
4.  
5. #define highms 500
6. #define lowms 20
7.  
8. float pot = 0;
9. float total = 0;
10. float ondelay = 0;
11. float offdelay = 0;
12.  
13. void setup()
14. {
15.   //Serial.begin(9600);
16.   pinMode(fetPin, OUTPUT);
17.   pinMode(ledPin, OUTPUT);
18.   pinMode(potPin, INPUT);
19.   total = highms-lowms;
20. }
21.  
22. void loop()
23. {
24.   pot = analogRead(potPin);
25.   pot /= 50.0;
26.   //pot = 1 - pot;
27.   if(pot > 1) pot = 1;
28.   if(pot < 0.04) pot = 0.04;
29.  
30.   offdelay = total*pot*pot;
31.   ondelay = total*pot-offdelay;
32.  
33.   //Serial.print(pot);
34.   //Serial.print("   ");
35.   //Serial.print(ondelay);
36.   //Serial.print("   ");
37.   //Serial.println(offdelay);
38.   digitalWrite(ledPin, 1);
39.   digitalWrite(fetPin, 1);
40.   delay(ondelay);
41.   digitalWrite(ledPin, 0);
42.   digitalWrite(fetPin, 0);
43.   delay(offdelay);
44. }

You might also like