MEASURING CAPASITOR

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Measuring%20Capasitor.zip

const int OUT_PIN = A2;
const int IN_PIN = A0;
const float IN_STRAY_CAP_TO_GND = 24.48;
const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND;
const float R_PULLUP = 34.8;
const int MAX_ADC_VALUE = 1023;

void setup()
{
pinMode(OUT_PIN, OUTPUT);
pinMode(IN_PIN, OUTPUT);
Serial.begin(9600);
}

void loop()
{
pinMode(IN_PIN, INPUT);
digitalWrite(OUT_PIN, HIGH);
int val = analogRead(IN_PIN);
digitalWrite(OUT_PIN, LOW);

if (val < 1000)
{
  pinMode(IN_PIN, OUTPUT);

  float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);

  Serial.print(F("Capacitance Value = "));
  Serial.print(capacitance, 3);
  Serial.print(F(" pF ("));
  Serial.print(val);
  Serial.println(F(") "));
}
else
{
  pinMode(IN_PIN, OUTPUT);
  delay(1);
  pinMode(OUT_PIN, INPUT_PULLUP);
  unsigned long u1 = micros();
  unsigned long t;
  int digVal;

  do
  {
    digVal = digitalRead(OUT_PIN);
    unsigned long u2 = micros();
    t = u2 > u1 ? u2 - u1 : u1 - u2;
  } while ((digVal < 1) && (t < 400000L));

  pinMode(OUT_PIN, INPUT);  
  val = analogRead(OUT_PIN);
  digitalWrite(IN_PIN, HIGH);
  int dischargeTime = (int)(t / 1000L) * 5;
  delay(dischargeTime);   
  pinMode(OUT_PIN, OUTPUT);  
  digitalWrite(OUT_PIN, LOW);
  digitalWrite(IN_PIN, LOW);

  float capacitance = -(float)t / R_PULLUP
                          / log(1.0 - (float)val / (float)MAX_ADC_VALUE);

  Serial.print(F("Capacitance Value = "));
  if (capacitance > 1000.0)
  {
    Serial.print(capacitance / 1000.0, 2);
    Serial.print(F(" uF"));
  }
  else
  {
    Serial.print(capacitance, 2);
    Serial.print(F(" nF"));
  }

  Serial.print(F(" ("));
  Serial.print(digVal == 1 ? F("Normal") : F("HighVal"));
  Serial.print(F(", t= "));
  Serial.print(t);
  Serial.print(F(" us, ADC= "));
  Serial.print(val);
  Serial.println(F(")"));
}
while (millis() % 1000 != 0)
  ;    

}

HALL SENSOR SWITCH

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/HallSensorSwitch.zip

// constants won’t change. They’re used here to
// set pin numbers:
const int OutputPin = 2; // the number of the pushbutton pin
const int ledPin = 3; // the number of the LED pin

// variables will change:
int HallState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(OutputPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
HallState = digitalRead(OutputPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (HallState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

SERIAL MONITOR TO LCD DISPLAY

LCD serial

/*In this project, we demonstrate the sending of characters from the serial monitor to the LCD display.

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Serial_to_LCD.zip

*/

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}

void loop() {
// when characters arrive over the serial port…
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}

CONTROLLING SERVO VIA SERIAL MONITOR

servo serial

/* We can control this servo through
the serial monitor,
type the angle value that we want (0-180)
then press enter.

the code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Servo_serial.zip

*/

#include <Servo.h>

Servo servo1;
long num;

void setup()
{
servo1.attach(9);
Serial.begin(9600);
Serial.print(“Enter Position = “);
}

void loop()
{
while(Serial.available()>0)
{
num= Serial.parseInt();
Serial.print(num);
Serial.println(” degree”);
Serial.print(“Enter Position = “);
}
servo1.write(num);
delay(15);
}

CONTROL STEPPER IR REMOTE

STepper remote

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Stepper_remote.zip

#include “Stepper.h”
#include “IRremote.h”
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 6

// In1, In2, In3, In4 in the sequence 1-3-2-4
Stepper small_stepper(STEPS, 12, 10, 11, 9);
IRrecv irrecv(receiver); // create instance of ‘irrecv’
decode_results results; // create instance of ‘decode_results’
void setup()
{
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?

{
switch(results.value)
{
case 0x20F0E01F: // RIGHT button pressed
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; // Rotate CW 360 deg
small_stepper.step(Steps2Take);
break;

case 0x20F0609F: // LEFT button pressed
small_stepper.setSpeed(500);
Steps2Take = -1024; // Rotate CCW 180 deg
small_stepper.step(Steps2Take);
break;
}
irrecv.resume(); // receive the next value
}
}