I need help with my project


Hi, so this is my circuit and I have no idea it doesn't show up.

#include <LiquidCrystal.h>

// Initialize LCD (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Analog input pins
const int V3_PIN = A0;  // First voltage point
const int V4_PIN = A1;  // Second voltage point

// Resistor values
const float R1 = 220.0;  // Current limiting resistor
const float R2 = 0.1;    // Shunt resistor

void setup() {
  lcd.begin(16, 2);
  lcd.print("DC Ammeter");
}

void loop() {
  // Read voltages across shunt resistor
  float v3 = (analogRead(V3_PIN) * 5.0) / 1024.0;
  float v4 = (analogRead(V4_PIN) * 5.0) / 1024.0;
  
  // Calculate voltage drop across shunt
  float voltageDrop = abs(v3 - v4);
  
  // Calculate current using Ohm's Law
  float current = voltageDrop / (R2);
  
  
  // Display current with 2 decimal places
  lcd.setCursor(0, 1);
  lcd.print("I = ");
  lcd.print(current, 2);  
  lcd.print(" A    ");
  
  delay(1000);
}

this is my code, I'm sorry for the mistakes because I'm a novice. Please guide me. I need to design an ammeter using Arduino Uno that can measure current flow ranges from 0 A to 1 A with an accuracy of 2 decimal places.

As your topic has nothing to do with the Arduino Project itself it has been moved to a more relevant forum category

What do you need help with exactly ?
Please describe what your project should and what it actually does, if anything

The circuit isn't clear enough, you have too many wires overwriting.
If you are using Tinkercad you should share the project link to let us directly open it (and copy). Or, better, switch to WokWi, much better than Tinkercad Circuits for many reasons, first of all it's easier to share.
Then, you should describe what you're trying to achieve, and exactly what you mean with "doesn't show up" (what that project does or don't).

PS: and to make things simpler, I suggest you (not only on simulators but also in real life) to use I2C displays, as they use less pins and connections and are easier to be defined.

Sorry. This is the link Circuit design Ammeter - Tinkercad

I'm want to measure current from the circuit like a real ammeter does. From my understanding, the arduino can only read voltage so I need to use Ohm's Law. The problem is, my lcd doesn't show what the power supply shows which is 22.7mA when I have R1 is 220ohm and R2 is 0.1 ohm. The reason for the two resistor is because it's just what we've been told to do.

Thanks for the suggestion for the display. I'll keep that in mind.

I'm sorry but I think it isn't the correct way to detect 5V DC 0-1A current .

Arduino reads the voltage applied to pin A0 and convert it into an integer value between 0 and 1023, and you here have a divider made up by a 220 Ohm (the "load") and a 0.1 Ohm: what voltage level are you expecting to get from there? Applying 5V to that divider with 220 Ohm as load, the A0 you'll get just 0.002 V so the voltage value you read will be always 0 or 1 (the ADC has fluctuations due to interferences and converter precision), not more.
Add a multimeter and see by yourself:

To be able to read a value proportional to the current up to 1A over 5V DC, IMO you need a better A/D converter than the one you have onboard because you need to be able to read voltages up to a few 100's of mV and the onboard ADC can't give you enough precision/range.

How do you think a real ammeter measure amps? :slight_smile:

1 Like

What does the pot thing do, it appears it will short the power supply probably damaging either the Arduino or the pot. A schematic would be much easier to follow and do not run wires on top of each other.

Maybe you should try something more easy, a ready made module.

Please, follow the steps of this tutorial:
1. Build the following circuit (Fig-1) around Arduio UNO without LCD.


Figure-1:

2. Upload the following tested (with 5V -- 2.2k -- A0 -- 2.2k -- GND network) sketch to show the current on Serial Monitor at 1-sec interval.

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  int adcValue = analogRead(A0); //measure voltage proportional to I
  Serial.println(adcValue, DEC);  //debug
  float milliVolt = (5.0/1023.0)*adcValue*1000; //convert adc reading to mV
  float milliAmp = milliVolt/220.0; //converting volt into mA
  Serial.print("Current, I =  ");  //show: Current, I = xx.xx mA
  Serial.print(milliAmp, 2);
  Serial.println(" mA");
  delay(1000);
}

3. Does Serial Monitor show the correct value of current? If yes, then connet your LCD and add codes with the sketch of Step-2 to show current on LCD.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.