

This document provides a detailed overview of a circuit that includes an Arduino UNO, an ADS1115 ADC, an ACS712 current sensor, a potentiometer, toggle switches, a push button, and a power supply. The circuit is designed to read current values, potentiometer settings, and switch states, and then send this data to a serial monitor for further processing.
ADS1115
Toggle Switch
Arduino UNO
ACS712 Current Sensor 5A 20A 30A
Potentiometer
2Pin Push Switch
POWER SUPPLY 5V 5AMP
#include <Adafruit_ADS1X15.h>
#include <Wire.h>
Adafruit_ADS1115 ads;  // Create an instance of the ADS1115
// Pin Definitions
const int potPin = A1;           // Pin for potentiometer
const int toggleSwitch1Pin = 3;  // Pin for toggle switch 1 (corrected)
const int toggleSwitch2Pin = 4;  // Pin for toggle switch 2 (corrected)
const int pushSwitchPin = 7;     // Pin for push button (corrected)
// Variables to store values
int toggleSwitch1State = 0;      // Variable for toggle switch 1 state
int toggleSwitch2State = 0;      // Variable for toggle switch 2 state
int pushSwitchState = 0;         // Variable for push button state
float currentSetting = 0;        // Variable for potentiometer value
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);  // Start Serial communication for debugging
  
  ads.begin();  // Initialize the ADS1115 ADC
  // Configure pins for switches
  pinMode(toggleSwitch1Pin, INPUT);    // Set toggle switch 1 pin as input
  pinMode(toggleSwitch2Pin, INPUT);    // Set toggle switch 2 pin as input
  pinMode(pushSwitchPin, INPUT_PULLUP); // Set push button pin as input with internal pull-up
}
void loop() {
  // put your main code here, to run repeatedly:
  // Read the current from ACS712 via ADS1115
  int16_t rawADC = ads.readADC_SingleEnded(0);  // Read from A0 of ADS1115
  float voltage = rawADC * (4.096 / 32767.0);   // Convert raw ADC value to voltage
  float current = (voltage - 2.5) / 0.185;      // Convert voltage to current based on ACS712 (adjust based on your model)
  // Read the potentiometer value
  currentSetting = analogRead(potPin);          // Read potentiometer value from A1
  float knobValue = map(currentSetting, 0, 1023, 0, 100);  // Map to 0-100 range (adjust as needed)
  // Read the toggle switch states
  toggleSwitch1State = digitalRead(toggleSwitch1Pin);  // Read toggle switch 1 state
  toggleSwitch2State = digitalRead(toggleSwitch2Pin);  // Read toggle switch 2 state
  // Read the push button state
  pushSwitchState = digitalRead(pushSwitchPin); // Read push button state (LOW when pressed)
  // Send data to Serial for your custom software
  Serial.print("Current: ");
  Serial.print(current, 3);                     // Print current in Amps
  Serial.print(" A, Knob Value: ");
  Serial.print(knobValue);                      // Print potentiometer value as a percentage
  Serial.print(" %, Toggle Switch 1: ");
  Serial.print(toggleSwitch1State == HIGH ? "OFF" : "ON");  // Print toggle switch 1 state
  Serial.print(", Toggle Switch 2: ");
  Serial.print(toggleSwitch2State == HIGH ? "OFF" : "ON");  // Print toggle switch 2 state
  Serial.print(", Push Button: ");
  Serial.println(pushSwitchState == HIGH ? "Released" : "Pressed");  // Print push button state
  // Add a small delay to avoid spamming Serial
  delay(500);  // Adjust the delay as needed
}
This code initializes the ADS1115 ADC, reads current values from the ACS712 current sensor, potentiometer values, and switch states, and then sends this data to the serial monitor for further processing.