I am trying to post ACS722 current sensor values to Particle cloud. As my coding skills are VERY limited, I am not sure whether the ‘null’ return I am receiving in Particle cloud is due to code or hardware error. Please see my code below:
Would help if I could check on serial monitor as this would eliminate whether the problem is in the publish part or thew actual sensor I suppose, but in this case, I no longer have access the the USB port on the Photon. If I had to, I would probably put my money on a coding error, hehe…
I would really appreciate some help. Thank you for your patience
I am receiving values meaning my board is working at least. Using a custom PCB I designed so was nervous as to whether it was done correctly. Seem it is, pheewww. Now just calibrating the sensor and then all good.
Could you share the circuit schematic being used with the ACS722?
What sort of current (AC or DC) are you measuring?
float acsvalue = 0;
for(int i = 0; i < 1000; i++) {
// average = average + (.0264 * analogRead(A5) -13.51) / 1000;
acsvalue = analogRead(A5);
delay(5);
}
If you are reading alternating current then this code will never work. Try a search for reading and calculating RMS current before you think about how to write the code. The timing of the voltage reading on the output from the ACS722 is incredibly important and using delay(5) just will not work reliably.
If you are reading direct current then there are a few things wrong with this code, the output from analogRead(A5) is not of data type float. Have a look at the reference documentation
analogRead() returns an integer value ranging from 0 to 4095.
If you want to average the value I would suggest something like this;
int avInt = 0;
for (int i = 0; i < 1000; i++) {
// some timing mechanism
avInt += analogRead(A5);
}
float acsvalue = 0.0264 * ((float) avInt / 1000); //C compiler experts may say this isn't necessary to convert an integer to a float - now you have the current as a floating point number
Next Particle.publish("acsvalue", PRIVATE); is not publishing the current reading as a data value - hence why you get 'null'. What you need is something like this: Particle.publish("acsvalue", "0.213", PRIVATE); where 0.213 is the value of acsvalue as a c-string - so you need to convert the float type to a const char* - I will leave you to lookup how to do that!
I am reading AC current indeed. I managed to get the publishing working with the assistance of @muneebr1. I am getting readings fluctuating between 2030 and 2044.
In the sample code the delay was sent to
delay(1)
I just changed it to 5 as I did not want to keep receiving so may readings whilst still trying to figure out the particle.Publish command. Reading through the documentation now to find out how to correctly configure the ACS722 to present accurate readings.
As I mentioned to @muneebr1, coding is not my forte, but the coder on this project is still busy with his code, I simply wanted to test and see whether the PCB I designed was working.
I only have the Eagle schematic of the entire PCB, but will gladly sent it if it will help. Is it safe to assume though that if I am getting readings, the circuit is working fine?
Is it safe to assume though that if I am getting readings, the circuit is working fine?
What was the AC current you were trying to measure?
That depends upon what accuracy you are looking for and what sort of load there is being measured.
The Allegro current sensors are only as accurate as the stability of the voltage supply - so using a LDO linear voltage regulator is fine as there will be no ripple but a switching DC:DC converter is not going to work so well.
On the load side AC is not a perfect sine wave unless you have a perfect resistive load. What would be more useful to understand is to read 100 values into an array and then output them via the Serial port - so you should then see something akin to a sine wave. A DSO on the output of the ACS722 would be a good idea for you to confirm that your readings are a good representation. If your software developer is expert with this stuff then fine.
Fortunately in this case we only need the current sensing to determine on/off (in use/not in use) status of a machine. The supply voltage to the machine is 230V with max current of 5A in this case. In other words, I do not need very 100% accurate readings.
It might be that some devices will draw 1A current whilst others might be operating at 4A. I am basically looking for a range of values resembling “off” or "not in use" status of a machine and then of course a range of values resembling “on” or “in use” status. I will then use these to send to Ubidots dashboard. where we will log all the data.
You could also try using a bridge recitifier to convert the AC signal to DC toss in a capacitor to smooth things out and use an LTC2945 to read the voltage and send it out via I2C …You lose about .5VDC on the Bridge but you can add it later for a more accurate reading
Thank you for your reply. I just had a look at one of your previous posts. I wish I have seen this before I started
I went with the ACS722 due to the good reviews it receives and the initially the code seemed simple enough. Of course I never realised all code examples was all done measuring DC and not AC. Nevertheless, I persisted and managed to get the results as per the image below:
I used a 1A light bulb to simulate load at 220V. I am improving my code to measure at increments of 1ms, taking 500 readings and then calculating the current. Finally posting every 1s as permissible in Particle Cloud.
I will post my project as soon as I am done. I tried several PCB manufacturers but for some reason they seem much more expensive, so I went with PCBWay again. Happy with their quality aso far, even with this PCB containing both HV and LV on the same (and quote small) board.
Thanks again for your reposes, it is much appreciated!
Hey Freidi if you want a lower cost manufacture of total PCB build try freya@quint-tech.comfreya@quint-tech.com;she makes our boards out of china for LoRa devices prices are the best ive seen so far
If you are only trying to detect AC voltage present then you could try using an opto coupler - an MC400 or the LTC2945. The MC400 does not require rectification of the AC but you do need to be careful how you control the current through it. I replied on a topic recently if you search for either IC.
Thank you again for your reply and advice. I will most certainly look into this for future designs. As for now, I already made the PCB’s for the ACS722, so will have to stick to that. It seems be to working well so far, or from what I can see at least
I watched a couple of videos on the LTC2945 component. It seems that in my case it would not work as the current I am working with is 220V and up to 5A. It seems the max voltage is 80V but does seem easier to work with though