Need help with Arduino - RJB INDUSTRIES
- RJB INDUSTRIES
- Specialist
- Posts: 144
- Joined: Fri Sep 09, 2011 5:49 pm
Hello everyone,
I have an electronic schematic and I need help on the code, (arduino code), I load the image and if you know arduino code please help me.
The project is an Electronic Electroscope and I connect it with the arduino, please take a look.
RJB INDUSTRIES
I have an electronic schematic and I need help on the code, (arduino code), I load the image and if you know arduino code please help me.
The project is an Electronic Electroscope and I connect it with the arduino, please take a look.
RJB INDUSTRIES
- POLAND_SPUD
- Captain
- Posts: 5402
- Joined: Sat Oct 13, 2007 4:43 pm
- Been thanked: 1 time
You aren't very specific you know. You didn't write where you got the code or whether you know what it is supposed to do
Ohh and if I were you I'd send the results through serial port to the computer. Here is an example sketch included in the arduino IDE. You can test the circuit with it - it should return a value ranging from 0 to 1023. Experiment with different charges and distances and note the values you get.
Ohh and if I were you I'd send the results through serial port to the computer. Here is an example sketch included in the arduino IDE. You can test the circuit with it - it should return a value ranging from 0 to 1023. Experiment with different charges and distances and note the values you get.
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor
This example code is in the public domain.
*/
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
Children are the future
unless we stop them now
unless we stop them now
- Technician1002
- Captain
- Posts: 5189
- Joined: Sat Apr 04, 2009 11:10 am
To save money, the processor can be replaced with an LM339.
If you are intending to use it for measuring an RF field strength, you will want an active detector to convert RF to DC along with some gain stages, unless you need near field detection only.
If this is for detecting electrostatic charges or a monitor for an Ion generator, then overvoltage protection is recommended along with a proper precision voltage divider and very low leakage igfet front end.
The 2N3819 is the wrong device to use for DC electrostatic field measurements.
If this is for tracking lost projectiles, a high gain, tuned front end is recommended for sensitivity, possibly a superhert front end. Otherwise the extremes of signal strength will create No signal to pegged signal conditons near the device to be tracked. Any significant distance will result in no signal. Typical fox hunting recievers have sensitivites in the microvolt range and are tuned to be selective of the desired signal.
Feeding RF directly to the analog in pin may be a problem for you if you are feeding a signal near 1/3 the divided clock frequency or above.
Snipped from a forum
What is your application?
If you are intending to use it for measuring an RF field strength, you will want an active detector to convert RF to DC along with some gain stages, unless you need near field detection only.
If this is for detecting electrostatic charges or a monitor for an Ion generator, then overvoltage protection is recommended along with a proper precision voltage divider and very low leakage igfet front end.
The 2N3819 is the wrong device to use for DC electrostatic field measurements.
If this is for tracking lost projectiles, a high gain, tuned front end is recommended for sensitivity, possibly a superhert front end. Otherwise the extremes of signal strength will create No signal to pegged signal conditons near the device to be tracked. Any significant distance will result in no signal. Typical fox hunting recievers have sensitivites in the microvolt range and are tuned to be selective of the desired signal.
Feeding RF directly to the analog in pin may be a problem for you if you are feeding a signal near 1/3 the divided clock frequency or above.
Snipped from a forum
With this in mind, it won't work with AM Radio frequencies or anything in the Shortwave bands, or above such as the RC bands. It seems to be limited to Audio Frequencies on the analog input.The ADC clock is 16 MHz divided by a prescale factor. The prescale is set to 128 (16MHz/128 = 125 KHz) in wiring.c. Since a conversion takes 13 ADC clocks, the sample rate is about 125KHz/13 or 9600 Hz.
What is your application?
Last edited by Technician1002 on Mon Mar 11, 2013 10:26 am, edited 1 time in total.
- mark.f
- Sergeant Major 4
- Posts: 3638
- Joined: Sat May 06, 2006 11:18 am
- Location: The Big Steezy
- Has thanked: 58 times
- Been thanked: 61 times
- Contact:
It looks like a high gain darlington setup using a touch plate/probe on the first transistor's base. But the code looks a little silly. If a is an integer 0 to 255 representing the voltage read from the darlington, all the led's will light up when the voltage is greater than a... you need to set a different value (or increment a by a fraction of 256) for each of the IF statements shown, otherwise all the LED's will light up regardless of reading.
For instance:
PS can tell you I'm no Arduino expert, but that's what I think.
EDIT: You could also use a single LED and dim it according to the voltage on the electroscope pin. Use analogWrite to the led with an integer of ~36 to 255 and "map" that to the Electroscopes read of 0 to 255. The number 36 will vary with the LED's breakdown voltage.
For instance:
Code: Select all
Electroscopio = analogRead(PinoElectroscopio); a=51;
if(Electroscopio > a){
digitalWrite(ledPin1, HIGH);
}
if(Electroscopio > a + 51){
digitalWrite(ledPin1, ledPin2, HIGH);
}
if(Electroscopio > a + 102){
digitalWrite(ledPin1, ledPin2, ledPin3, HIGH);
}
if(Electroscopio > a + 153){
digitalWrite(ledPin1, ledPin2, ledPin3, ledPin4, HIGH);
}
if(Electroscopio > a + 204){
digitalWrite(ledPin1, ledPin2, ledPin3, ledPin4, ledPin5, HIGH);
}
EDIT: You could also use a single LED and dim it according to the voltage on the electroscope pin. Use analogWrite to the led with an integer of ~36 to 255 and "map" that to the Electroscopes read of 0 to 255. The number 36 will vary with the LED's breakdown voltage.
- POLAND_SPUD
- Captain
- Posts: 5402
- Joined: Sat Oct 13, 2007 4:43 pm
- Been thanked: 1 time
The thing is that he is supposed to manually enter integer values in place of all the 'a' in the in statements.PS can tell you I'm no Arduino expert, but that's what I think.
He can do that but he doesn't know yet what values he can get. The ADC on arduino is 10bit (not 8bit) so at least theoretically it can be 0-1023, but you can't assume that his highest readings will be 1023.
If he uses the example code I posted earlier he can see how the circuit responds to charges and what values he receives under what circumstances and then manually enter values that make the sensor most useful.
ohh and note that the code you posted isn't complete as you only set the LED pins HIGH but there is nothing to set them LOW
Code: Select all
Electroscopio = map(analogRead(PinoElectroscopio), 0, 1023, 0, 5);
if(Electroscopio > 1){
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, ledPin3, ledPin4, ledPin5, !HIGH);
}
if(Electroscopio > 2){
digitalWrite(ledPin1, ledPin2, HIGH);
digitalWrite(ledPin3, ledPin4, ledPin5, !HIGH);
}
if(Electroscopio > 3){
digitalWrite(ledPin1, ledPin2, ledPin3, HIGH);
digitalWrite(ledPin4, ledPin5, !HIGH);
}
if(Electroscopio > 4){
digitalWrite(ledPin1, ledPin2, ledPin3, ledPin4, HIGH);
digitalWrite(ledPin5, !HIGH);
}
if(Electroscopio > 5){
digitalWrite(ledPin1, ledPin2, ledPin3, ledPin4, ledPin5, HIGH); }
delay (50);
Children are the future
unless we stop them now
unless we stop them now
- mark.f
- Sergeant Major 4
- Posts: 3638
- Joined: Sat May 06, 2006 11:18 am
- Location: The Big Steezy
- Has thanked: 58 times
- Been thanked: 61 times
- Contact:
Cool. As I said I'm no expert with Arduino, only have basic knowledge of things like C, RISC assembly, etc. I'm sure it's simpler than both once you learn the language.
Good point on the calibration too. I guess I was assuming he could adjust the darlington portion of the circuit to provide a useful output range for the arduino (0-5v).
Good point on the calibration too. I guess I was assuming he could adjust the darlington portion of the circuit to provide a useful output range for the arduino (0-5v).
- RJB INDUSTRIES
- Specialist
- Posts: 144
- Joined: Fri Sep 09, 2011 5:49 pm
Hello again, thanks to all of you, I really appreciate yours advices and your help, this project will allow me "measure" the electrostatic charge on bodies.
If someone could, if is really sure about it, write here all the code, since the begin, to do this, I would really appreciate and recognise the help.
The values are these:.
const int PinEletroscope = 0;
int Eletroscope = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
Eletroscope = analogRead(PinEletroscope);
if (Eletroscope > 290){
RJB INDUSTRIES
If someone could, if is really sure about it, write here all the code, since the begin, to do this, I would really appreciate and recognise the help.
The values are these:.
const int PinEletroscope = 0;
int Eletroscope = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
Eletroscope = analogRead(PinEletroscope);
if (Eletroscope > 290){
RJB INDUSTRIES
- Technician1002
- Captain
- Posts: 5189
- Joined: Sat Apr 04, 2009 11:10 am
Your input circuit still needs work.
1 It needs circuit protection from ESD.
2 It needs high impedance besides high darlington gain.
3 It needs DC offset bias to measure both + and - charges.
4 It needs RFI protection
1 You need current limitation on the input to prevent a static charge from destroying your input. A high value 1-10 Megohm HV resistor is recommended. Add steering diodes so any ESD into the input is safely shunted to ground or the +VSS supply rail.
2 Replace the first transistor of your darlington pair with a small signal IGFET. No sense having the circuit discharge your test subject and give a false zero. You will want an input impedance of 100 Megohm or higher.
3 Bias the source of your IGFET darlington pair so the output is 50% on your A/D converter so + and - charges can be measured.
4 Add a filter loop in a negative feedback in your amplifier with a time constant of about 0.1 seconds for a roll off frequency of about 10 HZ. This is to keep the local AM radio station out of your amplifier.
A saturated high gain amp will cause wierd readings as people walk past windows, open doors, etc that is not related to the ES field. These gremlins are hard to recognise without the proper test equipment.
With the high gain, you may also need a servo feedback loop on the bias as it may work very well as a thermometer without one.
For more info on the analog portion if you need to do this, pick up a copy of the "Op Amp Cookbook" http://www.analog.com/library/analogdia ... dbook.html
This chapter deals with driving Analog To Digital Converters.
http://www.analog.com/library/analogdia ... _final.pdf
1 It needs circuit protection from ESD.
2 It needs high impedance besides high darlington gain.
3 It needs DC offset bias to measure both + and - charges.
4 It needs RFI protection
1 You need current limitation on the input to prevent a static charge from destroying your input. A high value 1-10 Megohm HV resistor is recommended. Add steering diodes so any ESD into the input is safely shunted to ground or the +VSS supply rail.
2 Replace the first transistor of your darlington pair with a small signal IGFET. No sense having the circuit discharge your test subject and give a false zero. You will want an input impedance of 100 Megohm or higher.
3 Bias the source of your IGFET darlington pair so the output is 50% on your A/D converter so + and - charges can be measured.
4 Add a filter loop in a negative feedback in your amplifier with a time constant of about 0.1 seconds for a roll off frequency of about 10 HZ. This is to keep the local AM radio station out of your amplifier.
A saturated high gain amp will cause wierd readings as people walk past windows, open doors, etc that is not related to the ES field. These gremlins are hard to recognise without the proper test equipment.
With the high gain, you may also need a servo feedback loop on the bias as it may work very well as a thermometer without one.
For more info on the analog portion if you need to do this, pick up a copy of the "Op Amp Cookbook" http://www.analog.com/library/analogdia ... dbook.html
This chapter deals with driving Analog To Digital Converters.
http://www.analog.com/library/analogdia ... _final.pdf
- jimmy101
- Sergeant Major 2
- Posts: 3206
- Joined: Wed Mar 28, 2007 9:48 am
- Location: Greenwood, Indiana
- Has thanked: 6 times
- Been thanked: 18 times
- Contact:
There is a very simple electrometer circuit that might be better than the Darlington pair. It won't properly handle both possible field potentials (though swapping the antenna with the ground, ground is basically the 9V battery shell, will get the two polarities.) To get both polarities a pair of FETs, one on each side of the 9V battery, each with a small value resistor and each connected to its own Arduino analog input pin, might get both polarities.
http://amasci.com/emotor/chargdet.html
The (optional) 1Meg resistor is Tech's protection to keep a static discharge from frying the FET (or the Arduino).
Be a VERY good idea to protect the Arduino by running a diode from the signal line to the Arduino + supply and another diode to the Arduino ground. Both diodes are reverse biased (from the input line to the + supply and from ground to the input line).
Put a small value resistor (perhaps 100 Ohm) in series with the LED and use a voltmeter to measure the voltage drop in the presence of various electrostatic fields. That should give the info you need to properly calibrate the Arduino code.
The brain-dead circuit is based on the maximum current of the MPF102 jFET of 20mA (hence a current limiting resistor isn't needed even though it uses a 9V battery to power a LED).
The simple jFET circuit is phenomenally sensitive and might be too sensitive for your needs.
You might want to use a Log scale on the outputs from the Arduino.
http://amasci.com/emotor/chargdet.html
The (optional) 1Meg resistor is Tech's protection to keep a static discharge from frying the FET (or the Arduino).
Be a VERY good idea to protect the Arduino by running a diode from the signal line to the Arduino + supply and another diode to the Arduino ground. Both diodes are reverse biased (from the input line to the + supply and from ground to the input line).
Put a small value resistor (perhaps 100 Ohm) in series with the LED and use a voltmeter to measure the voltage drop in the presence of various electrostatic fields. That should give the info you need to properly calibrate the Arduino code.
The brain-dead circuit is based on the maximum current of the MPF102 jFET of 20mA (hence a current limiting resistor isn't needed even though it uses a 9V battery to power a LED).
The simple jFET circuit is phenomenally sensitive and might be too sensitive for your needs.
You might want to use a Log scale on the outputs from the Arduino.

- POLAND_SPUD
- Captain
- Posts: 5402
- Joined: Sat Oct 13, 2007 4:43 pm
- Been thanked: 1 time
ohh speaking of 9V batteries... why aren't the grounds common ?
Children are the future
unless we stop them now
unless we stop them now
- mobile chernobyl
- Corporal 3
- Posts: 756
- Joined: Sun Dec 03, 2006 11:53 am
- Been thanked: 7 times
He's using the Tesla version of ground. 

Hi All
i also need help on an Arduino project for SF.
I am prototyping a 25mm launcher that uses a stepper motor to index the magazine and then fire some relays to do the actual launch and reload.
None of this codes is mine, it is all screen scrape and I will freely admit it is a long time since i did coding in FORTRAN in High School. So..........
I have an UNO hooked up to a KTA179 uni-polar stepper drive, this is to index a rotary magazine. At this point the micro-controller is simply generating a stream of pulses on D13 so the KTA179 will step as instructed.
My issue is triggering the loop of steps; I have a button hooked up on D2 that when pressed should cause the main loop to run. The code needs to continuously poll D2 state and if that state changes then fire the main loop. It also needs to continue to run the loop until the if/then countdown expires then go back to monitoring the state of D2.
What should ultimately happen is:
Monitor the status of the button on D2
If it has been pressed, do this sequence of events, write D3 high for 50ms, then write D4 high for 100ms, then the run the loop to generate the stepper pulses
Go back to monitoring the status of D2
What DOES happen is that when I press the button, D13 goes high and the if/then countdown step loop starts, BUT if I let go of the button after say 12 of the 25 steps have been generated then the stepper stops. If I press the button again I get another chunk of steps and so on until all 25 steps have been sent to the motor. Nothing happens after that and the only way I can get the button to trigger another stream is to reset the Arduino.
I know this is long and baby stuff for most but any help would be appreciated.
Code below
I would describe this as a nested loop, though I'm not sure if that applies in Arduino.
Infinite Loop
Has button been pressed, does not matter if still pressed, just did it get pressed for some period of time
If true then
a:] Write D3 HIGH and wait x delay then D3 LOW
b: Write D4 HIGH and wait y delay then D4 LOW
c: Run finite loop that writes D2 HIGH/LOW z number of times with fixed delay between each HIGH/LOW
d: Do something else to a Digital pin, probably write HIGH to fire another relay
Go back to the top and see is the button has been pressed again.
Basically the plan it to have relays connected to the digital outputs (got that covered using a dedicated 8 relay board from eBay, tested and working fine).
So, operator presses a button and the relays get fired to activate some solenoid valves. We wait a bit then send some pulses to the stepper controller to rotate the magazine by a preset amount.
Now we are ready to look for another button press.
Hope that makes sense.
i also need help on an Arduino project for SF.
I am prototyping a 25mm launcher that uses a stepper motor to index the magazine and then fire some relays to do the actual launch and reload.
None of this codes is mine, it is all screen scrape and I will freely admit it is a long time since i did coding in FORTRAN in High School. So..........
I have an UNO hooked up to a KTA179 uni-polar stepper drive, this is to index a rotary magazine. At this point the micro-controller is simply generating a stream of pulses on D13 so the KTA179 will step as instructed.
My issue is triggering the loop of steps; I have a button hooked up on D2 that when pressed should cause the main loop to run. The code needs to continuously poll D2 state and if that state changes then fire the main loop. It also needs to continue to run the loop until the if/then countdown expires then go back to monitoring the state of D2.
What should ultimately happen is:
Monitor the status of the button on D2
If it has been pressed, do this sequence of events, write D3 high for 50ms, then write D4 high for 100ms, then the run the loop to generate the stepper pulses
Go back to monitoring the status of D2
What DOES happen is that when I press the button, D13 goes high and the if/then countdown step loop starts, BUT if I let go of the button after say 12 of the 25 steps have been generated then the stepper stops. If I press the button again I get another chunk of steps and so on until all 25 steps have been sent to the motor. Nothing happens after that and the only way I can get the button to trigger another stream is to reset the Arduino.
I know this is long and baby stuff for most but any help would be appreciated.
Code below
Code: Select all
const int StepPin = 13; // the number of the LED pin
const int ButtonPin = 2; // the number of the pushbutton pin
int StepCount = 0; // How many times should we loop before stopping? (0 for no stop)
//int buttonState = 0; // variable for reading the pushbutton status
int CurrButtonState = LOW;
int PrevButtonState = LOW;
void setup() {
// initialize the Stepper Driver pin as an output:
pinMode(StepPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(ButtonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
CurrButtonState = digitalRead(ButtonPin);
if (CurrButtonState != PrevButtonState) {
// turn Stepper Pin on:
if (CurrButtonState == HIGH)
if (StepCount <=25)
{ // Loop the number of steps above, check how many needed to rotate drum
StepCount++;
digitalWrite(StepPin, HIGH);
delay(50);
digitalWrite(StepPin, LOW);
delay(50);
}
else {
// turn LED off:
digitalWrite(StepPin, LOW);
PrevButtonState = CurrButtonState;
}
}
}
Infinite Loop
Has button been pressed, does not matter if still pressed, just did it get pressed for some period of time
If true then
a:] Write D3 HIGH and wait x delay then D3 LOW
b: Write D4 HIGH and wait y delay then D4 LOW
c: Run finite loop that writes D2 HIGH/LOW z number of times with fixed delay between each HIGH/LOW
d: Do something else to a Digital pin, probably write HIGH to fire another relay
Go back to the top and see is the button has been pressed again.
Basically the plan it to have relays connected to the digital outputs (got that covered using a dedicated 8 relay board from eBay, tested and working fine).
So, operator presses a button and the relays get fired to activate some solenoid valves. We wait a bit then send some pulses to the stepper controller to rotate the magazine by a preset amount.
Now we are ready to look for another button press.
Hope that makes sense.
- POLAND_SPUD
- Captain
- Posts: 5402
- Joined: Sat Oct 13, 2007 4:43 pm
- Been thanked: 1 time
That condition is true whenever the state of the button changesif (CurrButtonState != PrevButtonState) {
you put this inside it
which is true only if the state is HIGHif (CurrButtonState == HIGH)
which means that the arduino won't generate the pulses if the state of the button isn't high
which is precisely the reason why you get this >>
BUT if I let go of the button after say 12 of the 25 steps have been generated then the stepper stops.
Moreover since you're not setting the StepCount to zero again it is a let say 15 when you press the button again
which is why this happens ->>
If I press the button again I get another chunk of steps and so on until all 25 steps have been sent to the motor.
Because you need to make a condition that resets StepCOunt to zero when the StepCount is equal 25Nothing happens after that and the only way I can get the button to trigger another stream is to reset the Arduino.
Children are the future
unless we stop them now
unless we stop them now
Got it fixed, just needed to look at it with fresh eyes
Thanks
Thanks
Code: Select all
const int StepPin = 13; // the number of the Stepper Motor signal pin
const int ButtonPin = 2; // the number of the pushbutton pin
const int RelayPin1 = 3; // the number of the first relay
const int RelayPin2 = 4; // the number of the second relay
int CurrButtonState = LOW;
void setup() {
// initialize the Stepper Driver pin and the relay pins as outputs:
pinMode(StepPin, OUTPUT);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(ButtonPin, INPUT);
Serial.begin(115200);
}
void loop(){
// read the state of the pushbutton value:
CurrButtonState = digitalRead(ButtonPin);
if (CurrButtonState == HIGH) //Has the button been pushed ?
{digitalWrite(RelayPin1, HIGH); //Fire the solenoid valve and reset the pin
Serial.println("Relay 1 fired");
delay(500);
digitalWrite(RelayPin1, LOW);
digitalWrite(RelayPin2, HIGH); //Fire the tracking motor for 2 seconds to do several complete revolutions and reset the pin
Serial.println("Relay 2 fired");
delay(2000);
digitalWrite(RelayPin2, LOW);
for (int StepCount = 1; StepCount < 101 ; StepCount++){
Serial.print("Step Count = ");Serial.println(StepCount); //Remove once debugging finished
digitalWrite(StepPin, HIGH); // Send 100 pulses to the stepper controller which equals 180 degrees rotation
delay(5);
digitalWrite(StepPin, LOW);
delay(5);
}
}
else
{
Serial.println("Waiting...........");
}
}
- POLAND_SPUD
- Captain
- Posts: 5402
- Joined: Sat Oct 13, 2007 4:43 pm
- Been thanked: 1 time
sometimes you just need someone to have a look at your code
Care to post some pics of the gun ?
Care to post some pics of the gun ?
Children are the future
unless we stop them now
unless we stop them now